@nejs/basic-extensions 2.4.0 → 2.6.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 +151 -118
- package/dist/@nejs/basic-extensions.bundle.2.5.0.js +8 -0
- package/dist/@nejs/basic-extensions.bundle.2.5.0.js.map +7 -0
- package/dist/cjs/arrayextensions.js +56 -54
- package/dist/cjs/arrayextensions.js.map +1 -1
- package/dist/cjs/functionextensions.js +81 -79
- package/dist/cjs/functionextensions.js.map +1 -1
- package/dist/cjs/mapextensions.js +23 -21
- package/dist/cjs/mapextensions.js.map +1 -1
- package/dist/cjs/objectextensions.js +49 -17
- package/dist/cjs/objectextensions.js.map +1 -1
- package/dist/cjs/setextensions.js +191 -189
- package/dist/cjs/setextensions.js.map +1 -1
- package/dist/cjs/stringextensions.js +69 -67
- package/dist/cjs/stringextensions.js.map +1 -1
- package/dist/mjs/arrayextensions.js +56 -54
- package/dist/mjs/arrayextensions.js.map +1 -1
- package/dist/mjs/functionextensions.js +81 -79
- package/dist/mjs/functionextensions.js.map +1 -1
- package/dist/mjs/mapextensions.js +23 -21
- package/dist/mjs/mapextensions.js.map +1 -1
- package/dist/mjs/objectextensions.js +49 -17
- package/dist/mjs/objectextensions.js.map +1 -1
- package/dist/mjs/setextensions.js +191 -189
- package/dist/mjs/setextensions.js.map +1 -1
- package/dist/mjs/stringextensions.js +69 -67
- package/dist/mjs/stringextensions.js.map +1 -1
- package/docs/index.html +636 -478
- package/package.json +5 -4
- package/src/arrayextensions.js +56 -55
- package/src/functionextensions.js +87 -85
- package/src/mapextensions.js +26 -24
- package/src/objectextensions.js +52 -17
- package/src/setextensions.js +216 -214
- package/src/stringextensions.js +69 -67
- package/dist/@nejs/basic-extensions.bundle.2.3.0.js +0 -8
- package/dist/@nejs/basic-extensions.bundle.2.3.0.js.map +0 -7
|
@@ -1,201 +1,203 @@
|
|
|
1
1
|
import { Patch } from '@nejs/extension';
|
|
2
2
|
export const SetPrototypeExtensions = new Patch(Set.prototype, {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
[Patch.kMutablyHidden]: {
|
|
4
|
+
/**
|
|
5
|
+
* Merges multiple iterables into the set. Each element from the iterables
|
|
6
|
+
* is added to the set, ensuring uniqueness of all elements. This method
|
|
7
|
+
* mutates the original set.
|
|
8
|
+
*
|
|
9
|
+
* @param {...Iterable} iterables - One or more iterable objects (like Set
|
|
10
|
+
* or Array) whose elements will be added to the set.
|
|
11
|
+
*/
|
|
12
|
+
concat(...iterables) {
|
|
13
|
+
for (const iterable of iterables) {
|
|
14
|
+
if (typeof iterable === 'string' ||
|
|
15
|
+
!Reflect.has(iterable, Symbol.iterator)) {
|
|
16
|
+
this.add(iterable);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
for (const element of iterable) {
|
|
20
|
+
this.add(element);
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Checks to see if any value within the `Set` loosely equals the supplied
|
|
26
|
+
* value.
|
|
27
|
+
*
|
|
28
|
+
* @param {*} value any value that might be loosely equal to an item in the
|
|
29
|
+
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
|
|
30
|
+
* triple equals (`===`) check
|
|
31
|
+
* @returns {boolean} `true` if any value within the set is loosely equal to
|
|
32
|
+
* the supplied value, `false` otherwise
|
|
33
|
+
*/
|
|
34
|
+
contains(value) {
|
|
35
|
+
for (const element of this) {
|
|
36
|
+
if (value == element) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
20
39
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Checks if every element in the set passes the test implemented by the
|
|
44
|
+
* provided function. The function is called with each element of the set.
|
|
45
|
+
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
46
|
+
*
|
|
47
|
+
* @param {Function} everyFn - The function to test each element. Receives
|
|
48
|
+
* the element, index (always NaN), and the set itself.
|
|
49
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
50
|
+
* `everyFn`.
|
|
51
|
+
* @throws {TypeError} If `everyFn` is not a function.
|
|
52
|
+
* @returns {boolean} True if every element passes the test, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
every(everyFn, thisArg) {
|
|
55
|
+
if (typeof everyFn !== 'function') {
|
|
56
|
+
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
|
|
37
57
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* provided function. The function is called with each element of the set.
|
|
44
|
-
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
45
|
-
*
|
|
46
|
-
* @param {Function} everyFn - The function to test each element. Receives
|
|
47
|
-
* the element, index (always NaN), and the set itself.
|
|
48
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
49
|
-
* `everyFn`.
|
|
50
|
-
* @throws {TypeError} If `everyFn` is not a function.
|
|
51
|
-
* @returns {boolean} True if every element passes the test, false otherwise.
|
|
52
|
-
*/
|
|
53
|
-
every(everyFn, thisArg) {
|
|
54
|
-
if (typeof everyFn !== 'function') {
|
|
55
|
-
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
|
|
56
|
-
}
|
|
57
|
-
let found = 0;
|
|
58
|
-
for (const element of this) {
|
|
59
|
-
if (everyFn.call(thisArg, element, NaN, this)) {
|
|
60
|
-
found++;
|
|
58
|
+
let found = 0;
|
|
59
|
+
for (const element of this) {
|
|
60
|
+
if (everyFn.call(thisArg, element, NaN, this)) {
|
|
61
|
+
found++;
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
81
|
-
}
|
|
82
|
-
for (const element of this) {
|
|
83
|
-
const match = findFn.call(thisArg, element, NaN, this);
|
|
84
|
-
if (match) {
|
|
85
|
-
return element;
|
|
64
|
+
return (found === this.size);
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Finds the first element in the set satisfying the provided testing
|
|
68
|
+
* function. If no elements satisfy the testing function, undefined is
|
|
69
|
+
* returned. The function is called with each element of the set.
|
|
70
|
+
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
71
|
+
*
|
|
72
|
+
* @param {Function} findFn - The function to execute on each element. It
|
|
73
|
+
* receives the element, index (always NaN), and the set itself.
|
|
74
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
75
|
+
* `findFn`.
|
|
76
|
+
* @throws {TypeError} If `findFn` is not a function.
|
|
77
|
+
* @returns {*} The first element that satisfies `findFn`, or undefined.
|
|
78
|
+
*/
|
|
79
|
+
find(findFn, thisArg) {
|
|
80
|
+
if (typeof findFn !== 'function') {
|
|
81
|
+
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* If no elements satisfy the testing function, undefined is returned. The
|
|
93
|
-
* function is called with each element of the set in reverse order.
|
|
94
|
-
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
95
|
-
*
|
|
96
|
-
* @param {Function} findFn - The function to execute on each element. It
|
|
97
|
-
* receives the element, index (always NaN), and the set itself.
|
|
98
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
99
|
-
* `findFn`.
|
|
100
|
-
* @throws {TypeError} If `findFn` is not a function.
|
|
101
|
-
* @returns {*} The last element that satisfies `findFn`, or undefined.
|
|
102
|
-
*/
|
|
103
|
-
findLast(findFn, thisArg) {
|
|
104
|
-
if (typeof findFn !== 'function') {
|
|
105
|
-
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
106
|
-
}
|
|
107
|
-
const found = [];
|
|
108
|
-
for (const element of this) {
|
|
109
|
-
const match = findFn.call(thisArg, element, NaN, this);
|
|
110
|
-
if (match) {
|
|
111
|
-
found.push(element);
|
|
83
|
+
for (const element of this) {
|
|
84
|
+
const match = findFn.call(thisArg, element, NaN, this);
|
|
85
|
+
if (match) {
|
|
86
|
+
return element;
|
|
87
|
+
}
|
|
112
88
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
89
|
+
return undefined;
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Finds the last element in the set satisfying the provided testing function.
|
|
93
|
+
* If no elements satisfy the testing function, undefined is returned. The
|
|
94
|
+
* function is called with each element of the set in reverse order.
|
|
95
|
+
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
96
|
+
*
|
|
97
|
+
* @param {Function} findFn - The function to execute on each element. It
|
|
98
|
+
* receives the element, index (always NaN), and the set itself.
|
|
99
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
100
|
+
* `findFn`.
|
|
101
|
+
* @throws {TypeError} If `findFn` is not a function.
|
|
102
|
+
* @returns {*} The last element that satisfies `findFn`, or undefined.
|
|
103
|
+
*/
|
|
104
|
+
findLast(findFn, thisArg) {
|
|
105
|
+
if (typeof findFn !== 'function') {
|
|
106
|
+
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
107
|
+
}
|
|
108
|
+
const found = [];
|
|
109
|
+
for (const element of this) {
|
|
110
|
+
const match = findFn.call(thisArg, element, NaN, this);
|
|
111
|
+
if (match) {
|
|
112
|
+
found.push(element);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (found.length) {
|
|
116
|
+
return found[found.length - 1];
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* A getter property that returns the number of elements in the set.
|
|
122
|
+
* This is an alias for the `size` property of the set.
|
|
123
|
+
*
|
|
124
|
+
* @returns {number} The number of elements in the set.
|
|
125
|
+
*/
|
|
126
|
+
get length() {
|
|
127
|
+
return this.size;
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new array populated with the results of calling the provided
|
|
131
|
+
* function on every element in the set. The function is called with each
|
|
132
|
+
* element of the set. Note: Since sets do not have indices, the index
|
|
133
|
+
* parameter is always NaN.
|
|
134
|
+
*
|
|
135
|
+
* @param {Function} mapFn - The function to execute on each element. It
|
|
136
|
+
* receives the element, index (always NaN), and the set itself.
|
|
137
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
138
|
+
* `mapFn`.
|
|
139
|
+
* @throws {TypeError} If `mapFn` is not a function.
|
|
140
|
+
* @returns {Array} A new array with each element being the result of the
|
|
141
|
+
* `mapFn`.
|
|
142
|
+
*/
|
|
143
|
+
map(mapFn, thisArg) {
|
|
144
|
+
if (typeof mapFn !== 'function') {
|
|
145
|
+
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
|
|
146
|
+
}
|
|
147
|
+
const transformed = [];
|
|
148
|
+
for (const element of this) {
|
|
149
|
+
transformed.push(mapFn.call(thisArg, element, NaN, this));
|
|
150
|
+
}
|
|
151
|
+
return transformed;
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* Applies a function against an accumulator and each element in the set to
|
|
155
|
+
* reduce it to a single value. The function is called with each element of
|
|
156
|
+
* the set. Note: Since sets do not have indices, the index parameter is
|
|
157
|
+
* always NaN.
|
|
158
|
+
*
|
|
159
|
+
* @param {Function} reduceFn - The function to execute on each element. It
|
|
160
|
+
* receives the accumulator, element, index (always NaN), and the set itself.
|
|
161
|
+
* @param {*} initialValue - The initial value to start reducing from.
|
|
162
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
163
|
+
* `reduceFn`.
|
|
164
|
+
* @throws {TypeError} If `reduceFn` is not a function.
|
|
165
|
+
* @returns {*} The reduced value.
|
|
166
|
+
*/
|
|
167
|
+
reduce(reduceFn, initialValue, thisArg) {
|
|
168
|
+
if (typeof reduceFn !== 'function') {
|
|
169
|
+
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
|
|
170
|
+
}
|
|
171
|
+
let accumulator = initialValue;
|
|
172
|
+
for (const element of this) {
|
|
173
|
+
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
|
|
174
|
+
}
|
|
175
|
+
return accumulator;
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* Tests whether at least one element in the set passes the test implemented
|
|
179
|
+
* by the provided function. The function is called with each element of the
|
|
180
|
+
* set. Note: Since sets do not have indices, the index parameter is always NaN.
|
|
181
|
+
*
|
|
182
|
+
* @param {Function} someFn - The function to test each element. It receives
|
|
183
|
+
* the element, index (always NaN), and the set itself.
|
|
184
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
185
|
+
* `someFn`.
|
|
186
|
+
* @throws {TypeError} If `someFn` is not a function.
|
|
187
|
+
* @returns {boolean} True if at least one element passes the test, false
|
|
188
|
+
* otherwise.
|
|
189
|
+
*/
|
|
190
|
+
some(someFn, thisArg) {
|
|
191
|
+
if (typeof someFn !== 'function') {
|
|
192
|
+
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
|
|
193
|
+
}
|
|
194
|
+
for (const element of this) {
|
|
195
|
+
if (someFn.call(thisArg, element, NaN, this)) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
196
198
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
+
return false;
|
|
200
|
+
},
|
|
199
201
|
},
|
|
200
202
|
});
|
|
201
203
|
//# sourceMappingURL=setextensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setextensions.js","sourceRoot":"","sources":["../../src/setextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE;IAC7D;;;;;;;
|
|
1
|
+
{"version":3,"file":"setextensions.js","sourceRoot":"","sources":["../../src/setextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE;IAC7D,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;WAOG;QACH,MAAM,CAAC,GAAG,SAAS;YACjB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,IACE,OAAO,QAAQ,KAAK,QAAQ;oBAC5B,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,EACvC,CAAC;oBACD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;oBAClB,SAAQ;gBACV,CAAC;gBAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;oBAC/B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;QAED;;;;;;;;;WASG;QACH,QAAQ,CAAC,KAAK;YACZ,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC3B,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;oBACrB,OAAO,IAAI,CAAA;gBACb,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAA;QACd,CAAC;QAED;;;;;;;;;;;WAWG;QACH,KAAK,CAAC,OAAO,EAAE,OAAO;YACpB,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;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AC;YAED,OAAO,WAAW,CAAA;QACpB,CAAC;QAED;;;;;;;;;;;;WAYG;QACH,IAAI,CAAC,MAAM,EAAE,OAAO;YAClB,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;gBACjC,MAAM,IAAI,SAAS,CACjB,uCAAuC,MAAM,CAAC,MAAM,CAAC,EAAE,CACxD,CAAA;YACH,CAAC;YAED,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;oBAC7C,OAAO,IAAI,CAAA;gBACb,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAA;QACd,CAAC;KACF;CACF,CAAC,CAAA"}
|
|
@@ -79,75 +79,77 @@ export const StringExtensions = new Patch(String, {
|
|
|
79
79
|
* making string manipulation tasks more convenient and expressive.
|
|
80
80
|
*/
|
|
81
81
|
export const StringPrototypeExtensions = new Patch(String.prototype, {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
start
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
82
|
+
[Patch.kMutablyHidden]: {
|
|
83
|
+
/**
|
|
84
|
+
* Extracts a substring from the current string, starting at a given offset
|
|
85
|
+
* and bounded by specified opening and closing tokens. This method is
|
|
86
|
+
* particularly useful for parsing nested structures or quoted strings,
|
|
87
|
+
* where the level of nesting or the presence of escape characters must
|
|
88
|
+
* be considered.
|
|
89
|
+
*
|
|
90
|
+
* @param {number} offset The position in the string from which to start the
|
|
91
|
+
* search for the substring.
|
|
92
|
+
* @param {[string, string]} tokens An array containing two strings: the
|
|
93
|
+
* opening and closing tokens that define the boundaries of the substring
|
|
94
|
+
* to be extracted.
|
|
95
|
+
* @returns {Object} An object with two properties: `extracted`, the
|
|
96
|
+
* extracted substring, and `newOffset`, the position in the original
|
|
97
|
+
* string immediately after the end of the extracted substring. If no
|
|
98
|
+
* substring is found, `extracted` is `null` and `newOffset` is the same
|
|
99
|
+
* as the input offset.
|
|
100
|
+
*/
|
|
101
|
+
extractSubstring(offset = 0, tokens = parenthesisPair) {
|
|
102
|
+
let [openToken, closeToken] = tokens;
|
|
103
|
+
let depth = 0;
|
|
104
|
+
let start = -1;
|
|
105
|
+
let end = -1;
|
|
106
|
+
let leadingToken = '';
|
|
107
|
+
let firstToken = 0;
|
|
108
|
+
for (let i = offset; i < this.length; i++) {
|
|
109
|
+
const char = this[i];
|
|
110
|
+
if (char === openToken) {
|
|
111
|
+
depth++;
|
|
112
|
+
if (start === -1)
|
|
113
|
+
start = i;
|
|
114
|
+
}
|
|
115
|
+
else if (char === closeToken) {
|
|
116
|
+
depth--;
|
|
117
|
+
if (depth === 0) {
|
|
118
|
+
end = i;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
123
|
+
let lRange = [
|
|
124
|
+
Math.max(0, start - 100),
|
|
125
|
+
start
|
|
126
|
+
];
|
|
127
|
+
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('');
|
|
128
|
+
let reversedLeadingToken;
|
|
129
|
+
try {
|
|
130
|
+
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
|
|
131
|
+
leadingToken = [...reversedLeadingToken].reverse().join('');
|
|
132
|
+
}
|
|
133
|
+
catch (ignored) { }
|
|
134
|
+
if (start !== -1 && end !== -1) {
|
|
135
|
+
const sliceRange = [start, end + 1];
|
|
136
|
+
const extracted = this.slice(sliceRange[0], sliceRange[1]);
|
|
137
|
+
return {
|
|
138
|
+
extracted,
|
|
139
|
+
range: [start, end],
|
|
140
|
+
newOffset: end + 1,
|
|
141
|
+
leadingToken,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return {
|
|
146
|
+
extracted: null,
|
|
147
|
+
range: [start, end],
|
|
148
|
+
newOffset: offset,
|
|
149
|
+
leadingToken,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
},
|
|
151
153
|
},
|
|
152
154
|
});
|
|
153
155
|
//# sourceMappingURL=stringextensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringextensions.js","sourceRoot":"","sources":["../../src/stringextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK;QACZ,IAAI,KAAK,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC,EAAE,CAAC;YACpE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;QACzB,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;;;;;;OASG;IACH,IAAI,eAAe;QACjB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpB,CAAC;IAED;;;;;;;;;;OAUG;IACH,IAAI,kBAAkB;QACpB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,iBAAiB;QACnB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpB,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE;IACnE;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"stringextensions.js","sourceRoot":"","sources":["../../src/stringextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK;QACZ,IAAI,KAAK,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC,EAAE,CAAC;YACpE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;QACzB,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;;;;;;OASG;IACH,IAAI,eAAe;QACjB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpB,CAAC;IAED;;;;;;;;;;OAUG;IACH,IAAI,kBAAkB;QACpB,O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