UNPKG

attranslate

Version:

Semi-automated Text Translator for Websites and Apps

24 lines (23 loc) 805 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchIcu = void 0; let parseModule = null; const matchIcu = (input, replacer) => { // Import parseModule on demand to optimize launch-performance. if (!parseModule) { parseModule = require("messageformat-parser"); } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const parts = parseModule.parse(input); const regex = new RegExp(parts .map((part) => typeof part === "string" ? part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") : "(.*)") .join("")); const matches = input.match(regex); return (matches || []).slice(1).map((match, index) => ({ from: match, to: replacer(index), })); }; exports.matchIcu = matchIcu;