Review this generated redactor before it processes untrusted release notes.
Replace every configured term as literal text, leave messages unchanged when the term list is empty, insert the caller’s replacement literally, and reject messages over maxLength.
JavaScript
function createReleaseRedactor(terms, maxLength = 10_000) {
const source = terms.join('|');
const pattern = new RegExp(source, 'gi');
return function redact(message, replacement = '[hidden]') {
return message.replace(pattern, replacement);
};
}
const redact = createReleaseRedactor(['C++', 'C+', '[draft]']);
const notes = [
'Move [draft] C++ code; keep C+ notes.',
'Keep JavaScript release notes visible.',
];
for (const note of notes) {
console.log(redact(note, '$& removed'));
}
generated code is illustrative, not from any one model