@abaplint/runtime
Version:
Transpiler - Runtime
32 lines • 919 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.segment = segment;
const throw_error_1 = require("../throw_error");
const types_1 = require("../types");
function segment(input) {
let val = input.val;
if (typeof val !== "string") {
val = val.get();
}
let sep = input.sep;
if (typeof sep !== "string") {
sep = sep.get();
}
let index = input.index;
if (typeof index !== "number") {
index = index.get();
}
if (index === 0 || sep.length === 0) {
(0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
}
const array = val.split(sep);
if (index < 0) {
array.reverse();
index = Math.abs(index);
}
if (index > array.length) {
(0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
}
return new types_1.String().set(array[index - 1]);
}
//# sourceMappingURL=segment.js.map