@abaplint/runtime 2.1.49 → 2.1.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ function replace(input) {
17
17
  wi = input.with;
18
18
  }
19
19
  else if (input.with instanceof types_1.Character) {
20
- wi = input.with.get().replace(/ *$/, "");
20
+ wi = input.with.getTrimEnd();
21
21
  }
22
22
  else if (input.with) {
23
23
  wi = input.with.get();
@@ -60,7 +60,7 @@ function eq(left, right) {
60
60
  }
61
61
  let l = undefined;
62
62
  if (left instanceof types_1.Character) {
63
- l = left.get().replace(/ *$/, "");
63
+ l = left.getTrimEnd();
64
64
  }
65
65
  else if (typeof left === "object") {
66
66
  l = left.get();
@@ -70,7 +70,7 @@ function eq(left, right) {
70
70
  }
71
71
  let r = undefined;
72
72
  if (right instanceof types_1.Character) {
73
- r = right.get().replace(/ *$/, "");
73
+ r = right.getTrimEnd();
74
74
  }
75
75
  else if (typeof right === "object") {
76
76
  r = right.get();
@@ -8,7 +8,7 @@ function concat(left, right) {
8
8
  val += left;
9
9
  }
10
10
  else if (left instanceof types_1.Character) {
11
- val += left.get().replace(/( )*$/, "");
11
+ val += left.getTrimEnd();
12
12
  }
13
13
  else {
14
14
  val += left.get();
@@ -17,7 +17,7 @@ function concat(left, right) {
17
17
  val += right;
18
18
  }
19
19
  else if (right instanceof types_1.Character) {
20
- val += right.get().replace(/( )*$/, "");
20
+ val += right.getTrimEnd();
21
21
  }
22
22
  else {
23
23
  val += right.get();
@@ -10,5 +10,5 @@ declare type options = {
10
10
  currency?: any;
11
11
  align?: "left" | "right";
12
12
  };
13
- export declare function templateFormatting(source: ICharacter | INumeric, options: options): string;
13
+ export declare function templateFormatting(source: ICharacter | INumeric, options?: options): string;
14
14
  export {};
@@ -3,23 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.templateFormatting = void 0;
4
4
  const types_1 = require("./types");
5
5
  function templateFormatting(source, options) {
6
- let text = source.get() + "";
7
- if (options.currency !== undefined) {
6
+ let text = "";
7
+ if (source instanceof types_1.Character) {
8
+ text = source.getTrimEnd();
9
+ }
10
+ else {
11
+ text = source.get() + "";
12
+ }
13
+ if ((options === null || options === void 0 ? void 0 : options.currency) !== undefined) {
8
14
  throw "template formatting with currency not supported";
9
15
  }
10
- if (options.timestamp === "iso") {
16
+ if ((options === null || options === void 0 ? void 0 : options.timestamp) === "iso") {
11
17
  text = text.substr(0, 4) + "-" + text.substr(4, 2) + "-" + text.substr(6, 2) + "T" + text.substr(8, 2) + ":" + text.substr(10, 2) + ":" + text.substr(12, 2);
12
18
  if (text === "0--T::") {
13
19
  text = "0000-00-00T00:00:00";
14
20
  }
15
21
  }
16
- if (options.date === "iso") {
22
+ if ((options === null || options === void 0 ? void 0 : options.date) === "iso") {
17
23
  text = text.substr(0, 4) + "-" + text.substr(4, 2) + "-" + text.substr(6, 2);
18
24
  }
19
- if (options.time === "iso") {
25
+ if ((options === null || options === void 0 ? void 0 : options.time) === "iso") {
20
26
  text = text.substr(0, 2) + ":" + text.substr(2, 2) + ":" + text.substr(4, 2);
21
27
  }
22
- if (options.width && options.pad) {
28
+ if ((options === null || options === void 0 ? void 0 : options.width) && options.pad) {
23
29
  if (options.align === "right") {
24
30
  text = text.trimEnd().padStart(options.width, options.pad);
25
31
  }
@@ -27,13 +33,13 @@ function templateFormatting(source, options) {
27
33
  text = text.trimEnd().padEnd(options.width, options.pad);
28
34
  }
29
35
  }
30
- else if (options.width) {
36
+ else if (options === null || options === void 0 ? void 0 : options.width) {
31
37
  text = text.trimEnd().padEnd(options.width, " ");
32
38
  }
33
- else if (options.decimals && source instanceof types_1.Integer) {
39
+ else if ((options === null || options === void 0 ? void 0 : options.decimals) && source instanceof types_1.Integer) {
34
40
  text = source.get() + "." + "".padEnd(options.decimals, "0");
35
41
  }
36
- else if (options.decimals && source instanceof types_1.Packed) {
42
+ else if ((options === null || options === void 0 ? void 0 : options.decimals) && source instanceof types_1.Packed) {
37
43
  text = source.get().toFixed(options.decimals);
38
44
  }
39
45
  return text;
@@ -14,6 +14,7 @@ export declare class Character implements ICharacter {
14
14
  getLength(): number;
15
15
  clear(): void;
16
16
  get(): string;
17
+ getTrimEnd(): string;
17
18
  getOffset(input: {
18
19
  offset?: number | INumeric | Hex;
19
20
  length?: number | INumeric | Hex;
@@ -40,6 +40,9 @@ class Character {
40
40
  get() {
41
41
  return this.value;
42
42
  }
43
+ getTrimEnd() {
44
+ return this.value.replace(/ *$/, "");
45
+ }
43
46
  getOffset(input) {
44
47
  if (input === null || input === void 0 ? void 0 : input.offset) {
45
48
  input.offset = (0, _parse_1.parse)(input.offset);
@@ -21,7 +21,7 @@ class String {
21
21
  }
22
22
  else if (value instanceof character_1.Character) {
23
23
  // replace trailing blanks if the source is a Character string
24
- this.value = value.get().replace(/[ ]*$/g, "");
24
+ this.value = value.getTrimEnd();
25
25
  }
26
26
  else if (value instanceof integer_1.Integer) {
27
27
  const lv_sign = (parseInt(value.get(), 10) >= 0) ? " " : "-";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.1.49",
3
+ "version": "2.1.50",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",