@ptolemy2002/rgx 12.1.0 → 12.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.
- package/dist/class/base.d.ts +1 -0
- package/dist/class/base.js +4 -1
- package/dist/class/init.js +14 -0
- package/package.json +1 -1
package/dist/class/base.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare abstract class RGXClassToken implements RGXConvertibleToken {
|
|
|
12
12
|
rgxAcceptInsertion(tokens: RGXToken[], flags: ValidRegexFlags): string | boolean;
|
|
13
13
|
static check: (value: unknown) => value is RGXClassToken;
|
|
14
14
|
static assert: (value: unknown) => asserts value is RGXClassToken;
|
|
15
|
+
get rgxInterpolate(): boolean;
|
|
15
16
|
get rgxIsGroup(): boolean;
|
|
16
17
|
get rgxIsRepeatable(): boolean;
|
|
17
18
|
get rgxGroupWrap(): boolean;
|
package/dist/class/base.js
CHANGED
|
@@ -7,6 +7,9 @@ class RGXClassToken {
|
|
|
7
7
|
rgxAcceptInsertion(tokens, flags) {
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
|
+
get rgxInterpolate() {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
10
13
|
get rgxIsGroup() {
|
|
11
14
|
return false;
|
|
12
15
|
}
|
|
@@ -26,7 +29,7 @@ class RGXClassToken {
|
|
|
26
29
|
throw new errors_1.RGXNotImplementedError('RGXClassToken.repeat(min, max, lazy)', 'call rgxClassInit() first.');
|
|
27
30
|
}
|
|
28
31
|
optional(lazy = false) {
|
|
29
|
-
|
|
32
|
+
throw new errors_1.RGXNotImplementedError('RGXClassToken.optional(lazy)', 'call rgxClassInit() first.');
|
|
30
33
|
}
|
|
31
34
|
asLookahead(positive = true) {
|
|
32
35
|
throw new errors_1.RGXNotImplementedError('RGXClassToken.asLookahead(positive)', 'call rgxClassInit() first.');
|
package/dist/class/init.js
CHANGED
|
@@ -33,6 +33,20 @@ function rgxClassInit() {
|
|
|
33
33
|
throw new errors_1.RGXNotSupportedError("RGXLookaroundToken.repeat()", "Lookaround tokens cannot be repeated or made optional.");
|
|
34
34
|
return new repeat_1.RGXRepeatToken(this, min, max, lazy);
|
|
35
35
|
};
|
|
36
|
+
base_1.RGXClassToken.prototype.optional = function (lazy = false) {
|
|
37
|
+
if (repeat_1.RGXRepeatToken.check(this)) {
|
|
38
|
+
// Retun the self if already optional.
|
|
39
|
+
if (this.min === 0)
|
|
40
|
+
return this;
|
|
41
|
+
// Simply set min to 0 if it's currently 1,
|
|
42
|
+
// but not if it's any other number, since
|
|
43
|
+
// "either 0 or > 0" is not the same as "either 0 or >= n" for n > 1,
|
|
44
|
+
// but they are equivalent for n = 1, assuming n is an integer.
|
|
45
|
+
else if (this.min === 1)
|
|
46
|
+
return new repeat_1.RGXRepeatToken(this.token, 0, this.max, lazy);
|
|
47
|
+
}
|
|
48
|
+
return this.repeat(0, 1, lazy);
|
|
49
|
+
};
|
|
36
50
|
base_1.RGXClassToken.prototype.asLookahead = function (positive = true) {
|
|
37
51
|
if (lookahead_1.RGXLookaheadToken.check(this))
|
|
38
52
|
return this;
|