redacted-ts
Version:
Redacting classified documents
24 lines (23 loc) • 906 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToDictionary = exports.Dictionary = void 0;
const contains = (dictionary) => (word) => dictionary.includes(word) || word.endsWith('\'s') && dictionary.includes(word.substr(0, word.length - 2)) || dictionary.includes(word.replace(/[^a-zA-Z0-9]/g, ''));
const Dictionary = (words) => ({
words,
contains: contains(words),
isEmpty: () => words.length === 0,
length: () => words.length,
toString: () => words.join(' ')
});
exports.Dictionary = Dictionary;
const stringToDictionary = (str, ...delimiters) => {
if (delimiters.length === 0) {
delimiters = [' '];
}
let dic = [str];
delimiters.forEach(delim => {
dic = dic.map(word => word.split(delim)).flatMap(_ => _);
});
return (0, exports.Dictionary)(dic);
};
exports.stringToDictionary = stringToDictionary;