@witchcraft/expressit 0.0.2 → 0.1.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.
- package/README.md +6 -4
- package/dist/Lexer.d.ts +146 -0
- package/dist/Lexer.d.ts.map +1 -0
- package/dist/Lexer.js +960 -0
- package/dist/Parser.d.ts +140 -0
- package/dist/Parser.d.ts.map +1 -0
- package/dist/Parser.js +668 -0
- package/dist/ast/builders/token.js +1 -1
- package/dist/ast/handlers.d.ts +3 -3
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/index.d.ts.map +1 -1
- package/dist/examples/index.d.ts +2 -0
- package/dist/examples/index.d.ts.map +1 -0
- package/dist/examples/index.js +4 -0
- package/dist/examples/shortcutContextParser.d.ts +2 -1
- package/dist/examples/shortcutContextParser.d.ts.map +1 -1
- package/dist/examples/shortcutContextParser.js +9 -5
- package/dist/helpers/errors.d.ts.map +1 -1
- package/dist/helpers/errors.js +3 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/parser/checkParserOpts.d.ts.map +1 -1
- package/dist/helpers/parser/checkParserOpts.js +3 -2
- package/dist/helpers/parser/extractPosition.d.ts +2 -6
- package/dist/helpers/parser/extractPosition.d.ts.map +1 -1
- package/dist/helpers/parser/extractPosition.js +3 -3
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +2 -3
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +1 -1
- package/dist/helpers/parser/getUnclosedRightParenCount.js +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/methods/autocomplete.d.ts.map +1 -1
- package/dist/methods/autocomplete.js +1 -1
- package/dist/methods/autoreplace.js +1 -1
- package/dist/methods/autosuggest.js +1 -1
- package/dist/methods/evaluate.d.ts.map +1 -1
- package/dist/methods/evaluate.js +3 -1
- package/dist/methods/getIndexes.d.ts.map +1 -1
- package/dist/methods/getIndexes.js +2 -1
- package/dist/methods/normalize.d.ts +0 -2
- package/dist/methods/normalize.d.ts.map +1 -1
- package/dist/methods/normalize.js +2 -3
- package/dist/methods/validate.d.ts.map +1 -1
- package/dist/methods/validate.js +3 -1
- package/dist/package.json.js +44 -37
- package/dist/types/ast.d.ts +2 -8
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/errors.d.ts +5 -17
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +0 -1
- package/dist/types/parser.d.ts +6 -2
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +1 -1
- package/dist/utils/getCursorInfo.d.ts +2 -2
- package/dist/utils/getCursorInfo.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +3 -2
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +1 -1
- package/dist/utils/prettyAst.d.ts.map +1 -1
- package/dist/utils/prettyAst.js +15 -9
- package/package.json +42 -37
- package/src/Lexer.ts +704 -0
- package/src/Parser.ts +972 -0
- package/src/ast/builders/array.ts +2 -2
- package/src/ast/builders/condition.ts +1 -1
- package/src/ast/builders/expression.ts +1 -1
- package/src/ast/builders/group.ts +1 -1
- package/src/ast/builders/index.ts +1 -1
- package/src/ast/builders/pos.ts +1 -1
- package/src/ast/builders/token.ts +2 -2
- package/src/ast/builders/type.ts +1 -1
- package/src/ast/builders/variable.ts +1 -1
- package/src/ast/classes/ConditionNode.ts +1 -1
- package/src/ast/classes/ErrorToken.ts +1 -1
- package/src/ast/classes/ValidToken.ts +2 -2
- package/src/ast/classes/index.ts +1 -1
- package/src/ast/handlers.ts +6 -6
- package/src/ast/index.ts +2 -2
- package/src/examples/index.ts +3 -0
- package/src/examples/shortcutContextParser.ts +11 -6
- package/src/helpers/errors.ts +5 -3
- package/src/helpers/general/defaultConditionNormalizer.ts +1 -1
- package/src/helpers/general/index.ts +1 -1
- package/src/helpers/index.ts +3 -2
- package/src/helpers/parser/checkParserOpts.ts +13 -12
- package/src/helpers/parser/extractPosition.ts +4 -8
- package/src/helpers/parser/getUnclosedRightParenCount.ts +6 -6
- package/src/helpers/parser/index.ts +1 -1
- package/src/helpers/parser/parseParserOptions.ts +1 -1
- package/src/index.ts +2 -2
- package/src/methods/autocomplete.ts +5 -5
- package/src/methods/autoreplace.ts +2 -2
- package/src/methods/autosuggest.ts +3 -3
- package/src/methods/evaluate.ts +4 -2
- package/src/methods/getIndexes.ts +2 -1
- package/src/methods/normalize.ts +3 -4
- package/src/methods/validate.ts +4 -2
- package/src/types/ast.ts +2 -9
- package/src/types/errors.ts +12 -22
- package/src/types/parser.ts +6 -4
- package/src/utils/extractTokens.ts +1 -1
- package/src/utils/getCursorInfo.ts +6 -4
- package/src/utils/getOppositeDelimiter.ts +5 -2
- package/src/utils/prettyAst.ts +5 -3
- package/dist/examples/advancedValueComparer.d.ts +0 -3
- package/dist/examples/advancedValueComparer.d.ts.map +0 -1
- package/dist/examples/advancedValueComparer.js +0 -28
- package/dist/grammar/ParserBase.d.ts +0 -51
- package/dist/grammar/ParserBase.d.ts.map +0 -1
- package/dist/grammar/ParserBase.js +0 -516
- package/dist/grammar/createTokens.d.ts +0 -56
- package/dist/grammar/createTokens.d.ts.map +0 -1
- package/dist/grammar/createTokens.js +0 -843
- package/dist/grammar/index.d.ts +0 -3
- package/dist/grammar/index.d.ts.map +0 -1
- package/dist/grammar/index.js +0 -6
- package/dist/parser.d.ts +0 -58
- package/dist/parser.d.ts.map +0 -1
- package/dist/parser.js +0 -136
- package/src/examples/advancedValueComparer.ts +0 -31
- package/src/grammar/ParserBase.ts +0 -715
- package/src/grammar/createTokens.ts +0 -512
- package/src/grammar/index.ts +0 -4
- package/src/parser.ts +0 -183
package/dist/grammar/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/grammar/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/grammar/index.js
DELETED
package/dist/parser.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The parser's methods are often long and have a lot of documentation per method, so it's methods have been split into mixins. They can be found in the `./methods` folder.
|
|
3
|
-
*
|
|
4
|
-
* Writing from within any of these methods is like writing a method from here except:
|
|
5
|
-
* - `this` calls are wrapped in `(this as any as Parser<T>)`
|
|
6
|
-
* - private method/property access requires `// @ts-expect-error`.
|
|
7
|
-
* - recursion with hidden parameters requires re-typing this (see evaluate/validate for examples) since otherwise if we only retyped the function it would become unbound from `this`.
|
|
8
|
-
*
|
|
9
|
-
* Docs work like normal (on methods). From the outside, users of the library cannot even tell the class is composed of mixins.
|
|
10
|
-
*/
|
|
11
|
-
import type { Mixin } from "@alanscodelog/utils";
|
|
12
|
-
import { createTokens } from "./grammar/createTokens.js";
|
|
13
|
-
import { ParserBase } from "./grammar/ParserBase.js";
|
|
14
|
-
import { AutocompleteMixin } from "./methods/autocomplete.js";
|
|
15
|
-
import { AutoreplaceMixin } from "./methods/autoreplace.js";
|
|
16
|
-
import { Autosuggest } from "./methods/autosuggest.js";
|
|
17
|
-
import { EvaluateMixin } from "./methods/evaluate.js";
|
|
18
|
-
import { GetBestIndexesMixin } from "./methods/getBestIndex.js";
|
|
19
|
-
import { GetIndexMixin } from "./methods/getIndexes.js";
|
|
20
|
-
import { NormalizeMixin, ValidateMixin } from "./methods/index.js";
|
|
21
|
-
import type { ParserResults } from "./types/ast.js";
|
|
22
|
-
import type { FullParserOptions, ParserOptions } from "./types/parser.js";
|
|
23
|
-
/**
|
|
24
|
-
* Creates the main parser class which handles all functionality (evaluation, validation, etc).
|
|
25
|
-
*/
|
|
26
|
-
export declare class Parser<T extends {} = {}> {
|
|
27
|
-
options: FullParserOptions<T>;
|
|
28
|
-
private readonly rawOptions;
|
|
29
|
-
parser: ParserBase<T>;
|
|
30
|
-
private readonly lexer;
|
|
31
|
-
private readonly tokens;
|
|
32
|
-
info: ReturnType<typeof createTokens>["info"];
|
|
33
|
-
constructor(options?: ParserOptions<T>);
|
|
34
|
-
/**
|
|
35
|
-
* Parses a string.
|
|
36
|
-
*/
|
|
37
|
-
parse(input: string): ParserResults;
|
|
38
|
-
private evaluationOptionsChecked;
|
|
39
|
-
_checkEvaluationOptions(): void;
|
|
40
|
-
private validationOptionsChecked;
|
|
41
|
-
_checkValidationOptions(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Generates a railroad diagram for debugging. Does not 100% represent how things are actually handled internally.
|
|
44
|
-
*
|
|
45
|
-
* Not exposed because it uses the raw chevrotain tokens.
|
|
46
|
-
*
|
|
47
|
-
* **Note: It is not 100% accurate. Some special cases are parsed one way but handled internally differently.**
|
|
48
|
-
*/
|
|
49
|
-
private _generateRailRoadDiagram;
|
|
50
|
-
/**
|
|
51
|
-
* For debugging.
|
|
52
|
-
* Not exposed because it returns the raw chevrotain tokens.
|
|
53
|
-
*/
|
|
54
|
-
private _lex;
|
|
55
|
-
}
|
|
56
|
-
export interface Parser<T extends {} = {}> extends Mixin<AutocompleteMixin<T> | AutoreplaceMixin | Autosuggest<T> | EvaluateMixin<T> | ValidateMixin<T> | NormalizeMixin<T> | GetIndexMixin<T> | GetBestIndexesMixin>, AutocompleteMixin<T>, AutoreplaceMixin, Autosuggest<T>, EvaluateMixin<T>, ValidateMixin<T>, NormalizeMixin<T>, GetIndexMixin<T>, GetBestIndexesMixin {
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=parser.d.ts.map
|
package/dist/parser.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAKhD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGzE;;GAEG;AACH,qBAAa,MAAM,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE;IACpC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;IAE7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;IAE7C,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;IAErB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAElE,IAAI,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;gBAEjC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;IAYtC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa;IA8CnC,OAAO,CAAC,wBAAwB,CAAiB;IAGjD,uBAAuB,IAAI,IAAI;IAO/B,OAAO,CAAC,wBAAwB,CAAiB;IAGjD,uBAAuB,IAAI,IAAI;IAO/B;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAMhC;;;OAGG;IACH,OAAO,CAAC,IAAI;CAGZ;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,CAAE,SAAQ,KAAK,CACrD,iBAAiB,CAAC,CAAC,CAAC,GACpB,gBAAgB,GAChB,WAAW,CAAC,CAAC,CAAC,GACd,aAAa,CAAC,CAAC,CAAC,GAChB,aAAa,CAAC,CAAC,CAAC,GAChB,cAAc,CAAC,CAAC,CAAC,GACjB,aAAa,CAAC,CAAC,CAAC,GAChB,mBAAmB,CACrB,EACA,iBAAiB,CAAC,CAAC,CAAC,EACpB,gBAAgB,EAChB,WAAW,CAAC,CAAC,CAAC,EACd,aAAa,CAAC,CAAC,CAAC,EAChB,aAAa,CAAG,CAAC,CAAE,EACnB,cAAc,CAAC,CAAC,CAAC,EACjB,aAAa,CAAC,CAAC,CAAC,EAChB,mBAAmB;CAClB"}
|
package/dist/parser.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
import { mixin, isWhitespace } from "@alanscodelog/utils";
|
|
8
|
-
import { createSyntaxDiagramsCode } from "chevrotain";
|
|
9
|
-
import { token } from "./ast/handlers.js";
|
|
10
|
-
import { createTokens } from "./grammar/createTokens.js";
|
|
11
|
-
import { ParserBase } from "./grammar/ParserBase.js";
|
|
12
|
-
import { BooleanParserLibraryError } from "./helpers/errors.js";
|
|
13
|
-
import { checkParserOpts } from "./helpers/parser/checkParserOpts.js";
|
|
14
|
-
import { getUnclosedRightParenCount } from "./helpers/parser/getUnclosedRightParenCount.js";
|
|
15
|
-
import { ERROR_CODES } from "./types/errors.js";
|
|
16
|
-
import { parseParserOptions } from "./helpers/parser/parseParserOptions.js";
|
|
17
|
-
import { seal } from "./helpers/parser/seal.js";
|
|
18
|
-
import { AutocompleteMixin } from "./methods/autocomplete.js";
|
|
19
|
-
import { AutoreplaceMixin } from "./methods/autoreplace.js";
|
|
20
|
-
import { Autosuggest } from "./methods/autosuggest.js";
|
|
21
|
-
import { EvaluateMixin } from "./methods/evaluate.js";
|
|
22
|
-
import { GetBestIndexesMixin } from "./methods/getBestIndex.js";
|
|
23
|
-
import { GetIndexMixin } from "./methods/getIndexes.js";
|
|
24
|
-
import { NormalizeMixin } from "./methods/normalize.js";
|
|
25
|
-
import { ValidateMixin } from "./methods/validate.js";
|
|
26
|
-
class Parser {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
__publicField(this, "options");
|
|
29
|
-
__publicField(this, "rawOptions");
|
|
30
|
-
__publicField(this, "parser");
|
|
31
|
-
__publicField(this, "lexer");
|
|
32
|
-
__publicField(this, "tokens");
|
|
33
|
-
__publicField(this, "info");
|
|
34
|
-
// needed for evaluate and validate so they are only checked on demand
|
|
35
|
-
__publicField(this, "evaluationOptionsChecked", false);
|
|
36
|
-
__publicField(this, "validationOptionsChecked", false);
|
|
37
|
-
this.rawOptions = options ?? {};
|
|
38
|
-
const opts = parseParserOptions(this.rawOptions);
|
|
39
|
-
checkParserOpts(opts);
|
|
40
|
-
this.options = opts;
|
|
41
|
-
const { lexer, tokens, info } = createTokens(opts);
|
|
42
|
-
this.lexer = lexer;
|
|
43
|
-
this.tokens = tokens;
|
|
44
|
-
this.info = info;
|
|
45
|
-
this.parser = new ParserBase(opts, this.tokens, this.info);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parses a string.
|
|
49
|
-
*/
|
|
50
|
-
parse(input) {
|
|
51
|
-
var _a;
|
|
52
|
-
if (isWhitespace(input)) {
|
|
53
|
-
return token.value(void 0, { start: 0, end: 0 });
|
|
54
|
-
}
|
|
55
|
-
let lexed = this._lex(input);
|
|
56
|
-
const shift = getUnclosedRightParenCount(lexed.tokens, this.tokens);
|
|
57
|
-
if (shift) {
|
|
58
|
-
input = "(".repeat(shift) + input;
|
|
59
|
-
lexed = this._lex(input);
|
|
60
|
-
}
|
|
61
|
-
this.parser.shift = shift;
|
|
62
|
-
this.parser.input = lexed.tokens;
|
|
63
|
-
this.parser.rawInput = input;
|
|
64
|
-
try {
|
|
65
|
-
if (lexed.errors.length > 0)
|
|
66
|
-
throw new Error("Unexpected Lexer Errors");
|
|
67
|
-
this.parser.input = lexed.tokens;
|
|
68
|
-
const res = this.parser.main();
|
|
69
|
-
if (res === void 0) {
|
|
70
|
-
throw new Error("throw");
|
|
71
|
-
}
|
|
72
|
-
if (!((_a = arguments[1]) == null ? void 0 : _a.unsealed))
|
|
73
|
-
seal(res);
|
|
74
|
-
return res;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (error.message === "throw")
|
|
77
|
-
error = void 0;
|
|
78
|
-
const err = new BooleanParserLibraryError(ERROR_CODES.PARSER_ERROR, {
|
|
79
|
-
input,
|
|
80
|
-
options: this.rawOptions,
|
|
81
|
-
"parsed options": this.options,
|
|
82
|
-
error,
|
|
83
|
-
"lexed tokens": lexed.tokens,
|
|
84
|
-
"lexer errors": lexed.errors,
|
|
85
|
-
"parser errors": this.parser.errors
|
|
86
|
-
});
|
|
87
|
-
throw err;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
91
|
-
_checkEvaluationOptions() {
|
|
92
|
-
if (!this.evaluationOptionsChecked) {
|
|
93
|
-
checkParserOpts(this.options, true);
|
|
94
|
-
this.evaluationOptionsChecked = true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
98
|
-
_checkValidationOptions() {
|
|
99
|
-
if (!this.validationOptionsChecked) {
|
|
100
|
-
checkParserOpts(this.options, false, true);
|
|
101
|
-
this.validationOptionsChecked = true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Generates a railroad diagram for debugging. Does not 100% represent how things are actually handled internally.
|
|
106
|
-
*
|
|
107
|
-
* Not exposed because it uses the raw chevrotain tokens.
|
|
108
|
-
*
|
|
109
|
-
* **Note: It is not 100% accurate. Some special cases are parsed one way but handled internally differently.**
|
|
110
|
-
*/
|
|
111
|
-
_generateRailRoadDiagram() {
|
|
112
|
-
const serialized = this.parser.getSerializedGastProductions();
|
|
113
|
-
const html = createSyntaxDiagramsCode(serialized);
|
|
114
|
-
return html;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* For debugging.
|
|
118
|
-
* Not exposed because it returns the raw chevrotain tokens.
|
|
119
|
-
*/
|
|
120
|
-
_lex(input) {
|
|
121
|
-
return this.lexer.tokenize(input);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
mixin(Parser, [
|
|
125
|
-
AutocompleteMixin,
|
|
126
|
-
AutoreplaceMixin,
|
|
127
|
-
Autosuggest,
|
|
128
|
-
EvaluateMixin,
|
|
129
|
-
ValidateMixin,
|
|
130
|
-
NormalizeMixin,
|
|
131
|
-
GetIndexMixin,
|
|
132
|
-
GetBestIndexesMixin
|
|
133
|
-
]);
|
|
134
|
-
export {
|
|
135
|
-
Parser
|
|
136
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ValueQuery } from "../types/parser.js"
|
|
2
|
-
|
|
3
|
-
/* TODO TOUPDATE */
|
|
4
|
-
type Operators = ">" | "contains"
|
|
5
|
-
type Prefixes = "num"
|
|
6
|
-
export function valueComparer(contextValue: string, { operator, prefix, value, isRegex, regexFlags }: ValueQuery): boolean {
|
|
7
|
-
let finalValue: any = value
|
|
8
|
-
if (prefix) {
|
|
9
|
-
const val = value as string // it's always a string if prefixed
|
|
10
|
-
switch (prefix as Prefixes) {
|
|
11
|
-
case "num": finalValue = parseInt(val, 2); break
|
|
12
|
-
// ...
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (isRegex) {
|
|
16
|
-
const val = value as string // it's always a string and never prefixed if it's a regex
|
|
17
|
-
const regex = new RegExp(val, regexFlags)
|
|
18
|
-
return contextValue.match(regex) !== null
|
|
19
|
-
}
|
|
20
|
-
if (operator) {
|
|
21
|
-
switch (operator as Operators) {
|
|
22
|
-
// custom operators
|
|
23
|
-
case ">": return contextValue > finalValue
|
|
24
|
-
// ...
|
|
25
|
-
// custom expanded operators
|
|
26
|
-
case "contains": return contextValue.includes(finalValue)
|
|
27
|
-
// ...
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return contextValue === finalValue
|
|
31
|
-
}
|