@ptolemy2002/rgx 2.3.1 → 2.3.2
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 +1 -1
- package/dist/collection.d.ts +19 -17
- package/dist/collection.js +20 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ constructor(tokens: RGXToken[] = [], mode: RGXTokenCollectionMode = 'concat')
|
|
|
108
108
|
#### Properties
|
|
109
109
|
- `tokens` (`RGXToken[]`): The array of RGX tokens managed by the collection. In almost all cases, use `getTokens()` instead of accessing this property directly, as it will be copied to prevent external mutation.
|
|
110
110
|
- `mode` (`RGXTokenCollectionMode`): The mode of the collection, either 'union' or 'concat'. This determines how the tokens in the collection will be resolved when `toRgx()` is called.
|
|
111
|
-
- `toRgx()` (`() =>
|
|
111
|
+
- `toRgx()` (`() => ValidRegexString`): A method that resolves the collection to a single RGX token based on the collection mode. In both modes, a string is ultimately returned, but in 'union' mode, the tokens are resolved as alternatives (using the `|` operator), while in 'concat' mode, the tokens are resolved as concatenated together.
|
|
112
112
|
- `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.
|
|
113
113
|
- `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.
|
|
114
114
|
- `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.
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RGXToken, ValidRegexString } from "./types";
|
|
2
2
|
import { CloneDepth } from "@ptolemy2002/immutability-utils";
|
|
3
|
+
import { Collection } from "@ptolemy2002/ts-utils";
|
|
3
4
|
export type RGXTokenCollectionMode = 'union' | 'concat';
|
|
4
|
-
export declare class RGXTokenCollection {
|
|
5
|
+
export declare class RGXTokenCollection implements Collection<RGXToken> {
|
|
5
6
|
mode: RGXTokenCollectionMode;
|
|
6
7
|
tokens: RGXToken[];
|
|
7
8
|
constructor(tokens?: RGXToken[], mode?: RGXTokenCollectionMode);
|
|
8
|
-
toRgx():
|
|
9
|
+
toRgx(): ValidRegexString;
|
|
9
10
|
getTokens(): RGXToken[];
|
|
10
11
|
clone(depth?: CloneDepth): RGXTokenCollection;
|
|
11
12
|
asConcat(): RGXTokenCollection;
|
|
12
13
|
asUnion(): RGXTokenCollection;
|
|
14
|
+
toArray(): RGXToken[];
|
|
13
15
|
get length(): number;
|
|
14
16
|
at(index: number): RGXToken | undefined;
|
|
15
|
-
find(predicate: (token: RGXToken, index: number, array:
|
|
16
|
-
findIndex(predicate: (token: RGXToken, index: number, array:
|
|
17
|
+
find(predicate: (token: RGXToken, index: number, array: RGXTokenCollection) => boolean): RGXToken | undefined;
|
|
18
|
+
findIndex(predicate: (token: RGXToken, index: number, array: RGXTokenCollection) => boolean): number;
|
|
17
19
|
indexOf(token: RGXToken, fromIndex?: number): number;
|
|
18
20
|
includes(token: RGXToken, fromIndex?: number): boolean;
|
|
19
|
-
some(predicate: (token: RGXToken, index: number, array:
|
|
20
|
-
every(predicate: (token: RGXToken, index: number, array:
|
|
21
|
-
forEach(callback: (token: RGXToken, index: number, array:
|
|
22
|
-
map(callback: (token: RGXToken, index: number, array:
|
|
23
|
-
filter(predicate: (token: RGXToken, index: number, array:
|
|
24
|
-
reduce<T>(callback: (accumulator: T, token: RGXToken, index: number, array:
|
|
25
|
-
reduce(callback: (accumulator: RGXToken, token: RGXToken, index: number, array:
|
|
21
|
+
some(predicate: (token: RGXToken, index: number, array: RGXTokenCollection) => boolean): boolean;
|
|
22
|
+
every(predicate: (token: RGXToken, index: number, array: RGXTokenCollection) => boolean): boolean;
|
|
23
|
+
forEach(callback: (token: RGXToken, index: number, array: RGXTokenCollection) => void): void;
|
|
24
|
+
map<T>(callback: (token: RGXToken, index: number, array: RGXTokenCollection) => T): T[];
|
|
25
|
+
filter(predicate: (token: RGXToken, index: number, array: RGXTokenCollection) => boolean): RGXTokenCollection;
|
|
26
|
+
reduce<T>(callback: (accumulator: T, token: RGXToken, index: number, array: RGXTokenCollection) => T, initialValue: T): T;
|
|
27
|
+
reduce(callback: (accumulator: RGXToken, token: RGXToken, index: number, array: RGXTokenCollection) => RGXToken): RGXToken;
|
|
26
28
|
flat(depth?: number): RGXTokenCollection;
|
|
27
|
-
flatMap(callback: (token: RGXToken, index: number, array:
|
|
29
|
+
flatMap<T>(callback: (token: RGXToken, index: number, array: RGXTokenCollection) => T | T[], depth?: number): T[];
|
|
28
30
|
slice(start?: number, end?: number): RGXTokenCollection;
|
|
29
|
-
concat(...others: (RGXToken | RGXTokenCollection)[]): RGXTokenCollection;
|
|
31
|
+
concat(...others: (RGXToken | RGXToken[] | RGXTokenCollection)[]): RGXTokenCollection;
|
|
30
32
|
push(...tokens: RGXToken[]): void;
|
|
31
33
|
pop(): RGXToken | undefined;
|
|
32
34
|
shift(): RGXToken | undefined;
|
|
33
35
|
unshift(...tokens: RGXToken[]): number;
|
|
34
36
|
splice(start: number, deleteCount?: number, ...items: RGXToken[]): RGXTokenCollection;
|
|
35
|
-
reverse():
|
|
36
|
-
sort(compareFn?: (a: RGXToken, b: RGXToken) => number):
|
|
37
|
-
fill(value: RGXToken, start?: number, end?: number):
|
|
37
|
+
reverse(): RGXTokenCollection;
|
|
38
|
+
sort(compareFn?: (a: RGXToken, b: RGXToken) => number): RGXTokenCollection;
|
|
39
|
+
fill(value: RGXToken, start?: number, end?: number): RGXTokenCollection;
|
|
38
40
|
[Symbol.iterator](): Iterator<RGXToken>;
|
|
39
41
|
entries(): IterableIterator<[number, RGXToken]>;
|
|
40
42
|
keys(): IterableIterator<number>;
|
package/dist/collection.js
CHANGED
|
@@ -11,7 +11,7 @@ class RGXTokenCollection {
|
|
|
11
11
|
}
|
|
12
12
|
toRgx() {
|
|
13
13
|
if (this.mode === 'union') {
|
|
14
|
-
return (0, index_1.resolveRGXToken)(this.tokens
|
|
14
|
+
return (0, index_1.resolveRGXToken)(this.tokens);
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
17
|
return (0, index_1.rgxConcat)(this.tokens);
|
|
@@ -23,7 +23,7 @@ class RGXTokenCollection {
|
|
|
23
23
|
clone(depth = "max") {
|
|
24
24
|
if (depth === 0)
|
|
25
25
|
return this; // No cloning at depth 0, return the same instance.
|
|
26
|
-
return new RGXTokenCollection((0, immutability_utils_1.extClone)(this.tokens,
|
|
26
|
+
return new RGXTokenCollection((0, immutability_utils_1.extClone)(this.tokens, (0, immutability_utils_1.depthDecrement)(depth)), this.mode);
|
|
27
27
|
}
|
|
28
28
|
asConcat() {
|
|
29
29
|
if (this.mode === 'concat')
|
|
@@ -39,7 +39,10 @@ class RGXTokenCollection {
|
|
|
39
39
|
clone.mode = 'union';
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
// ------------------
|
|
42
|
+
// ------------------ Abstract Impplementations ------------------
|
|
43
|
+
toArray() {
|
|
44
|
+
return this.getTokens();
|
|
45
|
+
}
|
|
43
46
|
get length() {
|
|
44
47
|
return this.tokens.length;
|
|
45
48
|
}
|
|
@@ -47,10 +50,10 @@ class RGXTokenCollection {
|
|
|
47
50
|
return this.tokens[index];
|
|
48
51
|
}
|
|
49
52
|
find(predicate) {
|
|
50
|
-
return this.tokens.find(predicate);
|
|
53
|
+
return this.tokens.find((token, index) => predicate(token, index, this));
|
|
51
54
|
}
|
|
52
55
|
findIndex(predicate) {
|
|
53
|
-
return this.tokens.findIndex(predicate);
|
|
56
|
+
return this.tokens.findIndex((token, index) => predicate(token, index, this));
|
|
54
57
|
}
|
|
55
58
|
indexOf(token, fromIndex) {
|
|
56
59
|
return this.tokens.indexOf(token, fromIndex);
|
|
@@ -59,29 +62,27 @@ class RGXTokenCollection {
|
|
|
59
62
|
return this.tokens.includes(token, fromIndex);
|
|
60
63
|
}
|
|
61
64
|
some(predicate) {
|
|
62
|
-
return this.tokens.some(predicate);
|
|
65
|
+
return this.tokens.some((token, index) => predicate(token, index, this));
|
|
63
66
|
}
|
|
64
67
|
every(predicate) {
|
|
65
|
-
return this.tokens.every(predicate);
|
|
68
|
+
return this.tokens.every((token, index) => predicate(token, index, this));
|
|
66
69
|
}
|
|
67
70
|
forEach(callback) {
|
|
68
|
-
this.tokens.forEach(callback);
|
|
71
|
+
this.tokens.forEach((token, index) => callback(token, index, this));
|
|
69
72
|
}
|
|
70
73
|
map(callback) {
|
|
71
|
-
return (
|
|
72
|
-
clone.tokens = clone.tokens.map(callback);
|
|
73
|
-
});
|
|
74
|
+
return this.tokens.map((token, index) => callback(token, index, this));
|
|
74
75
|
}
|
|
75
76
|
filter(predicate) {
|
|
76
77
|
return (0, immutability_utils_1.immutableMut)(this, clone => {
|
|
77
|
-
clone.tokens = clone.tokens.filter(predicate);
|
|
78
|
+
clone.tokens = clone.tokens.filter((token, index) => predicate(token, index, this));
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
|
-
reduce(callback,
|
|
81
|
-
if (
|
|
82
|
-
return this.tokens.reduce(callback,
|
|
81
|
+
reduce(callback, initialValue) {
|
|
82
|
+
if (initialValue !== undefined) {
|
|
83
|
+
return this.tokens.reduce((accumulator, token, index) => callback(accumulator, token, index, this), initialValue);
|
|
83
84
|
}
|
|
84
|
-
return this.tokens.reduce(callback);
|
|
85
|
+
return this.tokens.reduce((accumulator, token, index) => callback(accumulator, token, index, this));
|
|
85
86
|
}
|
|
86
87
|
flat(depth = 1) {
|
|
87
88
|
return (0, immutability_utils_1.immutableMut)(this, clone => {
|
|
@@ -89,11 +90,8 @@ class RGXTokenCollection {
|
|
|
89
90
|
clone.tokens = clone.tokens.flat(depth);
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
|
-
flatMap(callback) {
|
|
93
|
-
return (
|
|
94
|
-
// Fixing TypeScript complaining about possible infinite recursion here.
|
|
95
|
-
clone.tokens = clone.tokens.flatMap(callback);
|
|
96
|
-
});
|
|
93
|
+
flatMap(callback, depth) {
|
|
94
|
+
return this.tokens.flatMap((token, index) => callback(token, index, this));
|
|
97
95
|
}
|
|
98
96
|
slice(start, end) {
|
|
99
97
|
return (0, immutability_utils_1.immutableMut)(this, clone => {
|
|
@@ -102,7 +100,7 @@ class RGXTokenCollection {
|
|
|
102
100
|
}
|
|
103
101
|
concat(...others) {
|
|
104
102
|
return (0, immutability_utils_1.immutableMut)(this, clone => {
|
|
105
|
-
const arrays = others.map(o => o instanceof RGXTokenCollection ? o.tokens : [o]);
|
|
103
|
+
const arrays = others.map(o => o instanceof RGXTokenCollection ? o.tokens : Array.isArray(o) ? o : [o]);
|
|
106
104
|
clone.tokens = clone.tokens.concat(...arrays.flat());
|
|
107
105
|
});
|
|
108
106
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptolemy2002/rgx",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@ptolemy2002/immutability-utils": "^2.0.0",
|
|
33
33
|
"@ptolemy2002/js-utils": "^3.2.2",
|
|
34
34
|
"@ptolemy2002/ts-brand-utils": "^1.0.0",
|
|
35
|
-
"@ptolemy2002/ts-utils": "^3.
|
|
35
|
+
"@ptolemy2002/ts-utils": "^3.5.1",
|
|
36
36
|
"@types/is-callable": "^1.1.2",
|
|
37
37
|
"@types/jest": "^29.5.0",
|
|
38
38
|
"@types/lodash.clonedeep": "^4.5.9",
|