UNPKG

unicode-to-plain-text

Version:

Convert fancy Unicode text to plain ASCII with smart language preservation

44 lines (43 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pipe = exports.normalizeCasing = exports.removeDecorations = exports.normalizeUnicode = exports.mapCharacters = exports.handleFlipped = exports.handleUnicodeId = exports.toPlainText = void 0; const handleUnicodeId_1 = require("./handleUnicodeId"); const mapCharacters_1 = require("./mapCharacters"); const normalizeCasing_1 = require("./normalizeCasing"); const normalizeUnicode_1 = require("./normalizeUnicode"); const removeDecorations_1 = require("./removeDecorations"); const pipe_1 = require("./pipe"); const validation_1 = require("./utils/validation"); const normalizeSpaces_1 = require("./normalizeSpaces"); const isAsciiOnly_1 = require("./isAsciiOnly"); const handleFlipped_1 = require("./handleFlipped"); const DEFAULT_OPTIONS = { normalizeSpaces: true, skipEmoji: false }; const toPlainText = (text, options = DEFAULT_OPTIONS) => { const validated = (0, validation_1.validateInput)(text); const normalizeSpacesHandler = (options?.normalizeSpaces ?? DEFAULT_OPTIONS.normalizeSpaces) ? normalizeSpaces_1.normalizeSpaces : (text) => text; const removeDecorationsHandler = (text) => (0, removeDecorations_1.removeDecorations)(text, { skipEmoji: options?.skipEmoji ?? DEFAULT_OPTIONS.skipEmoji }); if ((0, isAsciiOnly_1.isAsciiOnly)(validated)) { return (0, pipe_1.pipe)(handleUnicodeId_1.handleUnicodeId, normalizeSpacesHandler)(validated); } return (0, pipe_1.pipe)(handleFlipped_1.handleFlipped, mapCharacters_1.mapCharacters, normalizeUnicode_1.normalizeUnicode, removeDecorationsHandler, normalizeSpacesHandler, normalizeCasing_1.normalizeCasing)(validated); }; exports.toPlainText = toPlainText; var handleUnicodeId_2 = require("./handleUnicodeId"); Object.defineProperty(exports, "handleUnicodeId", { enumerable: true, get: function () { return handleUnicodeId_2.handleUnicodeId; } }); var handleFlipped_2 = require("./handleFlipped"); Object.defineProperty(exports, "handleFlipped", { enumerable: true, get: function () { return handleFlipped_2.handleFlipped; } }); var mapCharacters_2 = require("./mapCharacters"); Object.defineProperty(exports, "mapCharacters", { enumerable: true, get: function () { return mapCharacters_2.mapCharacters; } }); var normalizeUnicode_2 = require("./normalizeUnicode"); Object.defineProperty(exports, "normalizeUnicode", { enumerable: true, get: function () { return normalizeUnicode_2.normalizeUnicode; } }); var removeDecorations_2 = require("./removeDecorations"); Object.defineProperty(exports, "removeDecorations", { enumerable: true, get: function () { return removeDecorations_2.removeDecorations; } }); var normalizeCasing_2 = require("./normalizeCasing"); Object.defineProperty(exports, "normalizeCasing", { enumerable: true, get: function () { return normalizeCasing_2.normalizeCasing; } }); var pipe_2 = require("./pipe"); Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return pipe_2.pipe; } });