@abaplint/runtime
Version:
Transpiler - Runtime
79 lines • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WriteStatement = void 0;
const types_1 = require("../types");
const NO_DEICMAL_CURRENCIES = ["HUF", "KRW", "JPY"];
class WriteStatement {
context;
constructor(context) {
this.context = context;
}
write(source, options) {
let right = false;
if (source === undefined) {
throw new Error("WriteStatement: source is undefined");
}
if (options?.skipLine === true) {
this.context.console.add("\n");
}
else {
if (options?.newLine === true && this.context.console.isEmpty() === false) {
this.context.console.add("\n");
}
let result = "";
if (typeof source === "string" || typeof source === "number") {
result = source.toString();
}
else if (source instanceof types_1.Structure) {
const obj = source.getCharacter();
this.write(obj, { ...options });
}
else if (source instanceof types_1.Float) {
if (options?.exponent?.get() === 0) {
const tens = source.getRaw().toFixed(0).length - 1;
if (options.noSign === true && source.getRaw() < 0) {
result = source.getRaw().toFixed(17 - tens).replace(".", ",");
result = result.replace("-", "");
}
else {
result = source.getRaw().toFixed(16 - tens).replace(".", ",");
}
}
else {
result = source.get().toString();
}
}
else if (source instanceof types_1.Packed) {
let num = source.get();
let decimals = source.getDecimals();
if (NO_DEICMAL_CURRENCIES.includes(options?.currency?.get().trimEnd() || "")) {
// todo: more work needed here,
num = num * 100;
decimals = 0;
}
result = num.toFixed(decimals).replace(".", ",");
right = true;
}
else {
result = source.get().toString();
}
if (options?.noSign === true) {
result = result.replace("-", "");
}
if (options?.target) {
if (right === true) {
const len = options.target.get().length;
options.target.set(" ".repeat(len - result.length) + result);
}
else {
options.target.set(result);
}
}
else {
this.context.console.add(result);
}
}
}
}
exports.WriteStatement = WriteStatement;
//# sourceMappingURL=write.js.map