UNPKG

@abaplint/runtime

Version:
34 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.translate = translate; const types_1 = require("../types"); const string_1 = require("../types/string"); function translate(input) { let val = typeof input.val === "string" ? input.val : input.val.get(); const from = typeof input.from === "string" ? input.from : input.from.get(); let toSource; if (input.to instanceof types_1.FieldSymbol) { const pointer = input.to.getPointer(); if (pointer === undefined) { throw new Error("GETWA_NOT_ASSIGNED"); } toSource = pointer; } else { toSource = input.to; } let to = typeof toSource === "string" ? toSource : toSource.get(); if (toSource instanceof types_1.Character) { to = toSource.getTrimEnd(); } const fromSplit = from.split(""); const toSplit = to.split(""); const chars = {}; for (let i = 0; i < fromSplit.length; i++) { chars[fromSplit[i]] = toSplit[i] || ""; } const reg = new RegExp("[" + from + "]", "g"); val = val.replace(reg, m => chars[m] || ""); return new string_1.String().set(val); } //# sourceMappingURL=translate.js.map