@abaplint/runtime
Version:
Transpiler - Runtime
23 lines • 915 B
JavaScript
;
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 to = typeof input.to === "string" ? input.to : input.to.get();
if (input.to instanceof types_1.Character) {
to = input.to.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