hunspell-reader
Version:
A library for reading Hunspell Dictionary Files
20 lines • 630 B
JavaScript
const regexSpecialCharacters = /[|\\{}()[\]^$+*?.]/g;
export class Converter {
_match;
_map;
constructor(convList) {
const match = convList.map(({ from }) => from.replaceAll(regexSpecialCharacters, '\\$&')).join('|');
this._match = new RegExp(match, 'g');
this._map = Object.create(null);
convList.reduce((map, { from, to }) => {
map[from] = to;
return map;
}, this._map);
}
convert = (input) => {
return input.replace(this._match, (m) => {
return this._map[m] || '';
});
};
}
//# sourceMappingURL=converter.js.map