@litert/typeguard 1.0.0 → 1.2.0

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.
Files changed (74) hide show
  1. package/CHANGES.md +15 -0
  2. package/lib/BuiltInTypeCompiler.d.ts +4 -4
  3. package/lib/BuiltInTypeCompiler.d.ts.map +1 -1
  4. package/lib/BuiltInTypeCompiler.js +167 -166
  5. package/lib/BuiltInTypeCompiler.js.map +1 -1
  6. package/lib/BuiltInTypes.d.ts +1 -1
  7. package/lib/BuiltInTypes.js +37 -36
  8. package/lib/BuiltInTypes.js.map +1 -1
  9. package/lib/Common.d.ts +13 -9
  10. package/lib/Common.d.ts.map +1 -1
  11. package/lib/Common.js +1 -1
  12. package/lib/Compiler.d.ts +2 -2
  13. package/lib/Compiler.d.ts.map +1 -1
  14. package/lib/Compiler.js +77 -72
  15. package/lib/Compiler.js.map +1 -1
  16. package/lib/Context.d.ts +2 -2
  17. package/lib/Context.js +3 -2
  18. package/lib/Context.js.map +1 -1
  19. package/lib/FilterCompiler.d.ts +5 -5
  20. package/lib/FilterCompiler.d.ts.map +1 -1
  21. package/lib/FilterCompiler.js +25 -24
  22. package/lib/FilterCompiler.js.map +1 -1
  23. package/lib/InlineCompiler.d.ts +12 -5
  24. package/lib/InlineCompiler.d.ts.map +1 -1
  25. package/lib/InlineCompiler.js +14 -5
  26. package/lib/InlineCompiler.js.map +1 -1
  27. package/lib/Internal.d.ts +2 -1
  28. package/lib/Internal.d.ts.map +1 -1
  29. package/lib/Internal.js +12 -10
  30. package/lib/Internal.js.map +1 -1
  31. package/lib/Modifiers.d.ts +1 -1
  32. package/lib/Modifiers.js +2 -1
  33. package/lib/Modifiers.js.map +1 -1
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +19 -7
  36. package/lib/index.js.map +1 -1
  37. package/lib/langs/JavaScript.d.ts +2 -2
  38. package/lib/langs/JavaScript.d.ts.map +1 -1
  39. package/lib/langs/JavaScript.js +30 -23
  40. package/lib/langs/JavaScript.js.map +1 -1
  41. package/package.json +18 -13
  42. package/src/{samples → examples}/quick-start.ts +22 -12
  43. package/src/lib/BuiltInTypeCompiler.ts +171 -171
  44. package/src/lib/BuiltInTypes.ts +36 -36
  45. package/src/lib/Common.ts +15 -10
  46. package/src/lib/Compiler.ts +213 -208
  47. package/src/lib/Context.ts +3 -3
  48. package/src/lib/FilterCompiler.ts +84 -84
  49. package/src/lib/InlineCompiler.ts +35 -14
  50. package/src/lib/Internal.ts +12 -10
  51. package/src/lib/Modifiers.ts +2 -2
  52. package/src/lib/index.ts +5 -5
  53. package/src/lib/langs/JavaScript.ts +34 -24
  54. package/src/test/00-all.ts +11 -9
  55. package/src/test/01-elemental-types.ts +1111 -1110
  56. package/src/test/02-array-and-list.ts +75 -75
  57. package/src/test/03-tuple.ts +87 -87
  58. package/src/test/04-from-string.ts +849 -848
  59. package/src/test/05-string-asserts.ts +422 -422
  60. package/src/test/06-structure.ts +107 -107
  61. package/src/test/07-modifiers.ts +151 -42
  62. package/src/test/08-map-and-dict.ts +46 -46
  63. package/src/test/09-exceptions.ts +67 -0
  64. package/src/test/abstracts.ts +52 -43
  65. package/dist/typeguard.amd.d.ts +0 -588
  66. package/dist/typeguard.amd.d.ts.map +0 -1
  67. package/dist/typeguard.amd.js +0 -2063
  68. package/dist/typeguard.amd.js.map +0 -1
  69. package/dist/typeguard.system.d.ts +0 -588
  70. package/dist/typeguard.system.d.ts.map +0 -1
  71. package/dist/typeguard.system.js +0 -2179
  72. package/dist/typeguard.system.js.map +0 -1
  73. package/tsconfig-amd.json +0 -72
  74. package/tsconfig-systemjs.json +0 -72
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import * as i from "./Internal";
17
+ import * as i from './Internal';
18
18
 
