UNPKG

unicode-to-plain-text

Version:

Convert fancy Unicode text to plain ASCII with smart language preservation

17 lines (16 loc) 614 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeUnicode = void 0; const normalizeUnicode = (text) => { return Array.from(text) .map((char) => { const code = char.charCodeAt(0); const isLatin = (code >= 0x0041 && code <= 0x005a) || (code >= 0x0061 && code <= 0x007a) || (code >= 0x00c0 && code <= 0x02ff) || (code >= 0x1e00 && code <= 0x1eff); return isLatin ? char.normalize('NFD').replace(/[\u0300-\u036F]/g, '') : char; }) .join(''); }; exports.normalizeUnicode = normalizeUnicode;