@ptolemy2002/rgx 4.10.0 → 4.11.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 +19 -1
- package/dist/class/base.d.ts +2 -0
- package/dist/class/group.d.ts +2 -0
- package/dist/class/group.js +6 -0
- package/dist/class/init.js +4 -0
- package/dist/class/lookahead.d.ts +2 -0
- package/dist/class/lookahead.js +6 -0
- package/dist/class/lookbehind.d.ts +3 -2
- package/dist/class/lookbehind.js +6 -0
- package/dist/class/repeat.d.ts +3 -1
- package/dist/class/repeat.js +7 -0
- package/dist/class/union.d.ts +2 -0
- package/dist/class/union.js +6 -0
- package/dist/class/wrapper.d.ts +2 -0
- package/dist/class/wrapper.js +7 -0
- package/dist/clone.d.ts +3 -0
- package/dist/clone.js +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# RGX
|
|
2
2
|
A library for easy construction and validation of regular expressions in TypeScript. You can use `rgx` to concatenate various types of tokens into a valid regular expression string, with type safety and validation.
|
|
3
3
|
|
|
4
|
+
**Note**: This library is tested with nearly 100% coverage, but any override of `RGXClassToken.clone()` does not have the depth parameter fully tested, as that is ultimately part of `@ptolemy2002/immutability-utils`, which is tested, and setting up tests for that functionality is exceedingly complex.
|
|
5
|
+
|
|
4
6
|
## Type Reference
|
|
5
7
|
```typescript
|
|
6
8
|
import { Branded } from "@ptolemy2002/ts-brand-utils";
|
|
9
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
10
|
+
// type CloneDepth = number | "max";
|
|
7
11
|
|
|
8
12
|
type RGXNoOpToken = null | undefined;
|
|
9
13
|
type RGXLiteralToken = RegExp;
|
|
@@ -253,7 +257,7 @@ constructor(tokens: RGXTokenCollectionInput = [], mode: RGXTokenCollectionMode =
|
|
|
253
257
|
- `toRgx() => RegExp`: A method that resolves the collection to a `RegExp` object based on the collection mode. In 'union' mode, the tokens are resolved as alternatives (using the `|` operator), while in 'concat' mode, the tokens are resolved as concatenated together. No flags are applied to the resulting `RegExp`. Since this method returns a `RegExp` (which is `RGXLiteralToken`), `RGXTokenCollection` instances satisfy the `RGXConvertibleToken` interface and can be used directly as tokens in `rgx`, `rgxa`, and other token-accepting functions.
|
|
254
258
|
- `getTokens() => RGXToken[]`: A method that returns a copy of the array of RGX tokens managed by the collection. This is used to prevent external mutation of the internal `tokens` array.
|
|
255
259
|
- `toArray() => RGXToken[]`: An alias for `getTokens()`, provided for convenience.
|
|
256
|
-
- `clone() => RGXTokenCollection`: A method that creates and returns a deep clone of the RGXTokenCollection instance. This is useful for creating a new collection with the same tokens and mode without affecting the original collection.
|
|
260
|
+
- `clone(depth: CloneDepth = "max") => RGXTokenCollection`: A method that creates and returns a deep clone of the RGXTokenCollection instance. This is useful for creating a new collection with the same tokens and mode without affecting the original collection. The `depth` parameter controls how deeply nested collections are cloned: `0` for no clone, `1` for a shallow clone of the top-level collection, any other number for that many levels down, and `"max"` (the default) for a full deep clone.
|
|
257
261
|
- `asConcat() => RGXTokenCollection`: If this collection is in 'union' mode, this method returns a new RGXTokenCollection instance with the same tokens but in 'concat' mode. If the collection is already in 'concat' mode, it simply returns itself.
|
|
258
262
|
- `asUnion() => RGXTokenCollection`: If this collection is in 'concat' mode, this method returns a new RGXTokenCollection instance with the same tokens but in 'union' mode. If the collection is already in 'union' mode, it simply returns itself.
|
|
259
263
|
|
|
@@ -272,6 +276,7 @@ An abstract base class for creating custom RGX token classes. Subclasses must im
|
|
|
272
276
|
|
|
273
277
|
#### Abstract Methods
|
|
274
278
|
- `toRgx() => RGXToken`: Must be implemented by subclasses to return the token's regex representation as any valid RGX token (native, literal, convertible, or array of tokens).
|
|
279
|
+
- `clone(depth: CloneDepth = "max") => RGXClassToken`: Must be implemented by subclasses to return a deep clone of the token instance. The `depth` parameter controls how deeply nested tokens are cloned: `0` for no clone, `1` for a shallow clone of the top-level token, any other number for that many levels down, and `"max"` (the default) for a full deep clone.
|
|
275
280
|
|
|
276
281
|
#### Properties
|
|
277
282
|
- `isGroup` (`boolean`): Returns `false` by default. Subclasses can override this to indicate whether the token represents a group.
|
|
@@ -1208,6 +1213,19 @@ Tests whether the given regular expression matches at a specific position in the
|
|
|
1208
1213
|
#### Returns
|
|
1209
1214
|
- `boolean`: `true` if the regex matches at the specified position, otherwise `false`.
|
|
1210
1215
|
|
|
1216
|
+
### cloneRGXToken
|
|
1217
|
+
```typescript
|
|
1218
|
+
function cloneRGXTokeN<T extends RGXToken>(token: T, depth: CloneDepth="max"): T
|
|
1219
|
+
```
|
|
1220
|
+
Creates a clone of the given RGX token to the given depth, provided that the token is not a no-op or native token.
|
|
1221
|
+
|
|
1222
|
+
#### Parameters
|
|
1223
|
+
- `token` (`T`): The RGX token to clone. Must not be a no-op or native token, or an error will be thrown.
|
|
1224
|
+
- `depth` (`CloneDepth`, optional): The depth to which to clone the token. Can be a number (with 0 resulting in no clone at all and 1 resulting in a shallow clone) or the string `"max"` for a full deep clone. Defaults to `"max"`.
|
|
1225
|
+
|
|
1226
|
+
#### Returns
|
|
1227
|
+
- `T`: The cloned token.
|
|
1228
|
+
|
|
1211
1229
|
## Peer Dependencies
|
|
1212
1230
|
- `@ptolemy2002/immutability-utils` ^2.0.0
|
|
1213
1231
|
- `@ptolemy2002/js-utils` ^3.2.2
|
package/dist/class/base.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RGXToken, ValidRegexString } from "../types";
|
|
2
2
|
import { RGXTokenCollectionInput } from "../collection";
|
|
3
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
3
4
|
import type { RGXClassUnionToken } from "./union";
|
|
4
5
|
import type { RGXGroupToken, RGXGroupTokenArgs } from "./group";
|
|
5
6
|
import type { RGXRepeatToken } from "./repeat";
|
|
@@ -7,6 +8,7 @@ import type { RGXLookaheadToken } from "./lookahead";
|
|
|
7
8
|
import type { RGXLookbehindToken } from "./lookbehind";
|
|
8
9
|
export declare abstract class RGXClassToken {
|
|
9
10
|
abstract toRgx(): RGXToken;
|
|
11
|
+
abstract clone(depth?: CloneDepth): ThisType<this>;
|
|
10
12
|
static check: (value: unknown) => value is RGXClassToken;
|
|
11
13
|
static assert: (value: unknown) => asserts value is RGXClassToken;
|
|
12
14
|
get isGroup(): boolean;
|
package/dist/class/group.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RGXTokenCollection, RGXTokenCollectionInput } from "../collection";
|
|
2
2
|
import { RGXClassToken } from "./base";
|
|
3
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
3
4
|
export type RGXGroupTokenArgs = {
|
|
4
5
|
name?: string | null;
|
|
5
6
|
capturing?: boolean;
|
|
@@ -18,5 +19,6 @@ export declare class RGXGroupToken extends RGXClassToken {
|
|
|
18
19
|
get rgxGroupWrap(): false;
|
|
19
20
|
constructor({ name, capturing }?: RGXGroupTokenArgs, tokens?: RGXTokenCollectionInput);
|
|
20
21
|
toRgx(): RegExp;
|
|
22
|
+
clone(depth?: CloneDepth): RGXGroupToken;
|
|
21
23
|
}
|
|
22
24
|
export declare const rgxGroup: (args_0?: RGXGroupTokenArgs | undefined, tokens?: RGXTokenCollectionInput) => RGXGroupToken;
|
package/dist/class/group.js
CHANGED
|
@@ -5,6 +5,7 @@ const collection_1 = require("../collection");
|
|
|
5
5
|
const base_1 = require("./base");
|
|
6
6
|
const internal_1 = require("../internal");
|
|
7
7
|
const typeGuards_1 = require("../typeGuards");
|
|
8
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
8
9
|
class RGXGroupToken extends base_1.RGXClassToken {
|
|
9
10
|
get name() {
|
|
10
11
|
return this._name;
|
|
@@ -52,6 +53,11 @@ class RGXGroupToken extends base_1.RGXClassToken {
|
|
|
52
53
|
result = `(${result})`;
|
|
53
54
|
return new RegExp(result);
|
|
54
55
|
}
|
|
56
|
+
clone(depth = "max") {
|
|
57
|
+
if (depth === 0)
|
|
58
|
+
return this;
|
|
59
|
+
return new RGXGroupToken({ name: this.name, capturing: this._capturing }, this.tokens.clone((0, immutability_utils_1.depthDecrement)(depth, 1)));
|
|
60
|
+
}
|
|
55
61
|
}
|
|
56
62
|
exports.RGXGroupToken = RGXGroupToken;
|
|
57
63
|
RGXGroupToken.check = (0, internal_1.createClassGuardFunction)(RGXGroupToken);
|
package/dist/class/init.js
CHANGED
|
@@ -36,11 +36,15 @@ function rgxClassInit() {
|
|
|
36
36
|
base_1.RGXClassToken.prototype.asLookahead = function (positive = true) {
|
|
37
37
|
if (lookahead_1.RGXLookaheadToken.check(this))
|
|
38
38
|
return this;
|
|
39
|
+
if (lookbehind_1.RGXLookbehindToken.check(this))
|
|
40
|
+
return this.negate();
|
|
39
41
|
return new lookahead_1.RGXLookaheadToken([this], positive);
|
|
40
42
|
};
|
|
41
43
|
base_1.RGXClassToken.prototype.asLookbehind = function (positive = true) {
|
|
42
44
|
if (lookbehind_1.RGXLookbehindToken.check(this))
|
|
43
45
|
return this;
|
|
46
|
+
if (lookahead_1.RGXLookaheadToken.check(this))
|
|
47
|
+
return this.negate();
|
|
44
48
|
return new lookbehind_1.RGXLookbehindToken([this], positive);
|
|
45
49
|
};
|
|
46
50
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { RGXToken } from "../types";
|
|
2
2
|
import { RGXLookaroundToken } from "./lookaround";
|
|
3
3
|
import { RGXLookbehindToken } from "./lookbehind";
|
|
4
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
4
5
|
export declare class RGXLookaheadToken extends RGXLookaroundToken {
|
|
5
6
|
static check: (value: unknown) => value is RGXLookaheadToken;
|
|
6
7
|
static assert: (value: unknown) => asserts value is RGXLookaheadToken;
|
|
7
8
|
negate(): RGXLookaheadToken;
|
|
8
9
|
reverse(): RGXLookbehindToken;
|
|
9
10
|
toRgx(): RGXToken;
|
|
11
|
+
clone(depth?: CloneDepth): RGXLookaheadToken;
|
|
10
12
|
}
|
|
11
13
|
export declare const rgxLookahead: (tokens?: import("..").RGXTokenCollectionInput, positive?: boolean | undefined) => RGXLookaheadToken;
|
package/dist/class/lookahead.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.rgxLookahead = exports.RGXLookaheadToken = void 0;
|
|
|
4
4
|
const internal_1 = require("../internal");
|
|
5
5
|
const lookaround_1 = require("./lookaround");
|
|
6
6
|
const lookbehind_1 = require("./lookbehind");
|
|
7
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
7
8
|
class RGXLookaheadToken extends lookaround_1.RGXLookaroundToken {
|
|
8
9
|
negate() {
|
|
9
10
|
return new RGXLookaheadToken(this.tokens, !this.positive);
|
|
@@ -19,6 +20,11 @@ class RGXLookaheadToken extends lookaround_1.RGXLookaroundToken {
|
|
|
19
20
|
result = `(?!${result})`;
|
|
20
21
|
return new RegExp(result);
|
|
21
22
|
}
|
|
23
|
+
clone(depth = "max") {
|
|
24
|
+
if (depth === 0)
|
|
25
|
+
return this;
|
|
26
|
+
return new RGXLookaheadToken(this.tokens.clone((0, immutability_utils_1.depthDecrement)(depth, 1)), this.positive);
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
exports.RGXLookaheadToken = RGXLookaheadToken;
|
|
24
30
|
RGXLookaheadToken.check = (0, internal_1.createClassGuardFunction)(RGXLookaheadToken);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { RGXTokenCollectionInput } from "../collection";
|
|
2
1
|
import { RGXToken } from "../types";
|
|
3
2
|
import { RGXLookaheadToken } from "./lookahead";
|
|
4
3
|
import { RGXLookaroundToken } from "./lookaround";
|
|
4
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
5
5
|
export declare class RGXLookbehindToken extends RGXLookaroundToken {
|
|
6
6
|
static check: (value: unknown) => value is RGXLookbehindToken;
|
|
7
7
|
static assert: (value: unknown) => asserts value is RGXLookbehindToken;
|
|
8
8
|
negate(): RGXLookbehindToken;
|
|
9
9
|
reverse(): RGXLookaheadToken;
|
|
10
10
|
toRgx(): RGXToken;
|
|
11
|
+
clone(depth?: CloneDepth): RGXLookbehindToken;
|
|
11
12
|
}
|
|
12
|
-
export declare const rgxLookbehind: (tokens?: RGXTokenCollectionInput, positive?: boolean | undefined) => RGXLookbehindToken;
|
|
13
|
+
export declare const rgxLookbehind: (tokens?: import("..").RGXTokenCollectionInput, positive?: boolean | undefined) => RGXLookbehindToken;
|
package/dist/class/lookbehind.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.rgxLookbehind = exports.RGXLookbehindToken = void 0;
|
|
|
4
4
|
const internal_1 = require("../internal");
|
|
5
5
|
const lookahead_1 = require("./lookahead");
|
|
6
6
|
const lookaround_1 = require("./lookaround");
|
|
7
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
7
8
|
class RGXLookbehindToken extends lookaround_1.RGXLookaroundToken {
|
|
8
9
|
negate() {
|
|
9
10
|
return new RGXLookbehindToken(this.tokens, !this.positive);
|
|
@@ -19,6 +20,11 @@ class RGXLookbehindToken extends lookaround_1.RGXLookaroundToken {
|
|
|
19
20
|
result = `(?<!${result})`;
|
|
20
21
|
return new RegExp(result);
|
|
21
22
|
}
|
|
23
|
+
clone(depth = "max") {
|
|
24
|
+
if (depth === 0)
|
|
25
|
+
return this;
|
|
26
|
+
return new RGXLookbehindToken(this.tokens.clone((0, immutability_utils_1.depthDecrement)(depth, 1)), this.positive);
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
exports.RGXLookbehindToken = RGXLookbehindToken;
|
|
24
30
|
RGXLookbehindToken.check = (0, internal_1.createClassGuardFunction)(RGXLookbehindToken);
|
package/dist/class/repeat.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RGXGroupedToken, RGXToken } from "../types";
|
|
2
2
|
import { RGXClassToken } from "./base";
|
|
3
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
3
4
|
export declare class RGXRepeatToken extends RGXClassToken {
|
|
4
5
|
_token: RGXGroupedToken;
|
|
5
6
|
_min: number;
|
|
@@ -10,11 +11,12 @@ export declare class RGXRepeatToken extends RGXClassToken {
|
|
|
10
11
|
set min(value: number);
|
|
11
12
|
get max(): number | null;
|
|
12
13
|
set max(value: number | null);
|
|
13
|
-
get token():
|
|
14
|
+
get token(): RGXGroupedToken;
|
|
14
15
|
set token(value: RGXToken);
|
|
15
16
|
get rgxGroupWrap(): false;
|
|
16
17
|
constructor(token: RGXToken, min?: number, max?: number | null);
|
|
17
18
|
get repeaterSuffix(): string;
|
|
18
19
|
toRgx(): RGXToken;
|
|
20
|
+
clone(depth?: CloneDepth): RGXRepeatToken;
|
|
19
21
|
}
|
|
20
22
|
export declare const rgxRepeat: (token: RGXToken, min?: number | undefined, max?: number | null | undefined) => RGXRepeatToken;
|
package/dist/class/repeat.js
CHANGED
|
@@ -7,6 +7,8 @@ const typeGuards_1 = require("../typeGuards");
|
|
|
7
7
|
const errors_1 = require("../errors");
|
|
8
8
|
const resolve_1 = require("../resolve");
|
|
9
9
|
const internal_1 = require("../internal");
|
|
10
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
11
|
+
const clone_1 = require("../clone");
|
|
10
12
|
class RGXRepeatToken extends base_1.RGXClassToken {
|
|
11
13
|
get min() {
|
|
12
14
|
return this._min;
|
|
@@ -76,6 +78,11 @@ class RGXRepeatToken extends base_1.RGXClassToken {
|
|
|
76
78
|
const resolvedSource = (0, resolve_1.resolveRGXToken)(this.token);
|
|
77
79
|
return new RegExp(`${resolvedSource}${this.repeaterSuffix}`);
|
|
78
80
|
}
|
|
81
|
+
clone(depth = "max") {
|
|
82
|
+
if (depth === 0)
|
|
83
|
+
return this;
|
|
84
|
+
return new RGXRepeatToken((0, clone_1.cloneRGXToken)(this.token, (0, immutability_utils_1.depthDecrement)(depth, 1)), this.min, this.max);
|
|
85
|
+
}
|
|
79
86
|
}
|
|
80
87
|
exports.RGXRepeatToken = RGXRepeatToken;
|
|
81
88
|
RGXRepeatToken.check = (0, internal_1.createClassGuardFunction)(RGXRepeatToken);
|
package/dist/class/union.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RGXToken } from "../types";
|
|
2
2
|
import { RGXTokenCollection, RGXTokenCollectionInput } from "../collection";
|
|
3
3
|
import { RGXClassToken } from "./base";
|
|
4
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
4
5
|
export type RGXUnionInsertionPosition = 'prefix' | 'suffix';
|
|
5
6
|
export declare class RGXClassUnionToken extends RGXClassToken {
|
|
6
7
|
tokens: RGXTokenCollection;
|
|
@@ -11,6 +12,7 @@ export declare class RGXClassUnionToken extends RGXClassToken {
|
|
|
11
12
|
add(token: RGXToken, pos?: RGXUnionInsertionPosition): this;
|
|
12
13
|
concat(pos?: RGXUnionInsertionPosition, ...others: RGXTokenCollectionInput[]): this;
|
|
13
14
|
toRgx(): RegExp;
|
|
15
|
+
clone(depth?: CloneDepth): RGXClassUnionToken;
|
|
14
16
|
}
|
|
15
17
|
export declare function expandRgxUnionTokens(...tokens: RGXTokenCollectionInput[]): RGXTokenCollection;
|
|
16
18
|
export declare function removeRgxUnionDuplicates(...tokens: RGXTokenCollectionInput[]): RGXTokenCollection;
|
package/dist/class/union.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.removeRgxUnionDuplicates = removeRgxUnionDuplicates;
|
|
|
6
6
|
const internal_1 = require("../internal");
|
|
7
7
|
const collection_1 = require("../collection");
|
|
8
8
|
const base_1 = require("./base");
|
|
9
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
9
10
|
class RGXClassUnionToken extends base_1.RGXClassToken {
|
|
10
11
|
constructor(tokens = []) {
|
|
11
12
|
super();
|
|
@@ -44,6 +45,11 @@ class RGXClassUnionToken extends base_1.RGXClassToken {
|
|
|
44
45
|
toRgx() {
|
|
45
46
|
return this.tokens.toRgx();
|
|
46
47
|
}
|
|
48
|
+
clone(depth = "max") {
|
|
49
|
+
if (depth === 0)
|
|
50
|
+
return this;
|
|
51
|
+
return new RGXClassUnionToken(this.tokens.clone((0, immutability_utils_1.depthDecrement)(depth, 1)));
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
exports.RGXClassUnionToken = RGXClassUnionToken;
|
|
49
55
|
RGXClassUnionToken.check = (0, internal_1.createClassGuardFunction)(RGXClassUnionToken);
|
package/dist/class/wrapper.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RGXToken } from "../types";
|
|
2
2
|
import { RGXClassToken } from "./base";
|
|
3
|
+
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
3
4
|
export declare class RGXClassWrapperToken extends RGXClassToken {
|
|
4
5
|
token: RGXToken;
|
|
5
6
|
static check: (value: unknown) => value is RGXClassWrapperToken;
|
|
@@ -9,5 +10,6 @@ export declare class RGXClassWrapperToken extends RGXClassToken {
|
|
|
9
10
|
get isRepeatable(): boolean;
|
|
10
11
|
unwrap(): RGXToken;
|
|
11
12
|
toRgx(): RGXToken;
|
|
13
|
+
clone(depth?: CloneDepth): RGXClassWrapperToken;
|
|
12
14
|
}
|
|
13
15
|
export declare const rgxClassWrapper: (token: RGXToken) => RGXClassWrapperToken;
|
package/dist/class/wrapper.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.rgxClassWrapper = exports.RGXClassWrapperToken = void 0;
|
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
const typeGuards_1 = require("../typeGuards");
|
|
6
6
|
const internal_1 = require("../internal");
|
|
7
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
8
|
+
const clone_1 = require("../clone");
|
|
7
9
|
class RGXClassWrapperToken extends base_1.RGXClassToken {
|
|
8
10
|
constructor(token) {
|
|
9
11
|
super();
|
|
@@ -24,6 +26,11 @@ class RGXClassWrapperToken extends base_1.RGXClassToken {
|
|
|
24
26
|
toRgx() {
|
|
25
27
|
return this.unwrap();
|
|
26
28
|
}
|
|
29
|
+
clone(depth = "max") {
|
|
30
|
+
if (depth === 0)
|
|
31
|
+
return this;
|
|
32
|
+
return new RGXClassWrapperToken((0, clone_1.cloneRGXToken)(this.token, (0, immutability_utils_1.depthDecrement)(depth, 1)));
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
exports.RGXClassWrapperToken = RGXClassWrapperToken;
|
|
29
36
|
RGXClassWrapperToken.check = (0, internal_1.createClassGuardFunction)(RGXClassWrapperToken);
|
package/dist/clone.d.ts
ADDED
package/dist/clone.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloneRGXToken = cloneRGXToken;
|
|
4
|
+
const immutability_utils_1 = require("@ptolemy2002/immutability-utils");
|
|
5
|
+
const typeGuards_1 = require("./typeGuards");
|
|
6
|
+
function cloneRGXToken(token, depth = "max") {
|
|
7
|
+
if (depth === 0)
|
|
8
|
+
return token;
|
|
9
|
+
if ((0, typeGuards_1.isRGXToken)(token, "no-op") || (0, typeGuards_1.isRGXToken)(token, "native"))
|
|
10
|
+
return token;
|
|
11
|
+
return (0, immutability_utils_1.extClone)(token, (0, immutability_utils_1.depthDecrement)(depth, 1));
|
|
12
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export * from "./concat";
|
|
|
10
10
|
export * from "./utils";
|
|
11
11
|
export * from "./ExtRegExp";
|
|
12
12
|
export * from "./flag-transformer";
|
|
13
|
+
export * from "./clone";
|
|
13
14
|
export declare function rgxa(tokens: t.RGXToken[], flags?: string): ExtRegExp;
|
|
14
15
|
export default function rgx(flags?: string): (strings: TemplateStringsArray, ...tokens: t.RGXToken[]) => ExtRegExp;
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./concat"), exports);
|
|
|
31
31
|
__exportStar(require("./utils"), exports);
|
|
32
32
|
__exportStar(require("./ExtRegExp"), exports);
|
|
33
33
|
__exportStar(require("./flag-transformer"), exports);
|
|
34
|
+
__exportStar(require("./clone"), exports);
|
|
34
35
|
// Call this for certain class methods to work correctly
|
|
35
36
|
(0, class_1.rgxClassInit)();
|
|
36
37
|
// Call this for our custom flags to work correctly
|