@abaplint/runtime 1.8.24 → 1.8.27

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.
@@ -1,6 +1,9 @@
1
1
  import { Integer } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
- export declare function count(input: {
4
- val: ICharacter | string;
5
- sub: ICharacter | string;
6
- }): Integer;
3
+ export declare type countInput = {
4
+ val: ICharacter;
5
+ sub: ICharacter;
6
+ regex?: ICharacter;
7
+ case?: ICharacter;
8
+ };
9
+ export declare function count(input: countInput): Integer;
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.count = void 0;
4
+ const compare_1 = require("../compare");
4
5
  const types_1 = require("../types");
5
6
  function count(input) {
6
7
  let found = 0;
7
- const val = typeof input.val === "string" ? input.val : input.val.get();
8
- let sub = typeof input.sub === "string" ? input.sub : input.sub.get();
9
- sub = sub.replace(/\*/g, "\\*");
8
+ const val = input.val.get();
9
+ let reg = "";
10
+ if (input.sub) {
11
+ reg = input.sub.get();
12
+ reg = reg.replace(/\*/g, "\\*");
13
+ }
14
+ else if (input.regex) {
15
+ reg = input.regex.get();
16
+ }
17
+ let options = "g";
18
+ if (input.case && (0, compare_1.initial)(input.case)) {
19
+ options += "i";
20
+ }
10
21
  if (val !== "") {
11
- const res = val.match(new RegExp(sub, "g"));
22
+ const res = val.match(new RegExp(reg, options));
12
23
  if (res) {
13
24
  found = res.length;
14
25
  }
@@ -14,4 +14,4 @@ export interface IFindOptions {
14
14
  ignoringCase?: boolean;
15
15
  submatches?: ICharacter[];
16
16
  }
17
- export declare function find(input: ICharacter | string, options: IFindOptions): void;
17
+ export declare function find(input: ICharacter | Table, options: IFindOptions): void;
@@ -4,10 +4,6 @@ exports.find = void 0;
4
4
  const types_1 = require("../types");
5
5
  function find(input, options) {
6
6
  var _a, _b, _c, _d, _e, _f, _g;
7
- let i = input;
8
- if (typeof i !== "string") {
9
- i = i.get();
10
- }
11
7
  let sectionOffset = (_a = options.sectionOffset) === null || _a === void 0 ? void 0 : _a.get();
12
8
  if (sectionOffset && options.byteMode) {
13
9
  sectionOffset = sectionOffset * 2;
@@ -49,16 +45,31 @@ function find(input, options) {
49
45
  else {
50
46
  throw "FIND, runtime, no input";
51
47
  }
52
- if (sectionOffset) {
53
- i = i.substr(sectionOffset);
54
- }
55
- let temp;
56
48
  const matches = [];
57
- // eslint-disable-next-line no-cond-assign
58
- while (temp = s.exec(i)) {
59
- matches.push(temp);
60
- if (options.first === true) {
61
- break;
49
+ if (input instanceof types_1.Table) {
50
+ for (const blah of input.array()) {
51
+ let temp;
52
+ // eslint-disable-next-line no-cond-assign
53
+ while (temp = s.exec(blah.get())) {
54
+ matches.push(temp);
55
+ if (options.first === true) {
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ else {
62
+ let blah = input.get();
63
+ if (sectionOffset) {
64
+ blah = blah.substr(sectionOffset);
65
+ }
66
+ let temp;
67
+ // eslint-disable-next-line no-cond-assign
68
+ while (temp = s.exec(blah)) {
69
+ matches.push(temp);
70
+ if (options.first === true) {
71
+ break;
72
+ }
62
73
  }
63
74
  }
64
75
  if (options.submatches) {
@@ -1,2 +1,10 @@
1
1
  import { ICharacter } from "../types/_character";
2
- export declare function replace(input: ICharacter, all: boolean, s: ICharacter | string, r: ICharacter | string): void;
2
+ export declare type replaceInput = {
3
+ target: ICharacter;
4
+ sectionLength?: ICharacter;
5
+ regex?: ICharacter;
6
+ all: boolean;
7
+ with: ICharacter;
8
+ of: ICharacter;
9
+ };
10
+ export declare function replace(input: replaceInput): void;
@@ -1,27 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replace = void 0;
4
- function replace(input, all, s, r) {
5
- let temp = input.get();
4
+ function replace(input) {
5
+ let temp = input.target.get();
6
6
  let search = "";
7
- if (typeof s === "string") {
8
- search = s;
7
+ let found = false;
8
+ if (input.of) {
9
+ search = input.of.get();
10
+ if (search.length === 0 && input.all === true) {
11
+ throw "REPLACE, zero length input";
12
+ }
13
+ found = temp.indexOf(search) >= 0;
9
14
  }
10
- else {
11
- search = s.get();
15
+ else if (input.regex) {
16
+ if (input.regex.get().length === 0 && input.all === true) {
17
+ throw "REPLACE, zero length input";
18
+ }
19
+ found = temp.match(search) !== null;
20
+ search = new RegExp(input.regex.get());
12
21
  }
13
22
  let replace = "";
14
- if (typeof r === "string") {
15
- replace = r;
23
+ if (typeof input.with === "string") {
24
+ replace = input.with;
16
25
  }
17
26
  else {
18
- replace = r.get();
27
+ replace = input.with.get();
19
28
  }
20
- const found = temp.indexOf(search) >= 0;
21
- if (all === true) {
22
- if (search.length === 0) {
23
- throw "REPLACE, zero length input";
24
- }
29
+ if (input.all === true) {
25
30
  while (temp.replace(search, replace) !== temp) {
26
31
  temp = temp.replace(search, replace);
27
32
  }
@@ -32,7 +37,7 @@ function replace(input, all, s, r) {
32
37
  const subrc = found ? 0 : 4;
33
38
  // @ts-ignore
34
39
  abap.builtin.sy.get().subrc.set(subrc);
35
- input.set(temp);
40
+ input.target.set(temp);
36
41
  }
37
42
  exports.replace = replace;
38
43
  //# sourceMappingURL=replace.js.map
@@ -5,6 +5,7 @@ declare type options = {
5
5
  date?: string;
6
6
  time?: string;
7
7
  width?: number;
8
+ decimals?: number;
8
9
  };
9
10
  export declare function templateFormatting(source: ICharacter | INumeric, options: options): string;
10
11
  export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.templateFormatting = void 0;
4
+ const types_1 = require("./types");
4
5
  function templateFormatting(source, options) {
5
6
  let text = source.get() + "";
6
7
  if (options.timestamp === "iso") {
@@ -15,6 +16,9 @@ function templateFormatting(source, options) {
15
16
  if (options.width) {
16
17
  text = text.trimEnd().padEnd(options.width, " ");
17
18
  }
19
+ else if (options.decimals && source instanceof types_1.Integer) {
20
+ text = source.get() + "." + "".padEnd(options.decimals, "0");
21
+ }
18
22
  return text;
19
23
  }
20
24
  exports.templateFormatting = templateFormatting;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "1.8.24",
3
+ "version": "1.8.27",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -37,6 +37,6 @@
37
37
  "chai": "^4.3.6",
38
38
  "mocha": "^9.2.2",
39
39
  "source-map-support": "^0.5.21",
40
- "typescript": "^4.6.2"
40
+ "typescript": "^4.6.3"
41
41
  }
42
42
  }