mutts 1.0.1 → 1.0.3
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 +36 -6
- package/dist/chunks/_tslib-BgjropY9.js +81 -0
- package/dist/chunks/_tslib-BgjropY9.js.map +1 -0
- package/dist/chunks/_tslib-Mzh1rNsX.esm.js +75 -0
- package/dist/chunks/_tslib-Mzh1rNsX.esm.js.map +1 -0
- package/dist/chunks/{decorator-8qjFb7dw.js → decorator-DLvrD0UF.js} +103 -14
- package/dist/chunks/decorator-DLvrD0UF.js.map +1 -0
- package/dist/chunks/{decorator-AbRkXM5O.esm.js → decorator-DqiszP7i.esm.js} +100 -15
- package/dist/chunks/decorator-DqiszP7i.esm.js.map +1 -0
- package/dist/chunks/index-DzUDtFc7.esm.js +4841 -0
- package/dist/chunks/index-DzUDtFc7.esm.js.map +1 -0
- package/dist/chunks/index-HNVqPzjz.js +4891 -0
- package/dist/chunks/index-HNVqPzjz.js.map +1 -0
- package/dist/decorator.d.ts +57 -0
- package/dist/decorator.esm.js +1 -1
- package/dist/decorator.js +1 -1
- package/dist/destroyable.d.ts +43 -1
- package/dist/destroyable.esm.js +19 -1
- package/dist/destroyable.esm.js.map +1 -1
- package/dist/destroyable.js +19 -1
- package/dist/destroyable.js.map +1 -1
- package/dist/devtools/devtools.html +9 -0
- package/dist/devtools/devtools.js +5 -0
- package/dist/devtools/devtools.js.map +1 -0
- package/dist/devtools/manifest.json +8 -0
- package/dist/devtools/panel.css +72 -0
- package/dist/devtools/panel.html +31 -0
- package/dist/devtools/panel.js +13048 -0
- package/dist/devtools/panel.js.map +1 -0
- package/dist/eventful.d.ts +10 -1
- package/dist/eventful.esm.js +5 -27
- package/dist/eventful.esm.js.map +1 -1
- package/dist/eventful.js +15 -37
- package/dist/eventful.js.map +1 -1
- package/dist/index.d.ts +18 -14
- package/dist/index.esm.js +4 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +44 -5
- package/dist/index.js.map +1 -1
- package/dist/indexable.d.ts +213 -1
- package/dist/indexable.esm.js +203 -3
- package/dist/indexable.esm.js.map +1 -1
- package/dist/indexable.js +204 -2
- package/dist/indexable.js.map +1 -1
- package/dist/mutts.umd.js +1 -1
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/promiseChain.d.ts +10 -0
- package/dist/promiseChain.esm.js +6 -0
- package/dist/promiseChain.esm.js.map +1 -1
- package/dist/promiseChain.js +6 -0
- package/dist/promiseChain.js.map +1 -1
- package/dist/reactive.d.ts +774 -33
- package/dist/reactive.esm.js +4 -1458
- package/dist/reactive.esm.js.map +1 -1
- package/dist/reactive.js +53 -1474
- package/dist/reactive.js.map +1 -1
- package/dist/std-decorators.d.ts +35 -0
- package/dist/std-decorators.esm.js +36 -1
- package/dist/std-decorators.esm.js.map +1 -1
- package/dist/std-decorators.js +36 -1
- package/dist/std-decorators.js.map +1 -1
- package/docs/ai/api-reference.md +133 -0
- package/docs/ai/manual.md +105 -0
- package/docs/iterableWeak.md +646 -0
- package/docs/mixin.md +229 -0
- package/docs/reactive/advanced.md +1280 -0
- package/docs/reactive/collections.md +767 -0
- package/docs/reactive/core.md +973 -0
- package/docs/reactive.md +21 -2688
- package/package.json +18 -5
- package/src/decorator.ts +266 -0
- package/src/destroyable.ts +199 -0
- package/src/eventful.ts +77 -0
- package/src/index.d.ts +9 -0
- package/src/index.ts +9 -0
- package/src/indexable.ts +484 -0
- package/src/introspection.ts +59 -0
- package/src/iterableWeak.ts +233 -0
- package/src/mixins.ts +123 -0
- package/src/promiseChain.ts +110 -0
- package/src/reactive/array.ts +414 -0
- package/src/reactive/change.ts +134 -0
- package/src/reactive/debug.ts +517 -0
- package/src/reactive/deep-touch.ts +268 -0
- package/src/reactive/deep-watch-state.ts +82 -0
- package/src/reactive/deep-watch.ts +168 -0
- package/src/reactive/effect-context.ts +94 -0
- package/src/reactive/effects.ts +1333 -0
- package/src/reactive/index.ts +75 -0
- package/src/reactive/interface.ts +223 -0
- package/src/reactive/map.ts +171 -0
- package/src/reactive/mapped.ts +130 -0
- package/src/reactive/memoize.ts +107 -0
- package/src/reactive/non-reactive-state.ts +49 -0
- package/src/reactive/non-reactive.ts +43 -0
- package/src/reactive/project.project.md +93 -0
- package/src/reactive/project.ts +335 -0
- package/src/reactive/proxy-state.ts +27 -0
- package/src/reactive/proxy.ts +285 -0
- package/src/reactive/record.ts +196 -0
- package/src/reactive/register.ts +421 -0
- package/src/reactive/set.ts +144 -0
- package/src/reactive/tracking.ts +101 -0
- package/src/reactive/types.ts +358 -0
- package/src/reactive/zone.ts +208 -0
- package/src/std-decorators.ts +217 -0
- package/src/utils.ts +117 -0
- package/dist/chunks/decorator-8qjFb7dw.js.map +0 -1
- package/dist/chunks/decorator-AbRkXM5O.esm.js.map +0 -1
package/dist/indexable.esm.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol for defining custom getter logic for numeric index access
|
|
3
|
+
*/
|
|
1
4
|
const getAt = Symbol('getAt');
|
|
5
|
+
/**
|
|
6
|
+
* Symbol for defining custom setter logic for numeric index access
|
|
7
|
+
*/
|
|
2
8
|
const setAt = Symbol('setAt');
|
|
3
9
|
function Indexable(base, accessor) {
|
|
4
10
|
if (base && typeof base !== 'function') {
|
|
@@ -62,9 +68,8 @@ function Indexable(base, accessor) {
|
|
|
62
68
|
}
|
|
63
69
|
const numProp = Number(prop);
|
|
64
70
|
if (!Number.isNaN(numProp)) {
|
|
65
|
-
if (!accessor.set)
|
|
71
|
+
if (!accessor.set)
|
|
66
72
|
throw new Error('Indexable class has read-only numeric index access');
|
|
67
|
-
}
|
|
68
73
|
accessor.set.call(receiver, numProp, value);
|
|
69
74
|
return true;
|
|
70
75
|
}
|
|
@@ -80,6 +85,201 @@ function Indexable(base, accessor) {
|
|
|
80
85
|
}));
|
|
81
86
|
return Indexable;
|
|
82
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Symbol for accessing the forwarded array in ArrayReadForward
|
|
90
|
+
*/
|
|
91
|
+
const forwardArray = Symbol('forwardArray');
|
|
92
|
+
/**
|
|
93
|
+
* A read-only array forwarder that implements all reading/iterating methods of Array
|
|
94
|
+
* but does not implement modification methods.
|
|
95
|
+
*
|
|
96
|
+
* The constructor takes a callback that returns an array, and all methods forward
|
|
97
|
+
* their behavior to the result of that callback.
|
|
98
|
+
*/
|
|
99
|
+
class ArrayReadForward {
|
|
100
|
+
get [forwardArray]() {
|
|
101
|
+
throw new Error('ArrayReadForward is not implemented');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the length of the array
|
|
105
|
+
*/
|
|
106
|
+
get length() {
|
|
107
|
+
return this[forwardArray].length;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Iterator protocol support
|
|
111
|
+
*/
|
|
112
|
+
[Symbol.iterator]() {
|
|
113
|
+
return this[forwardArray][Symbol.iterator]();
|
|
114
|
+
}
|
|
115
|
+
// Reading/Iterating methods
|
|
116
|
+
/**
|
|
117
|
+
* Creates a new array with the results of calling a provided function on every element
|
|
118
|
+
*/
|
|
119
|
+
map(callbackfn, thisArg) {
|
|
120
|
+
return this[forwardArray].map(callbackfn, thisArg);
|
|
121
|
+
}
|
|
122
|
+
filter(predicate, thisArg) {
|
|
123
|
+
return this[forwardArray].filter(predicate, thisArg);
|
|
124
|
+
}
|
|
125
|
+
reduce(callbackfn, initialValue) {
|
|
126
|
+
return initialValue !== undefined
|
|
127
|
+
? this[forwardArray].reduce(callbackfn, initialValue)
|
|
128
|
+
: this[forwardArray].reduce(callbackfn);
|
|
129
|
+
}
|
|
130
|
+
reduceRight(callbackfn, initialValue) {
|
|
131
|
+
return initialValue !== undefined
|
|
132
|
+
? this[forwardArray].reduceRight(callbackfn, initialValue)
|
|
133
|
+
: this[forwardArray].reduceRight(callbackfn);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Executes a provided function once for each array element
|
|
137
|
+
*/
|
|
138
|
+
forEach(callbackfn, thisArg) {
|
|
139
|
+
this[forwardArray].forEach(callbackfn, thisArg);
|
|
140
|
+
}
|
|
141
|
+
find(predicate, thisArg) {
|
|
142
|
+
return this[forwardArray].find(predicate, thisArg);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the index of the first element in the array that satisfies the provided testing function
|
|
146
|
+
*/
|
|
147
|
+
findIndex(predicate, thisArg) {
|
|
148
|
+
return this[forwardArray].findIndex(predicate, thisArg);
|
|
149
|
+
}
|
|
150
|
+
findLast(predicate, thisArg) {
|
|
151
|
+
return this[forwardArray].findLast(predicate, thisArg);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the index of the last element in the array that satisfies the provided testing function
|
|
155
|
+
*/
|
|
156
|
+
findLastIndex(predicate, thisArg) {
|
|
157
|
+
return this[forwardArray].findLastIndex(predicate, thisArg);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Determines whether an array includes a certain value among its entries
|
|
161
|
+
*/
|
|
162
|
+
includes(searchElement, fromIndex) {
|
|
163
|
+
return this[forwardArray].includes(searchElement, fromIndex);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the first index at which a given element can be found in the array
|
|
167
|
+
*/
|
|
168
|
+
indexOf(searchElement, fromIndex) {
|
|
169
|
+
return this[forwardArray].indexOf(searchElement, fromIndex);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns the last index at which a given element can be found in the array
|
|
173
|
+
*/
|
|
174
|
+
lastIndexOf(searchElement, fromIndex) {
|
|
175
|
+
return this[forwardArray].lastIndexOf(searchElement, fromIndex);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns a shallow copy of a portion of an array into a new array object
|
|
179
|
+
*/
|
|
180
|
+
slice(start, end) {
|
|
181
|
+
return this[forwardArray].slice(start, end);
|
|
182
|
+
}
|
|
183
|
+
concat(...items) {
|
|
184
|
+
return this[forwardArray].concat(...items);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Tests whether all elements in the array pass the test implemented by the provided function
|
|
188
|
+
*/
|
|
189
|
+
every(predicate, thisArg) {
|
|
190
|
+
return this[forwardArray].every(predicate, thisArg);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Tests whether at least one element in the array passes the test implemented by the provided function
|
|
194
|
+
*/
|
|
195
|
+
some(predicate, thisArg) {
|
|
196
|
+
return this[forwardArray].some(predicate, thisArg);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Joins all elements of an array into a string
|
|
200
|
+
*/
|
|
201
|
+
join(separator) {
|
|
202
|
+
return this[forwardArray].join(separator);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns a new array iterator that contains the keys for each index in the array
|
|
206
|
+
*/
|
|
207
|
+
keys() {
|
|
208
|
+
return this[forwardArray].keys();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Returns a new array iterator that contains the values for each index in the array
|
|
212
|
+
*/
|
|
213
|
+
values() {
|
|
214
|
+
return this[forwardArray].values();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns a new array iterator that contains the key/value pairs for each index in the array
|
|
218
|
+
*/
|
|
219
|
+
entries() {
|
|
220
|
+
return this[forwardArray].entries();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Returns a string representation of the array
|
|
224
|
+
*/
|
|
225
|
+
toString() {
|
|
226
|
+
return this[forwardArray].toString();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Returns a localized string representing the array
|
|
230
|
+
*/
|
|
231
|
+
toLocaleString(locales, options) {
|
|
232
|
+
return this[forwardArray].toLocaleString(locales, options);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Returns the element at the specified index, or undefined if the index is out of bounds
|
|
236
|
+
*/
|
|
237
|
+
at(index) {
|
|
238
|
+
return this[forwardArray].at(index);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
|
|
242
|
+
*/
|
|
243
|
+
flat(depth) {
|
|
244
|
+
return this[forwardArray].flat(depth);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Returns a new array formed by applying a given callback function to each element of the array,
|
|
248
|
+
* and then flattening the result by one level
|
|
249
|
+
*/
|
|
250
|
+
flatMap(callback, thisArg) {
|
|
251
|
+
return this[forwardArray].flatMap(callback, thisArg);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns a new array with elements in reversed order (ES2023)
|
|
255
|
+
*/
|
|
256
|
+
toReversed() {
|
|
257
|
+
return this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Returns a new array with elements sorted (ES2023)
|
|
261
|
+
*/
|
|
262
|
+
toSorted(compareFn) {
|
|
263
|
+
return this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Returns a new array with some elements removed and/or replaced at a given index (ES2023)
|
|
267
|
+
*/
|
|
268
|
+
toSpliced(start, deleteCount, ...items) {
|
|
269
|
+
if (deleteCount === undefined)
|
|
270
|
+
return this[forwardArray].toSpliced(start);
|
|
271
|
+
return this[forwardArray].toSpliced(start, deleteCount, ...items);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Returns a new array with the element at the given index replaced with the given value (ES2023)
|
|
275
|
+
*/
|
|
276
|
+
with(index, value) {
|
|
277
|
+
return this[forwardArray].with(index, value);
|
|
278
|
+
}
|
|
279
|
+
get [Symbol.unscopables]() {
|
|
280
|
+
return this[forwardArray][Symbol.unscopables];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
83
283
|
|
|
84
|
-
export { Indexable, getAt, setAt };
|
|
284
|
+
export { ArrayReadForward, Indexable, forwardArray, getAt, setAt };
|
|
85
285
|
//# sourceMappingURL=indexable.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexable.esm.js","sources":["../src/indexable.ts"],"sourcesContent":["export const getAt = Symbol('getAt')\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) {\n\t\t\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n"],"names":[],"mappings":"MAAa,KAAK,GAAG,MAAM,CAAC,OAAO;MACtB,KAAK,GAAG,MAAM,CAAC,OAAO;AAoC7B,SAAU,SAAS,CACxB,IAAmC,EACnC,QAAgC,EAAA;AAEhC,IAAA,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QACvC,QAAQ,GAAG,IAA6B;QACxC,IAAI,GAAG,SAAS;IACjB;IACA,IAAI,CAAC,IAAI,EAAE;;AAEV,QAAA,IAAI,GAAG,MAAA;SAAgB;IACxB;IACA,IAAI,CAAC,QAAQ,EAAE;AACd,QAAA,QAAQ,GAAG;AACV,YAAA,GAAG,CAAY,KAAa,EAAA;gBAC3B,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AACtC,oBAAA,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC;gBAC/D;AACA,gBAAA,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;YAC1B,CAAC;YACD,GAAG,CAAY,KAAa,EAAE,KAAY,EAAA;gBACzC,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AACtC,oBAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;gBACtE;gBACA,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC;YAC1B,CAAC;SACD;IACF;IAEA,MAAe,SAAU,SAAS,IAAa,CAAA;AAE9C;AAED,IAAA,MAAM,CAAC,cAAc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AA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC7B,IAAI,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,SAAS,EAAE;oBAC5C,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,oBAAA,OAAO,IAAI;gBACZ;AACA,gBAAA,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;AAC3B,oBAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;AAClB,wBAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;oBACtE;oBACA,QAAQ,CAAC,GAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC;AAC5C,oBAAA,OAAO,IAAI;gBACZ;YACD;AACA,YAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACrC,KAAK;AACL,gBAAA,QAAQ,EAAE,IAAI;AACd,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,YAAY,EAAE,IAAI;AAClB,aAAA,CAAC;AACF,YAAA,OAAO,IAAI;QACZ,CAAC;AACD,KAAA,CAAC,CACF;AACD,IAAA,OAAO,SAAS;AACjB;;;;"}
|
|
1
|
+
{"version":3,"file":"indexable.esm.js","sources":["../src/indexable.ts"],"sourcesContent":["/**\n * Symbol for defining custom getter logic for numeric index access\n */\nexport const getAt = Symbol('getAt')\n/**\n * Symbol for defining custom setter logic for numeric index access\n */\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\n/**\n * Creates an indexable class with a base class and accessor object\n * @param base - The base class to extend\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\n/**\n * Creates an indexable class with only an accessor object (no base class)\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\n/**\n * Creates an indexable class with a base class that has [getAt] method\n * @param base - The base class that implements [getAt] method\n * @returns A class that supports numeric index access using the base class's [getAt] method\n */\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\n/**\n * Creates an abstract indexable base class\n * @returns An abstract class that supports numeric index access\n */\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) throw new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n\n/**\n * Symbol for accessing the forwarded array in ArrayReadForward\n */\nexport const forwardArray = Symbol('forwardArray')\n\n/**\n * A read-only array forwarder that implements all reading/iterating methods of Array\n * but does not implement modification methods.\n *\n * The constructor takes a callback that returns an array, and all methods forward\n * their behavior to the result of that callback.\n */\nexport class ArrayReadForward<T> {\n\tprotected get [forwardArray](): readonly T[] {\n\t\tthrow new Error('ArrayReadForward is not implemented')\n\t}\n\n\t/**\n\t * Get the length of the array\n\t */\n\tget length(): number {\n\t\treturn this[forwardArray].length\n\t}\n\n\t/**\n\t * Get an element at a specific index\n\t */\n\t[index: number]: T | undefined\n\n\t/**\n\t * Iterator protocol support\n\t */\n\t[Symbol.iterator](): Iterator<T> {\n\t\treturn this[forwardArray][Symbol.iterator]()\n\t}\n\n\t// Reading/Iterating methods\n\n\t/**\n\t * Creates a new array with the results of calling a provided function on every element\n\t */\n\tmap<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[] {\n\t\treturn this[forwardArray].map(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Creates a new array with all elements that pass the test implemented by the provided function\n\t */\n\tfilter<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[] {\n\t\treturn this[forwardArray].filter(predicate, thisArg)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array, resulting in a single output value\n\t */\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduce<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduce(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduce(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduce(callbackfn)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value\n\t */\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduceRight<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduceRight(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduceRight(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduceRight(callbackfn)\n\t}\n\n\t/**\n\t * Executes a provided function once for each array element\n\t */\n\tforEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void {\n\t\tthis[forwardArray].forEach(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the first element in the array that satisfies the provided testing function\n\t */\n\tfind<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].find(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the first element in the array that satisfies the provided testing function\n\t */\n\tfindIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLast<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].findLast(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLastIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findLastIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Determines whether an array includes a certain value among its entries\n\t */\n\tincludes(searchElement: T, fromIndex?: number): boolean {\n\t\treturn this[forwardArray].includes(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the first index at which a given element can be found in the array\n\t */\n\tindexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].indexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the last index at which a given element can be found in the array\n\t */\n\tlastIndexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].lastIndexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns a shallow copy of a portion of an array into a new array object\n\t */\n\tslice(start?: number, end?: number): T[] {\n\t\treturn this[forwardArray].slice(start, end)\n\t}\n\n\t/**\n\t * Returns a new array comprised of this array joined with other array(s) and/or value(s)\n\t */\n\tconcat(...items: ConcatArray<T>[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[] {\n\t\treturn this[forwardArray].concat(...items)\n\t}\n\n\t/**\n\t * Tests whether all elements in the array pass the test implemented by the provided function\n\t */\n\tevery(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].every(predicate, thisArg)\n\t}\n\n\t/**\n\t * Tests whether at least one element in the array passes the test implemented by the provided function\n\t */\n\tsome(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].some(predicate, thisArg)\n\t}\n\n\t/**\n\t * Joins all elements of an array into a string\n\t */\n\tjoin(separator?: string): string {\n\t\treturn this[forwardArray].join(separator)\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the keys for each index in the array\n\t */\n\tkeys(): IterableIterator<number> {\n\t\treturn this[forwardArray].keys()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the values for each index in the array\n\t */\n\tvalues(): IterableIterator<T> {\n\t\treturn this[forwardArray].values()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the key/value pairs for each index in the array\n\t */\n\tentries(): IterableIterator<[number, T]> {\n\t\treturn this[forwardArray].entries()\n\t}\n\n\t/**\n\t * Returns a string representation of the array\n\t */\n\ttoString(): string {\n\t\treturn this[forwardArray].toString()\n\t}\n\n\t/**\n\t * Returns a localized string representing the array\n\t */\n\ttoLocaleString(\n\t\tlocales?: string | string[],\n\t\toptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions\n\t): string {\n\t\treturn this[forwardArray].toLocaleString(locales as string | string[], options)\n\t}\n\n\t/**\n\t * Returns the element at the specified index, or undefined if the index is out of bounds\n\t */\n\tat(index: number): T | undefined {\n\t\treturn this[forwardArray].at(index)\n\t}\n\n\t/**\n\t * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth\n\t */\n\tflat(depth?: number): T[] {\n\t\treturn this[forwardArray].flat(depth) as T[]\n\t}\n\n\t/**\n\t * Returns a new array formed by applying a given callback function to each element of the array,\n\t * and then flattening the result by one level\n\t */\n\tflatMap<U, This = undefined>(\n\t\tcallback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>,\n\t\tthisArg?: This\n\t): U[] {\n\t\treturn this[forwardArray].flatMap(callback as any, thisArg)\n\t}\n\n\t/**\n\t * Returns a new array with elements in reversed order (ES2023)\n\t */\n\ttoReversed(): T[] {\n\t\treturn this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse()\n\t}\n\n\t/**\n\t * Returns a new array with elements sorted (ES2023)\n\t */\n\ttoSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[] {\n\t\treturn this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn)\n\t}\n\n\t/**\n\t * Returns a new array with some elements removed and/or replaced at a given index (ES2023)\n\t */\n\ttoSpliced(start: number, deleteCount?: number, ...items: T[]): T[] {\n\t\tif (deleteCount === undefined) return this[forwardArray].toSpliced(start)\n\t\treturn this[forwardArray].toSpliced(start, deleteCount, ...items)\n\t}\n\n\t/**\n\t * Returns a new array with the element at the given index replaced with the given value (ES2023)\n\t */\n\twith(index: number, value: T): T[] {\n\t\treturn this[forwardArray].with(index, value)\n\t}\n\tget [Symbol.unscopables]() {\n\t\treturn this[forwardArray][Symbol.unscopables]\n\t}\n}\n"],"names":[],"mappings":"AAAA;;AAEG;MACU,KAAK,GAAG,MAAM,CAAC,OAAO;AACnC;;AAEG;MACU,KAAK,GAAG,MAAM,CAAC,OAAO;AAwD7B,SAAU,SAAS,CACxB,IAAmC,EACnC,QAAgC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K,MAAM,CAAC,WAAW,CAAC,GAAA;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;IAC9C;AACA;;;;"}
|
package/dist/indexable.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Symbol for defining custom getter logic for numeric index access
|
|
5
|
+
*/
|
|
3
6
|
const getAt = Symbol('getAt');
|
|
7
|
+
/**
|
|
8
|
+
* Symbol for defining custom setter logic for numeric index access
|
|
9
|
+
*/
|
|
4
10
|
const setAt = Symbol('setAt');
|
|
5
11
|
function Indexable(base, accessor) {
|
|
6
12
|
if (base && typeof base !== 'function') {
|
|
@@ -64,9 +70,8 @@ function Indexable(base, accessor) {
|
|
|
64
70
|
}
|
|
65
71
|
const numProp = Number(prop);
|
|
66
72
|
if (!Number.isNaN(numProp)) {
|
|
67
|
-
if (!accessor.set)
|
|
73
|
+
if (!accessor.set)
|
|
68
74
|
throw new Error('Indexable class has read-only numeric index access');
|
|
69
|
-
}
|
|
70
75
|
accessor.set.call(receiver, numProp, value);
|
|
71
76
|
return true;
|
|
72
77
|
}
|
|
@@ -82,8 +87,205 @@ function Indexable(base, accessor) {
|
|
|
82
87
|
}));
|
|
83
88
|
return Indexable;
|
|
84
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Symbol for accessing the forwarded array in ArrayReadForward
|
|
92
|
+
*/
|
|
93
|
+
const forwardArray = Symbol('forwardArray');
|
|
94
|
+
/**
|
|
95
|
+
* A read-only array forwarder that implements all reading/iterating methods of Array
|
|
96
|
+
* but does not implement modification methods.
|
|
97
|
+
*
|
|
98
|
+
* The constructor takes a callback that returns an array, and all methods forward
|
|
99
|
+
* their behavior to the result of that callback.
|
|
100
|
+
*/
|
|
101
|
+
class ArrayReadForward {
|
|
102
|
+
get [forwardArray]() {
|
|
103
|
+
throw new Error('ArrayReadForward is not implemented');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the length of the array
|
|
107
|
+
*/
|
|
108
|
+
get length() {
|
|
109
|
+
return this[forwardArray].length;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Iterator protocol support
|
|
113
|
+
*/
|
|
114
|
+
[Symbol.iterator]() {
|
|
115
|
+
return this[forwardArray][Symbol.iterator]();
|
|
116
|
+
}
|
|
117
|
+
// Reading/Iterating methods
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new array with the results of calling a provided function on every element
|
|
120
|
+
*/
|
|
121
|
+
map(callbackfn, thisArg) {
|
|
122
|
+
return this[forwardArray].map(callbackfn, thisArg);
|
|
123
|
+
}
|
|
124
|
+
filter(predicate, thisArg) {
|
|
125
|
+
return this[forwardArray].filter(predicate, thisArg);
|
|
126
|
+
}
|
|
127
|
+
reduce(callbackfn, initialValue) {
|
|
128
|
+
return initialValue !== undefined
|
|
129
|
+
? this[forwardArray].reduce(callbackfn, initialValue)
|
|
130
|
+
: this[forwardArray].reduce(callbackfn);
|
|
131
|
+
}
|
|
132
|
+
reduceRight(callbackfn, initialValue) {
|
|
133
|
+
return initialValue !== undefined
|
|
134
|
+
? this[forwardArray].reduceRight(callbackfn, initialValue)
|
|
135
|
+
: this[forwardArray].reduceRight(callbackfn);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Executes a provided function once for each array element
|
|
139
|
+
*/
|
|
140
|
+
forEach(callbackfn, thisArg) {
|
|
141
|
+
this[forwardArray].forEach(callbackfn, thisArg);
|
|
142
|
+
}
|
|
143
|
+
find(predicate, thisArg) {
|
|
144
|
+
return this[forwardArray].find(predicate, thisArg);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Returns the index of the first element in the array that satisfies the provided testing function
|
|
148
|
+
*/
|
|
149
|
+
findIndex(predicate, thisArg) {
|
|
150
|
+
return this[forwardArray].findIndex(predicate, thisArg);
|
|
151
|
+
}
|
|
152
|
+
findLast(predicate, thisArg) {
|
|
153
|
+
return this[forwardArray].findLast(predicate, thisArg);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns the index of the last element in the array that satisfies the provided testing function
|
|
157
|
+
*/
|
|
158
|
+
findLastIndex(predicate, thisArg) {
|
|
159
|
+
return this[forwardArray].findLastIndex(predicate, thisArg);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Determines whether an array includes a certain value among its entries
|
|
163
|
+
*/
|
|
164
|
+
includes(searchElement, fromIndex) {
|
|
165
|
+
return this[forwardArray].includes(searchElement, fromIndex);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns the first index at which a given element can be found in the array
|
|
169
|
+
*/
|
|
170
|
+
indexOf(searchElement, fromIndex) {
|
|
171
|
+
return this[forwardArray].indexOf(searchElement, fromIndex);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Returns the last index at which a given element can be found in the array
|
|
175
|
+
*/
|
|
176
|
+
lastIndexOf(searchElement, fromIndex) {
|
|
177
|
+
return this[forwardArray].lastIndexOf(searchElement, fromIndex);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns a shallow copy of a portion of an array into a new array object
|
|
181
|
+
*/
|
|
182
|
+
slice(start, end) {
|
|
183
|
+
return this[forwardArray].slice(start, end);
|
|
184
|
+
}
|
|
185
|
+
concat(...items) {
|
|
186
|
+
return this[forwardArray].concat(...items);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Tests whether all elements in the array pass the test implemented by the provided function
|
|
190
|
+
*/
|
|
191
|
+
every(predicate, thisArg) {
|
|
192
|
+
return this[forwardArray].every(predicate, thisArg);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Tests whether at least one element in the array passes the test implemented by the provided function
|
|
196
|
+
*/
|
|
197
|
+
some(predicate, thisArg) {
|
|
198
|
+
return this[forwardArray].some(predicate, thisArg);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Joins all elements of an array into a string
|
|
202
|
+
*/
|
|
203
|
+
join(separator) {
|
|
204
|
+
return this[forwardArray].join(separator);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Returns a new array iterator that contains the keys for each index in the array
|
|
208
|
+
*/
|
|
209
|
+
keys() {
|
|
210
|
+
return this[forwardArray].keys();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns a new array iterator that contains the values for each index in the array
|
|
214
|
+
*/
|
|
215
|
+
values() {
|
|
216
|
+
return this[forwardArray].values();
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns a new array iterator that contains the key/value pairs for each index in the array
|
|
220
|
+
*/
|
|
221
|
+
entries() {
|
|
222
|
+
return this[forwardArray].entries();
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Returns a string representation of the array
|
|
226
|
+
*/
|
|
227
|
+
toString() {
|
|
228
|
+
return this[forwardArray].toString();
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Returns a localized string representing the array
|
|
232
|
+
*/
|
|
233
|
+
toLocaleString(locales, options) {
|
|
234
|
+
return this[forwardArray].toLocaleString(locales, options);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns the element at the specified index, or undefined if the index is out of bounds
|
|
238
|
+
*/
|
|
239
|
+
at(index) {
|
|
240
|
+
return this[forwardArray].at(index);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
|
|
244
|
+
*/
|
|
245
|
+
flat(depth) {
|
|
246
|
+
return this[forwardArray].flat(depth);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Returns a new array formed by applying a given callback function to each element of the array,
|
|
250
|
+
* and then flattening the result by one level
|
|
251
|
+
*/
|
|
252
|
+
flatMap(callback, thisArg) {
|
|
253
|
+
return this[forwardArray].flatMap(callback, thisArg);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Returns a new array with elements in reversed order (ES2023)
|
|
257
|
+
*/
|
|
258
|
+
toReversed() {
|
|
259
|
+
return this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse();
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Returns a new array with elements sorted (ES2023)
|
|
263
|
+
*/
|
|
264
|
+
toSorted(compareFn) {
|
|
265
|
+
return this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Returns a new array with some elements removed and/or replaced at a given index (ES2023)
|
|
269
|
+
*/
|
|
270
|
+
toSpliced(start, deleteCount, ...items) {
|
|
271
|
+
if (deleteCount === undefined)
|
|
272
|
+
return this[forwardArray].toSpliced(start);
|
|
273
|
+
return this[forwardArray].toSpliced(start, deleteCount, ...items);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Returns a new array with the element at the given index replaced with the given value (ES2023)
|
|
277
|
+
*/
|
|
278
|
+
with(index, value) {
|
|
279
|
+
return this[forwardArray].with(index, value);
|
|
280
|
+
}
|
|
281
|
+
get [Symbol.unscopables]() {
|
|
282
|
+
return this[forwardArray][Symbol.unscopables];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
85
285
|
|
|
286
|
+
exports.ArrayReadForward = ArrayReadForward;
|
|
86
287
|
exports.Indexable = Indexable;
|
|
288
|
+
exports.forwardArray = forwardArray;
|
|
87
289
|
exports.getAt = getAt;
|
|
88
290
|
exports.setAt = setAt;
|
|
89
291
|
//# sourceMappingURL=indexable.js.map
|
package/dist/indexable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexable.js","sources":["../src/indexable.ts"],"sourcesContent":["export const getAt = Symbol('getAt')\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) {\n\t\t\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n"],"names":[],"m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AAO,CAAC,EAAE;AAC3B,oBAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;AAClB,wBAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;oBACtE;oBACA,QAAQ,CAAC,GAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC;AAC5C,oBAAA,OAAO,IAAI;gBACZ;YACD;AACA,YAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACrC,KAAK;AACL,gBAAA,QAAQ,EAAE,IAAI;AACd,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,YAAY,EAAE,IAAI;AAClB,aAAA,CAAC;AACF,YAAA,OAAO,IAAI;QACZ,CAAC;AACD,KAAA,CAAC,CACF;AACD,IAAA,OAAO,SAAS;AACjB;;;;;;"}
|
|
1
|
+
{"version":3,"file":"indexable.js","sources":["../src/indexable.ts"],"sourcesContent":["/**\n * Symbol for defining custom getter logic for numeric index access\n */\nexport const getAt = Symbol('getAt')\n/**\n * Symbol for defining custom setter logic for numeric index access\n */\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\n/**\n * Creates an indexable class with a base class and accessor object\n * @param base - The base class to extend\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\n/**\n * Creates an indexable class with only an accessor object (no base class)\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\n/**\n * Creates an indexable class with a base class that has [getAt] method\n * @param base - The base class that implements [getAt] method\n * @returns A class that supports numeric index access using the base class's [getAt] method\n */\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\n/**\n * Creates an abstract indexable base class\n * @returns An abstract class that supports numeric index access\n */\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) throw new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n\n/**\n * Symbol for accessing the forwarded array in ArrayReadForward\n */\nexport const forwardArray = Symbol('forwardArray')\n\n/**\n * A read-only array forwarder that implements all reading/iterating methods of Array\n * but does not implement modification methods.\n *\n * The constructor takes a callback that returns an array, and all methods forward\n * their behavior to the result of that callback.\n */\nexport class ArrayReadForward<T> {\n\tprotected get [forwardArray](): readonly T[] {\n\t\tthrow new Error('ArrayReadForward is not implemented')\n\t}\n\n\t/**\n\t * Get the length of the array\n\t */\n\tget length(): number {\n\t\treturn this[forwardArray].length\n\t}\n\n\t/**\n\t * Get an element at a specific index\n\t */\n\t[index: number]: T | undefined\n\n\t/**\n\t * Iterator protocol support\n\t */\n\t[Symbol.iterator](): Iterator<T> {\n\t\treturn this[forwardArray][Symbol.iterator]()\n\t}\n\n\t// Reading/Iterating methods\n\n\t/**\n\t * Creates a new array with the results of calling a provided function on every element\n\t */\n\tmap<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[] {\n\t\treturn this[forwardArray].map(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Creates a new array with all elements that pass the test implemented by the provided function\n\t */\n\tfilter<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[] {\n\t\treturn this[forwardArray].filter(predicate, thisArg)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array, resulting in a single output value\n\t */\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduce<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduce(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduce(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduce(callbackfn)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value\n\t */\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduceRight<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduceRight(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduceRight(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduceRight(callbackfn)\n\t}\n\n\t/**\n\t * Executes a provided function once for each array element\n\t */\n\tforEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void {\n\t\tthis[forwardArray].forEach(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the first element in the array that satisfies the provided testing function\n\t */\n\tfind<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].find(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the first element in the array that satisfies the provided testing function\n\t */\n\tfindIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLast<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].findLast(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLastIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findLastIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Determines whether an array includes a certain value among its entries\n\t */\n\tincludes(searchElement: T, fromIndex?: number): boolean {\n\t\treturn this[forwardArray].includes(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the first index at which a given element can be found in the array\n\t */\n\tindexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].indexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the last index at which a given element can be found in the array\n\t */\n\tlastIndexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].lastIndexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns a shallow copy of a portion of an array into a new array object\n\t */\n\tslice(start?: number, end?: number): T[] {\n\t\treturn this[forwardArray].slice(start, end)\n\t}\n\n\t/**\n\t * Returns a new array comprised of this array joined with other array(s) and/or value(s)\n\t */\n\tconcat(...items: ConcatArray<T>[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[] {\n\t\treturn this[forwardArray].concat(...items)\n\t}\n\n\t/**\n\t * Tests whether all elements in the array pass the test implemented by the provided function\n\t */\n\tevery(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].every(predicate, thisArg)\n\t}\n\n\t/**\n\t * Tests whether at least one element in the array passes the test implemented by the provided function\n\t */\n\tsome(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].some(predicate, thisArg)\n\t}\n\n\t/**\n\t * Joins all elements of an array into a string\n\t */\n\tjoin(separator?: string): string {\n\t\treturn this[forwardArray].join(separator)\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the keys for each index in the array\n\t */\n\tkeys(): IterableIterator<number> {\n\t\treturn this[forwardArray].keys()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the values for each index in the array\n\t */\n\tvalues(): IterableIterator<T> {\n\t\treturn this[forwardArray].values()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the key/value pairs for each index in the array\n\t */\n\tentries(): IterableIterator<[number, T]> {\n\t\treturn this[forwardArray].entries()\n\t}\n\n\t/**\n\t * Returns a string representation of the array\n\t */\n\ttoString(): string {\n\t\treturn this[forwardArray].toString()\n\t}\n\n\t/**\n\t * Returns a localized string representing the array\n\t */\n\ttoLocaleString(\n\t\tlocales?: string | string[],\n\t\toptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions\n\t): string {\n\t\treturn this[forwardArray].toLocaleString(locales as string | string[], options)\n\t}\n\n\t/**\n\t * Returns the element at the specified index, or undefined if the index is out of bounds\n\t */\n\tat(index: number): T | undefined {\n\t\treturn this[forwardArray].at(index)\n\t}\n\n\t/**\n\t * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth\n\t */\n\tflat(depth?: number): T[] {\n\t\treturn this[forwardArray].flat(depth) as T[]\n\t}\n\n\t/**\n\t * Returns a new array formed by applying a given callback function to each element of the array,\n\t * and then flattening the result by one level\n\t */\n\tflatMap<U, This = undefined>(\n\t\tcallback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>,\n\t\tthisArg?: This\n\t): U[] {\n\t\treturn this[forwardArray].flatMap(callback as any, thisArg)\n\t}\n\n\t/**\n\t * Returns a new array with elements in reversed order (ES2023)\n\t */\n\ttoReversed(): T[] {\n\t\treturn this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse()\n\t}\n\n\t/**\n\t * Returns a new array with elements sorted (ES2023)\n\t */\n\ttoSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[] {\n\t\treturn this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn)\n\t}\n\n\t/**\n\t * Returns a new array with some elements removed and/or replaced at a given index (ES2023)\n\t */\n\ttoSpliced(start: number, deleteCount?: number, ...items: T[]): T[] {\n\t\tif (deleteCount === undefined) return this[forwardArray].toSpliced(start)\n\t\treturn this[forwardArray].toSpliced(start, deleteCount, ...items)\n\t}\n\n\t/**\n\t * Returns a new array with the element at the given index replaced with the given value (ES2023)\n\t */\n\twith(index: number, value: T): T[] {\n\t\treturn this[forwardArray].with(index, value)\n\t}\n\tget [Symbol.unscopables]() {\n\t\treturn this[forwardArray][Symbol.unscopables]\n\t}\n}\n"],"names":[],"mappings":";;AAAA;;AAEG;MACU,KAAK,GAAG,MAAM,CAAC,OAAO;AACnC;;AAEG;MACU,KAAK,GAAG,MAAM,CAAC,OAAO;AAwD7B,SAAU,SAAS,CACxB,IAAmC,EACnC,QAAgC,EAAA;AAEhC,IAAA,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QACvC,QAAQ,GAAG,IAA6B;QACxC,IAAI,GAAG,SAAS;IACjB;IACA,IAAI,CAAC,IAAI,EAAE;;AAEV,QAAA,IAAI,GAAG,MAAA;SAAgB;IACxB;IACA,IAAI,CAAC,QAAQ,EAAE;AACd,QAAA,QAAQ,GAAG;AACV,YAAA,GAAG,CAAY,KAAa,EAAA;gBAC3B,IAAI,OAAO,I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