19
19
  export class Context implements i.IContext {
20
20
 
@@ -80,7 +80,7 @@ export class Context implements i.IContext {
80
80
 
81
81
  if (!prev) {
82
82
 
83
- throw new Error("Failed to pop stack.");
83
+ throw new Error('Failed to pop stack.');
84
84
  }
85
85
 
86
86
  this.vName = prev.vName;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,143 +14,143 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import * as C from "./Common";
18
- import * as I from "./Internal";
17
+ import * as C from './Common';
18
+ import * as I from './Internal';
19
19
 
20
20
  export class FilterCompiler
21
21
  implements I.IFilterCompiler {
22
22
 
23
23
  public constructor(
24
- private _lang: C.ILanguageBuilder,
25
- private _bitc: I.IBuiltInTypeCompiler
24
+ private readonly _lang: C.ILanguageBuilder,
25
+ private readonly _bitc: I.IBuiltInTypeCompiler
26
26
  ) {}
27
27
 
28
28
  public compile(rule: string, ctx: I.IContext): string {
29
29
 
30
30
  let vName = ctx.vName;
31
31
 
32
- const filter = rule.slice(1).split(" ");
32
+ const filter = rule.slice(1).split(' ');
33
33
 
34
34
  if (filter.slice(2).length !== filter.slice(2).filter((x) => /^\d+(\.\d+)?$/.test(x)).length) {
35
35
 
36
- throw new TypeError("Only number is allowed as filter arguments.");
36
+ throw new TypeError('Only number is allowed as filter arguments.');
37
37
  }
38
38
 
39
- let ret: string[] = [];
39
+ const ret: string[] = [];
40
40
 
41
41
  switch (filter[0]) {
42
- case "array.length":
43
- ret.push(this._lang.isArray(vName, true));
44
- vName = this._lang.arrayLength(vName);
45
- break;
46
- case "string.length":
47
- ret.push(this._lang.isString(vName, true));
48
- vName = this._lang.stringLength(vName);
49
- break;
50
- case "value":
51
- ret.push(this._lang.isNumber(vName, true));
52
- break;
53
- default:
54
- ret.push(this._bitc.compile(filter[0], ctx, []));
55
- break;
42
+ case 'array.length':
43
+ ret.push(this._lang.isArray(vName, true));
44
+ vName = this._lang.arrayLength(vName);
45
+ break;
46
+ case 'string.length':
47
+ ret.push(this._lang.isString(vName, true));
48
+ vName = this._lang.stringLength(vName);
49
+ break;
50
+ case 'value':
51
+ ret.push(this._lang.isNumber(vName, true));
52
+ break;
53
+ default:
54
+ ret.push(this._bitc.compile(filter[0], ctx, []));
55
+ break;
56
56
  }
57
57
 
58
58
  switch (filter[1]) {
59
- case "between":
59
+ case 'between':
60
60
 
61
- if (filter.length !== 4) {
62
- throw new TypeError(`Filter ${filter[1]} require 2 arguments.`);
63
- }
61
+ if (filter.length !== 4) {
62
+ throw new TypeError(`Filter ${filter[1]} require 2 arguments.`);
63
+ }
64
64
 
65
- ret.push(this._lang.gte(vName, filter[2]));
66
- ret.push(this._lang.lte(vName, filter[3]));
65
+ ret.push(this._lang.gte(vName, filter[2]));
66
+ ret.push(this._lang.lte(vName, filter[3]));
67
67
 
68
- break;
68
+ break;
69
69
 
70
- case "gt":
71
- case ">":
70
+ case 'gt':
71
+ case '>':
72
72
 
73
- if (filter.length !== 3) {
74
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
75
- }
73
+ if (filter.length !== 3) {
74
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
75
+ }
76
76
 
77
- ret.push(this._lang.gt(vName, filter[2]));
77
+ ret.push(this._lang.gt(vName, filter[2]));
78
78
 
79
- break;
79
+ break;
80
80
 
81
- case "ge":
82
- case "gte":
83
- case ">=":
81
+ case 'ge':
82
+ case 'gte':
83
+ case '>=':
84
84
 
85
- if (filter.length !== 3) {
86
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
87
- }
85
+ if (filter.length !== 3) {
86
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
87
+ }
88
88
 
89
- ret.push(this._lang.gte(vName, filter[2]));
89
+ ret.push(this._lang.gte(vName, filter[2]));
90
90
 
91
- break;
91
+ break;
92
92
 
93
- case "lt":
94
- case "<":
93
+ case 'lt':
94
+ case '<':
95
95
 
96
- if (filter.length !== 3) {
97
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
98
- }
96
+ if (filter.length !== 3) {
97
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
98
+ }
99
99
 
100
- ret.push(this._lang.lt(vName, filter[2]));
100
+ ret.push(this._lang.lt(vName, filter[2]));
101
101
 
102
- break;
102
+ break;
103
103
 
104
- case "le":
105
- case "lte":
106
- case "<=":
104
+ case 'le':
105
+ case 'lte':
106
+ case '<=':
107
107
 
108
- if (filter.length !== 3) {
109
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
110
- }
108
+ if (filter.length !== 3) {
109
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
110
+ }
111
111
 
112
- ret.push(this._lang.lte(vName, filter[2]));
112
+ ret.push(this._lang.lte(vName, filter[2]));
113
113
 
114
- break;
114
+ break;
115
115
 
116
- case "eq":
117
- case "==":
116
+ case 'eq':
117
+ case '==':
118
118
 
119
- if (filter.length !== 3) {
120
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
121
- }
119
+ if (filter.length !== 3) {
120
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
121
+ }
122
122
 
123
- ret.push(this._lang.eq(vName, filter[2]));
123
+ ret.push(this._lang.eq(vName, filter[2]));
124
124
 
125
- break;
125
+ break;
126
126
 
127
- case "ne":
128
- case "!=":
127
+ case 'ne':
128
+ case '!=':
129
129
 
130
- if (filter.length !== 3) {
131
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
132
- }
130
+ if (filter.length !== 3) {
131
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
132
+ }
133
133
 
134
- ret.push(this._lang.ne(vName, filter[2]));
134
+ ret.push(this._lang.ne(vName, filter[2]));
135
135
 
136
- break;
136
+ break;
137
137
 
138
- case "timesof":
138
+ case 'timesof':
139
139
 
140
- if (filter.length !== 3) {
141
- throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
142
- }
140
+ if (filter.length !== 3) {
141
+ throw new TypeError(`Filter ${filter[1]} require 1 argument.`);
142
+ }
143
143
 
144
- ret.push(this._lang.eq(
145
- this._lang.modOf(vName, filter[2]),
146
- "0"
147
- ));
144
+ ret.push(this._lang.eq(
145
+ this._lang.modOf(vName, filter[2]),
146
+ '0'
147
+ ));
148
148
 
149
- break;
149
+ break;
150
150
 
151
- default:
151
+ default:
152
152
 
153
- throw new TypeError(`Unknown filter type "${filter[1]}".`);
153
+ throw new TypeError(`Unknown filter type "${filter[1]}".`);
154
154
  }
155
155
 
156
156
  return this._lang.and(ret);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,16 +14,17 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { createCompiler } from "./Compiler";
18
- import { createJavaScriptLanguageBuilder } from "./langs/JavaScript";
19
- import * as C from "./Common";
17
+ import { createCompiler } from './Compiler';
18
+ import { createJavaScriptLanguageBuilder } from './langs/JavaScript';
19
+ import * as C from './Common';
20
+ import * as I from './Internal';
20
21
 
21
22
  export interface IInlineCompileOptions extends C.ICompileOptions {
22
23
 
23
24
  /**
24
25
  * Added `debugger` statement before executing checking code.
25
26
  */
26
- "stopOnEntry"?: boolean;
27
+ 'stopOnEntry'?: boolean;
27
28
  }
28
29
 
29
30
  export interface IInlineCompiler {
@@ -34,14 +35,22 @@ export interface IInlineCompiler {
34
35
  *
35
36
  * @param options The options of compilation.
36
37
  */
37
- compile<T>(options: IInlineCompileOptions): C.TypeChecker<T>;
38
+ compile<T>(options: IInlineCompileOptions): C.ITypeChecker<T>;
38
39
 
39
40
  /**
40
41
  * Get the type-checker of a pre-defined type.
41
42
  *
42
43
  * @param name The name of the pre-defined type.
43
44
  */
44
- getPredefinedType<T>(name: string): C.TypeChecker<T>;
45
+ getPredefinedType<T>(name: string): C.ITypeChecker<T>;
46
+
47
+ /**
48
+ * Register a pre-defined type checker.
49
+ *
50
+ * @param name The name of the pre-defined type (without prefix `@`)
51
+ * @param checker The checker callback of the pre-defined type.
52
+ */
53
+ addPredefinedType<T>(name: string, checker: C.ITypeChecker<T>): this;
45
54
 
46
55
  /**
47
56
  * Check if a pre-defined type is compiled.
@@ -59,11 +68,11 @@ export interface IInlineCompiler {
59
68
  class InlineCompiler
60
69
  implements IInlineCompiler {
61
70
 
62
- private _defTypes: Record<string, C.TypeChecker<any>>;
71
+ private _defTypes: Record<string, C.ITypeChecker<any>>;
63
72
 
64
73
  private _missingTypes: Record<string, boolean>;
65
74
 
66
- private _compiler: C.ICompiler;
75
+ private readonly _compiler: C.ICompiler;
67
76
 
68
77
  public constructor() {
69
78
 
@@ -78,7 +87,7 @@ implements IInlineCompiler {
78
87
  );
79
88
  }
80
89
 
81
- public compile<T>(options: IInlineCompileOptions): C.TypeChecker<T> {
90
+ public compile<T>(options: IInlineCompileOptions): C.ITypeChecker<T> {
82
91
 
83
92
  const result = this._compiler.compile(options);
84
93
 
@@ -92,7 +101,7 @@ implements IInlineCompiler {
92
101
  stopOnEntry?: boolean
93
102
  ): void {
94
103
 
95
- for (let x of types) {
104
+ for (const x of types) {
96
105
 
97
106
  if (this._defTypes[x]) {
98
107
 
@@ -115,6 +124,18 @@ implements IInlineCompiler {
115
124
  }
116
125
  }
117
126
 
127
+ public addPredefinedType(name: string, checker: C.ITypeChecker<any>): this {
128
+
129
+ if (!I.RE_VALID_CUSTOM_TYPE_NAME.test(name)) {
130
+
131
+ throw new TypeError(`Invalid name ${ JSON.stringify(name) } for a pre-defined type.`);
132
+ }
133
+
134
+ this._defTypes[name] = checker;
135
+
136
+ return this;
137
+ }
138
+
118
139
  public detectUndefinedTypes(): string[] {
119
140
 
120
141
  return Object.keys(this._missingTypes);
@@ -125,7 +146,7 @@ implements IInlineCompiler {
125
146
  return !!this._defTypes[name];
126
147
  }
127
148
 
128
- public getPredefinedType(name: string): C.TypeChecker<any> {
149
+ public getPredefinedType(name: string): C.ITypeChecker<any> {
129
150
 
130
151
  if (!this._defTypes[name]) {
131
152
 
@@ -138,9 +159,9 @@ implements IInlineCompiler {
138
159
  private _wrapCheckerCode(
139
160
  info: C.ICompileResult,
140
161
  stopOnEntry: boolean = false
141
- ): C.TypeChecker<any> {
162
+ ): C.ITypeChecker<any> {
142
163
 
143
- const soe = stopOnEntry ? "debugger;" : "";
164
+ const soe = stopOnEntry ? 'debugger;' : '';
144
165
 
145
166
  return (new Function(
146
167
  info.typeSlotName,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,19 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export const MAP_SUFFIX = "{}";
17
+ export const MAP_SUFFIX = '{}';
18
18
 
19
- export const LIST_SUFFIX = "[]";
19
+ export const LIST_SUFFIX = '[]';
20
20
 
21
- export const MODIFIER_PREFIX = "$.";
21
+ export const MODIFIER_PREFIX = '$.';
22
22
 
23
- export const FILTER_PREFIX = "|";
23
+ export const FILTER_PREFIX = '|';
24
24
 
25
- export const IMPLICIT_SYMBOL = "?";
25
+ export const IMPLICIT_SYMBOL = '?';
26
26
 
27
- export const PREDEF_TYPE_SYMBOL = "@";
27
+ export const PREDEF_TYPE_SYMBOL = '@';
28
28
 
29
- export const NEGATIVE_SYMBOL = "!";
29
+ export const NEGATIVE_SYMBOL = '!';
30
30
 
31
31
  export const KEY_MAP_SUFFIX = `->${MAP_SUFFIX}`;
32
32
 
@@ -34,9 +34,9 @@ export const KEY_LIST_SUFFIX = `->${LIST_SUFFIX}`;
34
34
 
35
35
  export const KEY_ARRAY_SUFFIX = /->\[\s*(\d+)(\s*,\s*(\d+)?)?\s*\]$/;
36
36
 
37
- export const KEY_STRICT_SUFFIX = "->()";
37
+ export const KEY_STRICT_SUFFIX = '->()';
38
38
 
39
- export const KEY_EQUAL_SUFFIX = "->(=)";
39
+ export const KEY_EQUAL_SUFFIX = '->(=)';
40
40
 
41
41
  export enum EFlags {
42
42
 
@@ -123,3 +123,5 @@ export interface IBuiltInTypeCompiler {
123
123
 
124
124
  isElemental(type: string): boolean;
125
125
  }
126
+
127
+ export const RE_VALID_CUSTOM_TYPE_NAME = /^[-:.\w]+$/;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import * as I from "./Internal";
17
+ import * as I from './Internal';
18
18
 
19
19
  export const PREFIX: string = I.MODIFIER_PREFIX;
20
20
 
package/src/lib/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export * from "./InlineCompiler";
18
- export * from "./langs/JavaScript";
19
- export * from "./Compiler";
20
- export * from "./Common";
17
+ export * from './InlineCompiler';
18
+ export * from './langs/JavaScript';
19
+ export * from './Compiler';
20
+ export * from './Common';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,19 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import * as C from "../Common";
17
+ import * as C from '../Common';
18
18
 
19
19
  class JavaScriptLanguage
20
20
  implements C.ILanguageBuilder {
21
21
 
22
22
  public switchCase(expr: string, cases: string[]): string {
23
23
 
24
- return `switch (${expr}) { ${cases.join("")} }`;
24
+ return `switch (${expr}) { ${cases.join('')} }`;
25
25
  }
26
26
 
27
27
  public caseIf(cond: string[], expr: string): string {
28
28
 
29
- return `${cond.map((x) => `case ${x}:`).join(" ")} { ${expr} break; }`;
29
+ return `${cond.map((x) => `case ${x}:`).join(' ')} { ${expr} break; }`;
30
30
  }
31
31
 
32
32
  public caseDefault(expr: string): string {
@@ -61,7 +61,7 @@ implements C.ILanguageBuilder {
61
61
 
62
62
  public call(fnName: string, ...args: string[]): string {
63
63
 
64
- return `${fnName}(${args.join(",")})`;
64
+ return `${fnName}(${args.join(',')})`;
65
65
  }
66
66
 
67
67
  public startsWith(
@@ -105,14 +105,19 @@ implements C.ILanguageBuilder {
105
105
  return conditions[0];
106
106
  }
107
107
 
108
- conditions = this._dereplicate(conditions.filter((x) => x !== "true"));
108
+ if (conditions.includes('true')) {
109
+
110
+ return 'true';
111
+ }
112
+
113
+ conditions = this._dereplicate(conditions.filter((x) => x !== 'false'));
109
114
 
110
115
  if (!conditions.length) {
111
116
 
112
- return "true";
117
+ return 'true';
113
118
  }
114
119
 
115
- return `${conditions.map((x) => `(${x})`).join(" || ")}`;
120
+ return `${conditions.map((x) => `(${x})`).join(' || ')}`;
116
121
  }
117
122
 
118
123
  public and(conditions: string[]): string {
@@ -122,14 +127,19 @@ implements C.ILanguageBuilder {
122
127
  return conditions[0];
123
128
  }
124
129
 
125
- conditions = this._dereplicate(conditions.filter((x) => x !== "true"));
130
+ if (conditions.includes('false')) {
131
+
132
+ return 'false';
133
+ }
134
+
135
+ conditions = this._dereplicate(conditions.filter((x) => x !== 'true'));
126
136
 
127
137
  if (!conditions.length) {
128
138
 
129
- return "true";
139
+ return 'true';
130
140
  }
131
141
 
132
- return `${conditions.map((x) => `(${x})`).join(" && ")}`;
142
+ return `${conditions.map((x) => `(${x})`).join(' && ')}`;
133
143
  }
134
144
 
135
145
  public eq(a: string, b: string | number): string {
@@ -182,11 +192,11 @@ implements C.ILanguageBuilder {
182
192
  regExp: string
183
193
  ): string {
184
194
 
185
- let m = regExp.match(/^\/(.+)\/([a-z]*)$/i);
195
+ const m = /^\/(.+)\/([a-z]*)$/i.exec(regExp);
186
196
 
187
197
  if (m) {
188
198
 
189
- return `/${m[1]}/${m[2] || ""}.test(${expr})`;
199
+ return `/${m[1]}/${m[2] || ''}.test(${expr})`;
190
200
  }
191
201
 
192
202
  return `/${regExp}/.test(${expr})`;
@@ -204,12 +214,12 @@ implements C.ILanguageBuilder {
204
214
 
205
215
  private _equal(positive: boolean = true): string {
206
216
 
207
- return positive ? "===" : "!==";
217
+ return positive ? '===' : '!==';
208
218
  }
209
219
 
210
220
  private _not(positive: boolean = true): string {
211
221
 
212
- return positive ? "" : "!";
222
+ return positive ? '' : '!';
213
223
  }
214
224
 
215
225
  public isString(vn: string, positive: boolean = true): string {
@@ -242,13 +252,13 @@ implements C.ILanguageBuilder {
242
252
  this.isNumber(vn, true),
243
253
  this.and([
244
254
  this.isString(vn, true),
245
- this.matchRegExp(vn, "^[+-]?\\d+(\\.\\d+)?$")
255
+ this.matchRegExp(vn, '^[+-]?\\d+(\\.\\d+)?$')
246
256
  ])
247
257
  ]) : this.and([
248
258
  this.isNumber(vn, false),
249
259
  this.or([
250
260
  this.isString(vn, false),
251
- this.not(this.matchRegExp(vn, "^[+-]?\\d+(\\.\\d+)?$"))
261
+ this.not(this.matchRegExp(vn, '^[+-]?\\d+(\\.\\d+)?$'))
252
262
  ])
253
263
  ]);
254
264
  }
@@ -291,7 +301,7 @@ implements C.ILanguageBuilder {
291
301
 
292
302
  public series(statements: string[]): string {
293
303
 
294
- return statements.map((s) => s.endsWith(";") ? s : `${s};`).join("");
304
+ return statements.map((s) => s.endsWith(';') ? s : `${s};`).join('');
295
305
  }
296
306
 
297
307
  public ifThen(
@@ -369,22 +379,22 @@ implements C.ILanguageBuilder {
369
379
 
370
380
  public get literalFalse(): string {
371
381
 
372
- return `false`;
382
+ return 'false';
373
383
  }
374
384
 
375
385
  public get literalTrue(): string {
376
386
 
377
- return `true`;
387
+ return 'true';
378
388
  }
379
389
 
380
390
  public get maxSafeInteger(): string {
381
391
 
382
- return "0X1FFFFFFFFFFFFF";
392
+ return '0X1FFFFFFFFFFFFF';
383
393
  }
384
394
 
385
395
  public get minSafeInteger(): string {
386
396
 
387
- return "-0X1FFFFFFFFFFFFF";
397
+ return '-0X1FFFFFFFFFFFFF';
388
398
  }
389
399
 
390
400
  public isTrueValue(vn: string): string {
@@ -408,10 +418,10 @@ implements C.ILanguageBuilder {
408
418
  body: string
409
419
  ): string {
410
420
 
411
- return `(function(${params.join(", ")}) {
421
+ return `(function(${params.join(', ')}) {
412
422
  ${body}
413
423
  })(${
414
- args.join(", ")
424
+ args.join(', ')
415
425
  })`;
416
426
  }
417
427
  }