"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { strtr: () => strtr }); module.exports = __toCommonJS(src_exports); function strtr(string, from, to) { if (arguments.length >= 3) { string = String(string); from = String(from); to = String(to); const actualLength = Math.min(from.length, to.length); const fromArray = from.substring(0, actualLength).split(""); const toArray = to.substring(0, actualLength).split(""); return string.split("").map((char) => { const index = fromArray.lastIndexOf(char); return index !== -1 ? toArray[index] : char; }).join(""); } if (arguments.length === 2) { if (from == null || typeof from !== "object") { throw new TypeError("strtr(): The second argument is not an array."); } string = String(string); const sortedKeys = Object.keys(from).sort((a, b) => b.length - a.length); const characters = string.split(""); const replacedIndices = new Array(string.length).fill(false); for (const key of sortedKeys) { let index = 0; while (index <= characters.length - key.length) { if (!replacedIndices.slice(index, index + key.length).includes(true) && characters.slice(index, index + key.length).join("") === key) { characters.splice(index, key.length, ...from[key].split("")); replacedIndices.splice(index, key.length, ...new Array(from[key].length).fill(true)); index += from[key].length; } else { index += 1; } } } return characters.join(""); } throw new TypeError(`strtr() expects at least 2 parameters, ${arguments.length} given`); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { strtr });