@ptolemy2002/rgx 4.7.0 → 4.8.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 +76 -6
- package/dist/class/base.d.ts +5 -0
- package/dist/class/base.js +9 -0
- package/dist/class/index.d.ts +3 -0
- package/dist/class/index.js +3 -0
- package/dist/class/init.js +16 -0
- package/dist/class/lookahead.d.ts +11 -0
- package/dist/class/lookahead.js +26 -0
- package/dist/class/lookaround.d.ts +18 -0
- package/dist/class/lookaround.js +47 -0
- package/dist/class/lookbehind.d.ts +12 -0
- package/dist/class/lookbehind.js +26 -0
- package/dist/class/repeat.js +3 -0
- package/dist/errors/base.d.ts +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/notSupported.d.ts +6 -0
- package/dist/errors/notSupported.js +19 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ type RGXTokenFromType<T extends RGXTokenTypeGuardInput> =
|
|
|
44
44
|
// ... see source for full definition
|
|
45
45
|
;
|
|
46
46
|
|
|
47
|
-
type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT';
|
|
47
|
+
type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'NOT_SUPPORTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT';
|
|
48
48
|
|
|
49
49
|
type RangeObject = {
|
|
50
50
|
min?: number | null;
|
|
@@ -143,6 +143,19 @@ constructor(functionality: string, message?: string | null)
|
|
|
143
143
|
#### Properties
|
|
144
144
|
- `functionality` (`string`): The description of the unimplemented functionality.
|
|
145
145
|
|
|
146
|
+
### RGXNotSupportedError extends RGXError
|
|
147
|
+
A specific error class for unsupported functionality. This error is thrown when a feature or method is intentionally not supported (as opposed to simply not yet implemented). The error code is set to `NOT_SUPPORTED` on instantiation.
|
|
148
|
+
|
|
149
|
+
#### Constructor
|
|
150
|
+
```typescript
|
|
151
|
+
constructor(functionality: string, message?: string | null)
|
|
152
|
+
```
|
|
153
|
+
- `functionality` (`string`): A description of the functionality that is not supported.
|
|
154
|
+
- `message` (`string | null`, optional): An optional additional message providing more context. Defaults to `null`.
|
|
155
|
+
|
|
156
|
+
#### Properties
|
|
157
|
+
- `functionality` (`string`): The description of the unsupported functionality.
|
|
158
|
+
|
|
146
159
|
### RGXInvalidIdentifierError extends RGXError
|
|
147
160
|
A specific error class for invalid identifiers. This error is thrown when a string fails validation as a valid identifier. The error code is set to `INVALID_IDENTIFIER` on instantiation.
|
|
148
161
|
|
|
@@ -262,14 +275,17 @@ An abstract base class for creating custom RGX token classes. Subclasses must im
|
|
|
262
275
|
|
|
263
276
|
#### Properties
|
|
264
277
|
- `isGroup` (`boolean`): Returns `false` by default. Subclasses can override this to indicate whether the token represents a group.
|
|
278
|
+
- `isRepeatable` (`boolean`): Returns `true` by default. Subclasses can override this to indicate that the token cannot be wrapped in an `RGXRepeatToken`. When `false`, attempting to set this token as the `token` property of an `RGXRepeatToken` (including via `repeat()` or `optional()`) will throw an `RGXNotSupportedError`.
|
|
265
279
|
- `rgxGroupWrap` (`boolean`): Returns `true` by default. Controls whether the resolver wraps this token's resolved output in a non-capturing group. Subclasses can override this to prevent double-wrapping (e.g., when the token already wraps itself in a group).
|
|
266
280
|
|
|
267
281
|
#### Methods
|
|
268
282
|
- `or(...others: RGXTokenCollectionInput[]) => RGXClassUnionToken`: Creates an `RGXClassUnionToken` that represents a union (alternation) of this token with the provided others. If any of the `others` are `RGXClassUnionToken` instances, their tokens are flattened into the union rather than nested. If `this` is already an `RGXClassUnionToken`, its existing tokens are preserved and the others are appended.
|
|
269
283
|
- `group(args?: RGXGroupTokenArgs) => RGXGroupToken`: Wraps this token in an `RGXGroupToken` with the provided arguments. The `args` parameter defaults to `{}`, which creates a capturing group with no name. This is a convenience method that creates a new `RGXGroupToken` with `this` as the sole token.
|
|
270
|
-
- `repeat(min?: number, max?: number | null) => RGXRepeatToken`: Wraps this token in an `RGXRepeatToken` with the given repetition bounds. `min` defaults to `1`, `max` defaults to `min`. Pass `null` for `max` to allow unlimited repetitions. This is a convenience method that creates a new `RGXRepeatToken` with `this` as the token.
|
|
271
|
-
- `optional() => RGXRepeatToken`: Shorthand for `repeat(0, 1)`. Wraps this token in an `RGXRepeatToken` that matches the token zero or one times.
|
|
272
|
-
- `
|
|
284
|
+
- `repeat(min?: number, max?: number | null) => RGXRepeatToken`: Wraps this token in an `RGXRepeatToken` with the given repetition bounds. `min` defaults to `1`, `max` defaults to `min`. Pass `null` for `max` to allow unlimited repetitions. This is a convenience method that creates a new `RGXRepeatToken` with `this` as the token. Throws `RGXNotSupportedError` if called on an `RGXLookaroundToken`, as lookaround assertions cannot be repeated.
|
|
285
|
+
- `optional() => RGXRepeatToken`: Shorthand for `repeat(0, 1)`. Wraps this token in an `RGXRepeatToken` that matches the token zero or one times. Throws `RGXNotSupportedError` if called on an `RGXLookaroundToken`, as lookaround assertions cannot be made optional.
|
|
286
|
+
- `asLookahead(positive?: boolean) => RGXLookaheadToken`: Wraps this token in an `RGXLookaheadToken`. `positive` defaults to `true`. If this token is already an `RGXLookaheadToken`, it is returned as-is without re-wrapping.
|
|
287
|
+
- `asLookbehind(positive?: boolean) => RGXLookbehindToken`: Wraps this token in an `RGXLookbehindToken`. `positive` defaults to `true`. If this token is already an `RGXLookbehindToken`, it is returned as-is without re-wrapping.
|
|
288
|
+
- `resolve() => ValidRegexString`: A convenience method that resolves this token by calling `resolveRGXToken(this)`, returning the resolved regex string representation. Since this method is defined on `RGXClassToken`, it is available on all subclasses including `RGXClassUnionToken`, `RGXGroupToken`, `RGXRepeatToken`, and `RGXLookaroundToken`.
|
|
273
289
|
|
|
274
290
|
### RGXClassUnionToken extends RGXClassToken
|
|
275
291
|
A class representing a union (alternation) of RGX tokens. This is typically created via the `or()` method on `RGXClassToken`, but can also be instantiated directly.
|
|
@@ -340,7 +356,7 @@ constructor(token: RGXToken, min?: number, max?: number | null)
|
|
|
340
356
|
- `max` (`number | null`, optional): The maximum number of repetitions. Must be >= `min` when not `null`. Non-integer values are floored. Pass `null` for unlimited repetitions. Defaults to `min`.
|
|
341
357
|
|
|
342
358
|
#### Properties
|
|
343
|
-
- `token` (`RGXGroupedToken`): The token being repeated. Setting this will automatically wrap non-grouped tokens in a non-capturing `RGXGroupToken`.
|
|
359
|
+
- `token` (`RGXGroupedToken`): The token being repeated. Setting this will throw `RGXNotSupportedError` if the value is a class token with `isRepeatable` set to `false`, and will automatically wrap non-grouped tokens in a non-capturing `RGXGroupToken`.
|
|
344
360
|
- `min` (`number`): The minimum number of repetitions. Setting this validates that the value is >= 0 and <= `max` (when `max` is not `null`), and floors non-integer values. Throws `RGXOutOfBoundsError` if validation fails.
|
|
345
361
|
- `max` (`number | null`): The maximum number of repetitions. Setting this validates that the value is >= `min` when not `null`, and floors non-integer values. Pass `null` for unlimited. Throws `RGXOutOfBoundsError` if validation fails.
|
|
346
362
|
- `repeaterSuffix` (`string`): Returns the regex quantifier suffix based on the current `min` and `max` values: `*` for `{0,}`, `+` for `{1,}`, `?` for `{0,1}`, `{n}` for exact repetitions, `{n,}` for minimum-only, `{n,m}` for a range, or an empty string for `{1,1}` (exactly once, no quantifier needed).
|
|
@@ -349,6 +365,60 @@ constructor(token: RGXToken, min?: number, max?: number | null)
|
|
|
349
365
|
#### Methods
|
|
350
366
|
- `toRgx() => RGXToken`: Resolves the repeat token to a `RegExp` by resolving the inner token and appending the `repeaterSuffix`. Returns `null` (a no-op) when both `min` and `max` are `0`.
|
|
351
367
|
|
|
368
|
+
### RGXLookaroundToken extends RGXClassToken (abstract)
|
|
369
|
+
An abstract base class for lookaround assertion tokens (lookahead and lookbehind). Lookaround assertions match a pattern without consuming characters in the string. Subclasses must implement the `toRgx()`, `negate()`, and `reverse()` methods.
|
|
370
|
+
|
|
371
|
+
#### Static Properties
|
|
372
|
+
- `check(value: unknown): value is RGXLookaroundToken`: A type guard that checks if the given value is an instance of `RGXLookaroundToken`.
|
|
373
|
+
- `assert(value: unknown): asserts value is RGXLookaroundToken`: An assertion that checks if the given value is an instance of `RGXLookaroundToken`. If the assertion fails, an `RGXInvalidTokenError` will be thrown.
|
|
374
|
+
|
|
375
|
+
#### Constructor
|
|
376
|
+
```typescript
|
|
377
|
+
constructor(tokens?: RGXTokenCollectionInput, positive?: boolean)
|
|
378
|
+
```
|
|
379
|
+
- `tokens` (`RGXTokenCollectionInput`, optional): The tokens to include in the lookaround. Internally stored as an `RGXTokenCollection` in 'concat' mode. Defaults to an empty array.
|
|
380
|
+
- `positive` (`boolean`, optional): Whether the lookaround is positive (matches if the pattern is present) or negative (matches if the pattern is absent). Defaults to `true`.
|
|
381
|
+
|
|
382
|
+
#### Properties
|
|
383
|
+
- `tokens` (`RGXTokenCollection`): The internal collection of tokens managed in 'concat' mode.
|
|
384
|
+
- `positive` (`boolean`): Whether the lookaround is positive. Setting this updates `negative` accordingly.
|
|
385
|
+
- `negative` (`boolean`): Whether the lookaround is negative. Setting this updates `positive` accordingly.
|
|
386
|
+
- `isGroup` (`true`): Returns `true` as a constant, indicating this token represents a group.
|
|
387
|
+
- `isRepeatable` (`false`): Returns `false` as a constant, since lookaround assertions cannot be repeated.
|
|
388
|
+
- `rgxGroupWrap` (`false`): Returns `false` as a constant, since the lookaround already wraps itself in a group.
|
|
389
|
+
|
|
390
|
+
#### Abstract Methods
|
|
391
|
+
- `negate() => RGXLookaroundToken`: Returns a new lookaround token of the same type with the opposite positivity, preserving the original tokens.
|
|
392
|
+
- `reverse() => RGXLookaroundToken`: Returns a new lookaround token of the opposite direction (lookahead becomes lookbehind and vice versa), preserving the original tokens and positivity.
|
|
393
|
+
|
|
394
|
+
### RGXLookaheadToken extends RGXLookaroundToken
|
|
395
|
+
A class representing a lookahead assertion. Positive lookaheads (`(?=...)`) match if the pattern is present ahead, while negative lookaheads (`(?!...)`) match if the pattern is absent. This is typically created via the `asLookahead()` method on `RGXClassToken`, but can also be instantiated directly.
|
|
396
|
+
|
|
397
|
+
A function `rgxLookahead` is provided with the same parameters as this class' constructor, for easier instantiation without needing to use the `new` keyword.
|
|
398
|
+
|
|
399
|
+
#### Static Properties
|
|
400
|
+
- `check(value: unknown): value is RGXLookaheadToken`: A type guard that checks if the given value is an instance of `RGXLookaheadToken`.
|
|
401
|
+
- `assert(value: unknown): asserts value is RGXLookaheadToken`: An assertion that checks if the given value is an instance of `RGXLookaheadToken`. If the assertion fails, an `RGXInvalidTokenError` will be thrown.
|
|
402
|
+
|
|
403
|
+
#### Methods
|
|
404
|
+
- `negate() => RGXLookaheadToken`: Returns a new `RGXLookaheadToken` with the opposite positivity, preserving the original tokens.
|
|
405
|
+
- `reverse() => RGXLookbehindToken`: Returns a new `RGXLookbehindToken` with the same tokens and positivity.
|
|
406
|
+
- `toRgx() => RegExp`: Resolves the lookahead to a `RegExp`. Positive lookaheads produce `(?=...)` and negative lookaheads produce `(?!...)`.
|
|
407
|
+
|
|
408
|
+
### RGXLookbehindToken extends RGXLookaroundToken
|
|
409
|
+
A class representing a lookbehind assertion. Positive lookbehinds (`(?<=...)`) match if the pattern is present behind, while negative lookbehinds (`(?<!...)`) match if the pattern is absent. This is typically created via the `asLookbehind()` method on `RGXClassToken`, but can also be instantiated directly.
|
|
410
|
+
|
|
411
|
+
A function `rgxLookbehind` is provided with the same parameters as this class' constructor, for easier instantiation without needing to use the `new` keyword.
|
|
412
|
+
|
|
413
|
+
#### Static Properties
|
|
414
|
+
- `check(value: unknown): value is RGXLookbehindToken`: A type guard that checks if the given value is an instance of `RGXLookbehindToken`.
|
|
415
|
+
- `assert(value: unknown): asserts value is RGXLookbehindToken`: An assertion that checks if the given value is an instance of `RGXLookbehindToken`. If the assertion fails, an `RGXInvalidTokenError` will be thrown.
|
|
416
|
+
|
|
417
|
+
#### Methods
|
|
418
|
+
- `negate() => RGXLookbehindToken`: Returns a new `RGXLookbehindToken` with the opposite positivity, preserving the original tokens.
|
|
419
|
+
- `reverse() => RGXLookaheadToken`: Returns a new `RGXLookaheadToken` with the same tokens and positivity.
|
|
420
|
+
- `toRgx() => RegExp`: Resolves the lookbehind to a `RegExp`. Positive lookbehinds produce `(?<=...)` and negative lookbehinds produce `(?<!...)`.
|
|
421
|
+
|
|
352
422
|
### ExtRegExp extends RegExp
|
|
353
423
|
A subclass of `RegExp` that supports custom flag transformers in addition to the standard vanilla regex flags (g, i, m, s, u, y). When constructed, custom flags are extracted, their corresponding transformers are applied to the pattern and vanilla flags, and the resulting transformed `RegExp` is created. The `flags` getter returns both the vanilla flags and any custom flags.
|
|
354
424
|
|
|
@@ -850,7 +920,7 @@ Removes duplicate tokens from the provided list using `Set` equality and returns
|
|
|
850
920
|
function rgxClassInit(): void
|
|
851
921
|
```
|
|
852
922
|
|
|
853
|
-
Initializes internal method patches required for `RGXClassToken` subclass methods (such as `or`, `group`, and `
|
|
923
|
+
Initializes internal method patches required for `RGXClassToken` subclass methods (such as `or`, `group`, `repeat`, `asLookahead`, and `asLookbehind`) to work correctly. This function is called automatically when importing from the main module entry point, so you typically do not need to call it yourself. It only needs to be called manually if you import directly from sub-modules.
|
|
854
924
|
|
|
855
925
|
### isInRange
|
|
856
926
|
```typescript
|
package/dist/class/base.d.ts
CHANGED
|
@@ -3,15 +3,20 @@ import { RGXTokenCollectionInput } from "../collection";
|
|
|
3
3
|
import type { RGXClassUnionToken } from "./union";
|
|
4
4
|
import type { RGXGroupToken, RGXGroupTokenArgs } from "./group";
|
|
5
5
|
import type { RGXRepeatToken } from "./repeat";
|
|
6
|
+
import type { RGXLookaheadToken } from "./lookahead";
|
|
7
|
+
import type { RGXLookbehindToken } from "./lookbehind";
|
|
6
8
|
export declare abstract class RGXClassToken {
|
|
7
9
|
abstract toRgx(): RGXToken;
|
|
8
10
|
static check: (value: unknown) => value is RGXClassToken;
|
|
9
11
|
static assert: (value: unknown) => asserts value is RGXClassToken;
|
|
10
12
|
get isGroup(): boolean;
|
|
13
|
+
get isRepeatable(): boolean;
|
|
11
14
|
get rgxGroupWrap(): boolean;
|
|
12
15
|
or(...others: RGXTokenCollectionInput[]): RGXClassUnionToken;
|
|
13
16
|
group(args?: RGXGroupTokenArgs): RGXGroupToken;
|
|
14
17
|
repeat(min?: number, max?: number | null): RGXRepeatToken;
|
|
15
18
|
optional(): RGXRepeatToken;
|
|
19
|
+
asLookahead(positive?: boolean): RGXLookaheadToken;
|
|
20
|
+
asLookbehind(positive?: boolean): RGXLookbehindToken;
|
|
16
21
|
resolve(): ValidRegexString;
|
|
17
22
|
}
|
package/dist/class/base.js
CHANGED
|
@@ -7,6 +7,9 @@ class RGXClassToken {
|
|
|
7
7
|
get isGroup() {
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
|
+
get isRepeatable() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
10
13
|
get rgxGroupWrap() {
|
|
11
14
|
return true;
|
|
12
15
|
}
|
|
@@ -22,6 +25,12 @@ class RGXClassToken {
|
|
|
22
25
|
optional() {
|
|
23
26
|
return this.repeat(0, 1);
|
|
24
27
|
}
|
|
28
|
+
asLookahead(positive = true) {
|
|
29
|
+
throw new errors_1.RGXNotImplementedError('RGXClassToken.asLookahead(positive)', 'call rgxClassInit() first.');
|
|
30
|
+
}
|
|
31
|
+
asLookbehind(positive = true) {
|
|
32
|
+
throw new errors_1.RGXNotImplementedError('RGXClassToken.asLookbehind(positive)', 'call rgxClassInit() first.');
|
|
33
|
+
}
|
|
25
34
|
resolve() {
|
|
26
35
|
return (0, resolve_1.resolveRGXToken)(this);
|
|
27
36
|
}
|
package/dist/class/index.d.ts
CHANGED
package/dist/class/index.js
CHANGED
|
@@ -19,3 +19,6 @@ __exportStar(require("./base"), exports);
|
|
|
19
19
|
__exportStar(require("./union"), exports);
|
|
20
20
|
__exportStar(require("./group"), exports);
|
|
21
21
|
__exportStar(require("./repeat"), exports);
|
|
22
|
+
__exportStar(require("./lookaround"), exports);
|
|
23
|
+
__exportStar(require("./lookahead"), exports);
|
|
24
|
+
__exportStar(require("./lookbehind"), exports);
|
package/dist/class/init.js
CHANGED
|
@@ -5,6 +5,10 @@ const base_1 = require("./base");
|
|
|
5
5
|
const union_1 = require("./union");
|
|
6
6
|
const group_1 = require("./group");
|
|
7
7
|
const repeat_1 = require("./repeat");
|
|
8
|
+
const lookaround_1 = require("./lookaround");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const lookahead_1 = require("./lookahead");
|
|
11
|
+
const lookbehind_1 = require("./lookbehind");
|
|
8
12
|
function rgxClassInit() {
|
|
9
13
|
// Patch RGXClassToken here, Since classes like RGXClassUnionToken are instances of RGXClassToken
|
|
10
14
|
// themselves. If we tried to import RGXClassUnionToken in base.ts, it would cause a circular dependency.
|
|
@@ -25,6 +29,18 @@ function rgxClassInit() {
|
|
|
25
29
|
return new group_1.RGXGroupToken(args, [this]);
|
|
26
30
|
};
|
|
27
31
|
base_1.RGXClassToken.prototype.repeat = function (min = 1, max = min) {
|
|
32
|
+
if (lookaround_1.RGXLookaroundToken.check(this))
|
|
33
|
+
throw new errors_1.RGXNotSupportedError("RGXLookaroundToken.repeat()", "Lookaround tokens cannot be repeated or made optional.");
|
|
28
34
|
return new repeat_1.RGXRepeatToken(this, min, max);
|
|
29
35
|
};
|
|
36
|
+
base_1.RGXClassToken.prototype.asLookahead = function (positive = true) {
|
|
37
|
+
if (lookahead_1.RGXLookaheadToken.check(this))
|
|
38
|
+
return this;
|
|
39
|
+
return new lookahead_1.RGXLookaheadToken([this], positive);
|
|
40
|
+
};
|
|
41
|
+
base_1.RGXClassToken.prototype.asLookbehind = function (positive = true) {
|
|
42
|
+
if (lookbehind_1.RGXLookbehindToken.check(this))
|
|
43
|
+
return this;
|
|
44
|
+
return new lookbehind_1.RGXLookbehindToken([this], positive);
|
|
45
|
+
};
|
|
30
46
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RGXToken } from "../types";
|
|
2
|
+
import { RGXLookaroundToken } from "./lookaround";
|
|
3
|
+
import { RGXLookbehindToken } from "./lookbehind";
|
|
4
|
+
export declare class RGXLookaheadToken extends RGXLookaroundToken {
|
|
5
|
+
static check: (value: unknown) => value is RGXLookaheadToken;
|
|
6
|
+
static assert: (value: unknown) => asserts value is RGXLookaheadToken;
|
|
7
|
+
negate(): RGXLookaheadToken;
|
|
8
|
+
reverse(): RGXLookbehindToken;
|
|
9
|
+
toRgx(): RGXToken;
|
|
10
|
+
}
|
|
11
|
+
export declare const rgxLookahead: (tokens?: import("..").RGXTokenCollectionInput, positive?: boolean | undefined) => RGXLookaheadToken;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rgxLookahead = exports.RGXLookaheadToken = void 0;
|
|
4
|
+
const internal_1 = require("../internal");
|
|
5
|
+
const lookaround_1 = require("./lookaround");
|
|
6
|
+
const lookbehind_1 = require("./lookbehind");
|
|
7
|
+
class RGXLookaheadToken extends lookaround_1.RGXLookaroundToken {
|
|
8
|
+
negate() {
|
|
9
|
+
return new RGXLookaheadToken(this.tokens, !this.positive);
|
|
10
|
+
}
|
|
11
|
+
reverse() {
|
|
12
|
+
return new lookbehind_1.RGXLookbehindToken(this.tokens, this.positive);
|
|
13
|
+
}
|
|
14
|
+
toRgx() {
|
|
15
|
+
let result = this.tokens.toRgx().source;
|
|
16
|
+
if (this.positive)
|
|
17
|
+
result = `(?=${result})`;
|
|
18
|
+
else
|
|
19
|
+
result = `(?!${result})`;
|
|
20
|
+
return new RegExp(result);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.RGXLookaheadToken = RGXLookaheadToken;
|
|
24
|
+
RGXLookaheadToken.check = (0, internal_1.createClassGuardFunction)(RGXLookaheadToken);
|
|
25
|
+
RGXLookaheadToken.assert = (0, internal_1.createAssertClassGuardFunction)(RGXLookaheadToken);
|
|
26
|
+
exports.rgxLookahead = (0, internal_1.createConstructFunction)(RGXLookaheadToken);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RGXTokenCollection, RGXTokenCollectionInput } from "../collection";
|
|
2
|
+
import { RGXClassToken } from "./base";
|
|
3
|
+
export declare abstract class RGXLookaroundToken extends RGXClassToken {
|
|
4
|
+
tokens: RGXTokenCollection;
|
|
5
|
+
_negative: boolean;
|
|
6
|
+
static check: (value: unknown) => value is RGXLookaroundToken;
|
|
7
|
+
static assert: (value: unknown) => asserts value is RGXLookaroundToken;
|
|
8
|
+
get isGroup(): true;
|
|
9
|
+
get isRepeatable(): false;
|
|
10
|
+
get rgxGroupWrap(): false;
|
|
11
|
+
set negative(value: boolean);
|
|
12
|
+
get negative(): boolean;
|
|
13
|
+
set positive(value: boolean);
|
|
14
|
+
get positive(): boolean;
|
|
15
|
+
constructor(tokens?: RGXTokenCollectionInput, positive?: boolean);
|
|
16
|
+
abstract negate(): RGXLookaroundToken;
|
|
17
|
+
abstract reverse(): RGXLookaroundToken;
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGXLookaroundToken = void 0;
|
|
4
|
+
const collection_1 = require("../collection");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
class RGXLookaroundToken extends base_1.RGXClassToken {
|
|
8
|
+
get isGroup() {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
get isRepeatable() {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
get rgxGroupWrap() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
set negative(value) {
|
|
18
|
+
this._negative = value;
|
|
19
|
+
}
|
|
20
|
+
get negative() {
|
|
21
|
+
return this._negative;
|
|
22
|
+
}
|
|
23
|
+
set positive(value) {
|
|
24
|
+
this.negative = !value;
|
|
25
|
+
}
|
|
26
|
+
get positive() {
|
|
27
|
+
return !this.negative;
|
|
28
|
+
}
|
|
29
|
+
constructor(tokens = [], positive = true) {
|
|
30
|
+
super();
|
|
31
|
+
this._negative = false;
|
|
32
|
+
this.positive = positive;
|
|
33
|
+
if (tokens instanceof collection_1.RGXTokenCollection && tokens.mode === 'union')
|
|
34
|
+
this.tokens = new collection_1.RGXTokenCollection(tokens, 'concat');
|
|
35
|
+
else
|
|
36
|
+
this.tokens = new collection_1.RGXTokenCollection(tokens, 'concat');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.RGXLookaroundToken = RGXLookaroundToken;
|
|
40
|
+
// The createClassGuard function only accepts non-abstract classes, so we
|
|
41
|
+
// manually define the guard and assertion functions for RGXLookaroundToken here.
|
|
42
|
+
RGXLookaroundToken.check = (value) => value instanceof RGXLookaroundToken;
|
|
43
|
+
RGXLookaroundToken.assert = (value) => {
|
|
44
|
+
if (!(value instanceof RGXLookaroundToken)) {
|
|
45
|
+
throw new errors_1.RGXInvalidTokenError("Invalid token type", { type: "custom", values: ["instance of RGXLookaroundToken"] }, value);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RGXTokenCollectionInput } from "../collection";
|
|
2
|
+
import { RGXToken } from "../types";
|
|
3
|
+
import { RGXLookaheadToken } from "./lookahead";
|
|
4
|
+
import { RGXLookaroundToken } from "./lookaround";
|
|
5
|
+
export declare class RGXLookbehindToken extends RGXLookaroundToken {
|
|
6
|
+
static check: (value: unknown) => value is RGXLookbehindToken;
|
|
7
|
+
static assert: (value: unknown) => asserts value is RGXLookbehindToken;
|
|
8
|
+
negate(): RGXLookbehindToken;
|
|
9
|
+
reverse(): RGXLookaheadToken;
|
|
10
|
+
toRgx(): RGXToken;
|
|
11
|
+
}
|
|
12
|
+
export declare const rgxLookbehind: (tokens?: RGXTokenCollectionInput, positive?: boolean | undefined) => RGXLookbehindToken;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rgxLookbehind = exports.RGXLookbehindToken = void 0;
|
|
4
|
+
const internal_1 = require("../internal");
|
|
5
|
+
const lookahead_1 = require("./lookahead");
|
|
6
|
+
const lookaround_1 = require("./lookaround");
|
|
7
|
+
class RGXLookbehindToken extends lookaround_1.RGXLookaroundToken {
|
|
8
|
+
negate() {
|
|
9
|
+
return new RGXLookbehindToken(this.tokens, !this.positive);
|
|
10
|
+
}
|
|
11
|
+
reverse() {
|
|
12
|
+
return new lookahead_1.RGXLookaheadToken(this.tokens, this.positive);
|
|
13
|
+
}
|
|
14
|
+
toRgx() {
|
|
15
|
+
let result = this.tokens.toRgx().source;
|
|
16
|
+
if (this.positive)
|
|
17
|
+
result = `(?<=${result})`;
|
|
18
|
+
else
|
|
19
|
+
result = `(?<!${result})`;
|
|
20
|
+
return new RegExp(result);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.RGXLookbehindToken = RGXLookbehindToken;
|
|
24
|
+
RGXLookbehindToken.check = (0, internal_1.createClassGuardFunction)(RGXLookbehindToken);
|
|
25
|
+
RGXLookbehindToken.assert = (0, internal_1.createAssertClassGuardFunction)(RGXLookbehindToken);
|
|
26
|
+
exports.rgxLookbehind = (0, internal_1.createConstructFunction)(RGXLookbehindToken);
|
package/dist/class/repeat.js
CHANGED
|
@@ -30,6 +30,9 @@ class RGXRepeatToken extends base_1.RGXClassToken {
|
|
|
30
30
|
return this._token;
|
|
31
31
|
}
|
|
32
32
|
set token(value) {
|
|
33
|
+
if ((0, typeGuards_1.isRGXToken)(value, "class") && !value.isRepeatable) {
|
|
34
|
+
throw new errors_1.RGXNotSupportedError(`Repeating ${value.constructor.name} tokens`, "The token was manually marked as non-repeatable.");
|
|
35
|
+
}
|
|
33
36
|
// Make sure we are always working with a grouped token.
|
|
34
37
|
if ((0, typeGuards_1.isRGXGroupedToken)(value))
|
|
35
38
|
this._token = value;
|
package/dist/errors/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT';
|
|
1
|
+
export type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'NOT_SUPPORTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT';
|
|
2
2
|
export declare class RGXError extends Error {
|
|
3
3
|
_message: string;
|
|
4
4
|
code: RGXErrorCode;
|
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.js
CHANGED
|
@@ -24,3 +24,4 @@ __exportStar(require("./invalidIdentifier"), exports);
|
|
|
24
24
|
__exportStar(require("./outOfBounds"), exports);
|
|
25
25
|
__exportStar(require("./invalidFlagTransformerKey"), exports);
|
|
26
26
|
__exportStar(require("./flagTransformerConflict"), exports);
|
|
27
|
+
__exportStar(require("./notSupported"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGXNotSupportedError = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
class RGXNotSupportedError extends base_1.RGXError {
|
|
6
|
+
constructor(functionality, message = null) {
|
|
7
|
+
super(message || "", "NOT_SUPPORTED");
|
|
8
|
+
this.functionality = functionality;
|
|
9
|
+
this.name = "RGXNotSupportedError";
|
|
10
|
+
}
|
|
11
|
+
calcMessage(message) {
|
|
12
|
+
const result = `${this.functionality} is not supported.`;
|
|
13
|
+
if (message)
|
|
14
|
+
return result + ` Additional info: ${message}`;
|
|
15
|
+
else
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.RGXNotSupportedError = RGXNotSupportedError;
|