unicode-to-plain-text
Version:
Convert fancy Unicode text to plain ASCII with smart language preservation
20 lines (19 loc) • 727 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeDecorations = void 0;
const DECORATIVE_CHARS_1 = require("./maps/DECORATIVE_CHARS");
const SPAM_RATIO_THRESHOLD = 0.4;
const removeDecorations = (text, options) => {
const cleaned = [...text]
.filter((char) => {
if (DECORATIVE_CHARS_1.OTHER_DECORATIONS.has(char))
return false;
if ((0, DECORATIVE_CHARS_1.isEmoji)(char))
return options?.skipEmoji ?? false;
return true;
})
.join('');
const isMostlyDecoration = cleaned.length < text.length * SPAM_RATIO_THRESHOLD;
return isMostlyDecoration ? '' : cleaned;
};
exports.removeDecorations = removeDecorations;