UNPKG

@abaplint/runtime

Version:
52 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = parse; const types_1 = require("../types"); const xstring_1 = require("../types/xstring"); function parse(val) { if (typeof val === "number") { return val; } else if (typeof val === "string") { if (val.includes(".")) { return parseFloat(val); } else { return parseInt(val, 10); } } else if (val instanceof types_1.Integer) { // optimize, as this is the most common case return val.get(); } else if (val instanceof types_1.Float) { return val.getRaw(); } else if (val instanceof xstring_1.XString) { if (val.get() === "") { return 0; } return parseInt(val.get(), 16); } else if (val instanceof types_1.Hex || val instanceof types_1.HexUInt8) { let num = parseInt(val.get(), 16); // handle two complement, if (val.getLength() >= 4) { const maxVal = Math.pow(2, val.get().length / 2 * 8); if (num > maxVal / 2 - 1) { num = num - maxVal; } } return num; } else if (val instanceof types_1.Time || val instanceof types_1.Date) { return val.getNumeric(); } else if (val instanceof types_1.DecFloat34) { return val.getRaw(); } else { return parse(val.get()); } } //# sourceMappingURL=_parse.js.map