UNPKG

hunspell-reader

Version:
20 lines 630 B
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