mutts 1.0.2 → 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 +14 -6
- package/dist/chunks/{_tslib-C-cuVLvZ.js → _tslib-BgjropY9.js} +9 -1
- package/dist/chunks/_tslib-BgjropY9.js.map +1 -0
- package/dist/chunks/{_tslib-CMEnd0VE.esm.js → _tslib-Mzh1rNsX.esm.js} +9 -2
- package/dist/chunks/_tslib-Mzh1rNsX.esm.js.map +1 -0
- package/dist/chunks/{decorator-D4DU97Zg.js → decorator-DLvrD0UF.js} +42 -19
- package/dist/chunks/decorator-DLvrD0UF.js.map +1 -0
- package/dist/chunks/{decorator-GnHw1Az7.esm.js → decorator-DqiszP7i.esm.js} +42 -19
- 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.esm.js +1 -1
- package/dist/decorator.js +1 -1
- package/dist/destroyable.d.ts +1 -1
- package/dist/destroyable.esm.js +1 -1
- package/dist/destroyable.esm.js.map +1 -1
- package/dist/destroyable.js +1 -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.esm.js +1 -1
- package/dist/eventful.js +1 -1
- package/dist/index.d.ts +18 -63
- package/dist/index.esm.js +4 -4
- package/dist/index.js +36 -11
- package/dist/index.js.map +1 -1
- package/dist/indexable.d.ts +187 -1
- package/dist/indexable.esm.js +197 -3
- package/dist/indexable.esm.js.map +1 -1
- package/dist/indexable.js +198 -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.esm.js.map +1 -1
- package/dist/promiseChain.js.map +1 -1
- package/dist/reactive.d.ts +601 -97
- package/dist/reactive.esm.js +3 -3
- package/dist/reactive.js +31 -10
- package/dist/reactive.js.map +1 -1
- package/dist/std-decorators.esm.js +1 -1
- package/dist/std-decorators.js +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/reactive/advanced.md +1280 -0
- package/docs/reactive/collections.md +767 -0
- package/docs/reactive/core.md +973 -0
- package/docs/reactive.md +21 -9545
- 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/_tslib-C-cuVLvZ.js.map +0 -1
- package/dist/chunks/_tslib-CMEnd0VE.esm.js.map +0 -1
- package/dist/chunks/decorator-D4DU97Zg.js.map +0 -1
- package/dist/chunks/decorator-GnHw1Az7.esm.js.map +0 -1
- package/dist/chunks/index-DBScoeCX.esm.js +0 -1960
- package/dist/chunks/index-DBScoeCX.esm.js.map +0 -1
- package/dist/chunks/index-DOTmXL89.js +0 -1983
- package/dist/chunks/index-DOTmXL89.js.map +0 -1
package/dist/eventful.esm.js
CHANGED
package/dist/eventful.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,64 +1,19 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
1
|
+
export * from './decorator.js'
|
|
2
|
+
export * from './destroyable.js'
|
|
3
|
+
export * from './eventful.js'
|
|
4
|
+
export * from './indexable.js'
|
|
5
|
+
export * from './iterableWeak.js'
|
|
6
|
+
export * from './mixins.js'
|
|
7
|
+
export * from './reactive.js'
|
|
8
|
+
export * from './std-decorators.js'
|
|
9
|
+
export * from './utils.js'
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type MixinClass<Mixed> = new (...args: any[]) => Mixed;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a mixin that can be used both as a class (extends) and as a function (mixin)
|
|
20
|
-
*
|
|
21
|
-
* This function supports:
|
|
22
|
-
* - Using mixins as base classes: `class MyClass extends MyMixin`
|
|
23
|
-
* - Using mixins as functions: `class MyClass extends MyMixin(SomeBase)`
|
|
24
|
-
* - Composing mixins: `const Composed = MixinA(MixinB)`
|
|
25
|
-
* - Type-safe property inference for all patterns
|
|
26
|
-
*
|
|
27
|
-
* @param mixinFunction - The function that creates the mixin
|
|
28
|
-
* @param unwrapFunction - Optional function to unwrap reactive objects for method calls
|
|
29
|
-
* @returns A mixin that can be used both as a class and as a function
|
|
30
|
-
*/
|
|
31
|
-
declare function mixin<MixinFn extends (base: any) => new (...args: any[]) => any>(mixinFunction: MixinFn, unwrapFunction?: (obj: any) => any): (new (...args: any[]) => InstanceType<ReturnType<MixinFn>>) & (<Base>(base: abstract new (...args: any[]) => Base) => new (...args: any[]) => InstanceType<ReturnType<MixinFn>> & Base);
|
|
32
|
-
|
|
33
|
-
type ElementTypes<T extends readonly unknown[]> = {
|
|
34
|
-
[K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K];
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Combines multiple arrays into an array of tuples, stopping at the shortest array length
|
|
38
|
-
* @param args - Arrays to zip together
|
|
39
|
-
* @returns Array of tuples containing elements from each input array
|
|
40
|
-
*/
|
|
41
|
-
declare function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[];
|
|
42
|
-
/**
|
|
43
|
-
* Checks if a function is a constructor (class or constructor function)
|
|
44
|
-
* @param fn - The function to check
|
|
45
|
-
* @returns True if the function is a constructor
|
|
46
|
-
*/
|
|
47
|
-
declare function isConstructor(fn: Function): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Renames a function with a new name
|
|
50
|
-
* @param fct - The function to rename
|
|
51
|
-
* @param name - The new name for the function
|
|
52
|
-
* @returns The function with the new name
|
|
53
|
-
*/
|
|
54
|
-
declare function renamed<F extends Function>(fct: F, name: string): F;
|
|
55
|
-
declare function ReflectGet(obj: any, prop: any, receiver: any): any;
|
|
56
|
-
declare function ReflectSet(obj: any, prop: any, value: any, receiver: any): any;
|
|
57
|
-
declare function isOwnAccessor(obj: any, prop: any): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Check if an object is an object (not null, not primitive)
|
|
60
|
-
*/
|
|
61
|
-
declare function isObject(obj: any): obj is object;
|
|
62
|
-
|
|
63
|
-
export { ReflectGet, ReflectSet, isConstructor, isObject, isOwnAccessor, mixin, renamed, zip };
|
|
64
|
-
export type { MixinClass, MixinFunction };
|
|
11
|
+
// Augment Array.isArray to properly handle readonly arrays in type narrowing
|
|
12
|
+
interface ArrayConstructor {
|
|
13
|
+
/**
|
|
14
|
+
* Determines whether an object is an array.
|
|
15
|
+
* @param arg Any value to test.
|
|
16
|
+
* @returns True if the value is an array (mutable or readonly), false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
isArray(arg: any): arg is any[] | readonly any[]
|
|
19
|
+
}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { D as DecoratorError, R as ReflectGet,
|
|
1
|
+
export { D as DecoratorError, R as ReflectGet, b as ReflectSet, a as arrayEquals, d as decorator, i as isConstructor, c as isOwnAccessor, l as legacyDecorator, m as modernDecorator, r as renamed, z as zip } from './chunks/decorator-DqiszP7i.esm.js';
|
|
2
2
|
export { Destroyable, DestructionError, allocated, allocatedValues, callOnGC, destructor } from './destroyable.esm.js';
|
|
3
3
|
export { Eventful } from './eventful.esm.js';
|
|
4
|
-
export { Indexable, getAt, setAt } from './indexable.esm.js';
|
|
5
|
-
export {
|
|
4
|
+
export { ArrayReadForward, Indexable, forwardArray, getAt, setAt } from './indexable.esm.js';
|
|
5
|
+
export { I as IterableWeakMap, a as IterableWeakSet, L as ReactiveBase, U as ReactiveError, R as ReadOnlyError, Q as Register, j as addBatchCleanup, k as atomic, l as biDi, c as buildReactivityGraph, x as cleanedBy, y as cleanup, h as deepWatch, n as defer, z as derived, o as effect, e as enableDevTools, q as getActiveEffect, g as getState, F as immutables, i as isDevtoolsEnabled, G as isNonReactive, K as isReactive, V as isZoneEnabled, C as mapped, E as memoize, m as mixin, O as organize, P as organized, p as profileInfo, J as project, M as reactive, T as reactiveOptions, D as reduced, S as register, r as registerEffectForDebug, H as registerNativeReactivity, d as registerObjectForDebug, u as root, s as setEffectName, f as setObjectName, W as setZoneEnabled, t as touched, b as touched1, v as trackEffect, A as unreactive, w as untracked, N as unwrap, B as watch } from './chunks/index-DzUDtFc7.esm.js';
|
|
6
6
|
export { cache, cached, debounce, deprecated, describe, isCached, throttle } from './std-decorators.esm.js';
|
|
7
|
-
import './chunks/_tslib-
|
|
7
|
+
import './chunks/_tslib-Mzh1rNsX.esm.js';
|
|
8
8
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var decorator = require('./chunks/decorator-
|
|
3
|
+
var decorator = require('./chunks/decorator-DLvrD0UF.js');
|
|
4
4
|
var destroyable = require('./destroyable.js');
|
|
5
5
|
var eventful = require('./eventful.js');
|
|
6
6
|
var indexable = require('./indexable.js');
|
|
7
|
-
var reactive = require('./chunks/index-
|
|
7
|
+
var reactive = require('./chunks/index-HNVqPzjz.js');
|
|
8
8
|
var stdDecorators = require('./std-decorators.js');
|
|
9
|
-
require('./chunks/_tslib-
|
|
9
|
+
require('./chunks/_tslib-BgjropY9.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
exports.DecoratorError = decorator.DecoratorError;
|
|
14
14
|
exports.ReflectGet = decorator.ReflectGet;
|
|
15
15
|
exports.ReflectSet = decorator.ReflectSet;
|
|
16
|
+
exports.arrayEquals = decorator.arrayEquals;
|
|
16
17
|
exports.decorator = decorator.decorator;
|
|
17
18
|
exports.isConstructor = decorator.isConstructor;
|
|
18
|
-
exports.isObject = decorator.isObject;
|
|
19
19
|
exports.isOwnAccessor = decorator.isOwnAccessor;
|
|
20
20
|
exports.legacyDecorator = decorator.legacyDecorator;
|
|
21
21
|
exports.modernDecorator = decorator.modernDecorator;
|
|
@@ -28,30 +28,55 @@ exports.allocatedValues = destroyable.allocatedValues;
|
|
|
28
28
|
exports.callOnGC = destroyable.callOnGC;
|
|
29
29
|
exports.destructor = destroyable.destructor;
|
|
30
30
|
exports.Eventful = eventful.Eventful;
|
|
31
|
+
exports.ArrayReadForward = indexable.ArrayReadForward;
|
|
31
32
|
exports.Indexable = indexable.Indexable;
|
|
33
|
+
exports.forwardArray = indexable.forwardArray;
|
|
32
34
|
exports.getAt = indexable.getAt;
|
|
33
35
|
exports.setAt = indexable.setAt;
|
|
34
|
-
exports.
|
|
36
|
+
exports.IterableWeakMap = reactive.IterableWeakMap;
|
|
37
|
+
exports.IterableWeakSet = reactive.IterableWeakSet;
|
|
35
38
|
exports.ReactiveBase = reactive.ReactiveBase;
|
|
36
39
|
exports.ReactiveError = reactive.ReactiveError;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
get: function () { return reactive.activeEffect; }
|
|
40
|
-
});
|
|
40
|
+
exports.ReadOnlyError = reactive.ReadOnlyError;
|
|
41
|
+
exports.Register = reactive.Register;
|
|
41
42
|
exports.addBatchCleanup = reactive.addBatchCleanup;
|
|
42
43
|
exports.atomic = reactive.atomic;
|
|
44
|
+
exports.biDi = reactive.biDi;
|
|
45
|
+
exports.buildReactivityGraph = reactive.buildReactivityGraph;
|
|
43
46
|
exports.cleanedBy = reactive.cleanedBy;
|
|
44
|
-
exports.
|
|
47
|
+
exports.cleanup = reactive.cleanup;
|
|
48
|
+
exports.deepWatch = reactive.deepWatch;
|
|
49
|
+
exports.defer = reactive.defer;
|
|
50
|
+
exports.derived = reactive.derived;
|
|
45
51
|
exports.effect = reactive.effect;
|
|
52
|
+
exports.enableDevTools = reactive.enableDevTools;
|
|
53
|
+
exports.getActiveEffect = reactive.getActiveEffect;
|
|
46
54
|
exports.getState = reactive.getState;
|
|
47
55
|
exports.immutables = reactive.immutables;
|
|
48
|
-
exports.
|
|
56
|
+
exports.isDevtoolsEnabled = reactive.isDevtoolsEnabled;
|
|
49
57
|
exports.isNonReactive = reactive.isNonReactive;
|
|
50
58
|
exports.isReactive = reactive.isReactive;
|
|
59
|
+
exports.isZoneEnabled = reactive.isZoneEnabled;
|
|
60
|
+
exports.mapped = reactive.mapped;
|
|
61
|
+
exports.memoize = reactive.memoize;
|
|
51
62
|
exports.mixin = reactive.mixin;
|
|
63
|
+
exports.organize = reactive.organize;
|
|
64
|
+
exports.organized = reactive.organized;
|
|
52
65
|
exports.profileInfo = reactive.profileInfo;
|
|
66
|
+
exports.project = reactive.project;
|
|
53
67
|
exports.reactive = reactive.reactive;
|
|
54
68
|
exports.reactiveOptions = reactive.options;
|
|
69
|
+
exports.reduced = reactive.reduced;
|
|
70
|
+
exports.register = reactive.register;
|
|
71
|
+
exports.registerEffectForDebug = reactive.registerEffectForDebug;
|
|
72
|
+
exports.registerNativeReactivity = reactive.registerNativeReactivity;
|
|
73
|
+
exports.registerObjectForDebug = reactive.registerObjectForDebug;
|
|
74
|
+
exports.root = reactive.root;
|
|
75
|
+
exports.setEffectName = reactive.setEffectName;
|
|
76
|
+
exports.setObjectName = reactive.setObjectName;
|
|
77
|
+
exports.setZoneEnabled = reactive.setZoneEnabled;
|
|
78
|
+
exports.touched = reactive.touched;
|
|
79
|
+
exports.touched1 = reactive.touched1;
|
|
55
80
|
exports.trackEffect = reactive.trackEffect;
|
|
56
81
|
exports.unreactive = reactive.unreactive;
|
|
57
82
|
exports.untracked = reactive.untracked;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/indexable.d.ts
CHANGED
|
@@ -53,5 +53,191 @@ declare function Indexable<Items>(): abstract new (...args: any[]) => AbstractGe
|
|
|
53
53
|
type AtReturnType<T> = T extends {
|
|
54
54
|
[getAt](index: number): infer R;
|
|
55
55
|
} ? R : never;
|
|
56
|
+
/**
|
|
57
|
+
* Symbol for accessing the forwarded array in ArrayReadForward
|
|
58
|
+
*/
|
|
59
|
+
declare const forwardArray: unique symbol;
|
|
60
|
+
/**
|
|
61
|
+
* A read-only array forwarder that implements all reading/iterating methods of Array
|
|
62
|
+
* but does not implement modification methods.
|
|
63
|
+
*
|
|
64
|
+
* The constructor takes a callback that returns an array, and all methods forward
|
|
65
|
+
* their behavior to the result of that callback.
|
|
66
|
+
*/
|
|
67
|
+
declare class ArrayReadForward<T> {
|
|
68
|
+
protected get [forwardArray](): readonly T[];
|
|
69
|
+
/**
|
|
70
|
+
* Get the length of the array
|
|
71
|
+
*/
|
|
72
|
+
get length(): number;
|
|
73
|
+
/**
|
|
74
|
+
* Get an element at a specific index
|
|
75
|
+
*/
|
|
76
|
+
[index: number]: T | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Iterator protocol support
|
|
79
|
+
*/
|
|
80
|
+
[Symbol.iterator](): Iterator<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a new array with the results of calling a provided function on every element
|
|
83
|
+
*/
|
|
84
|
+
map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new array with all elements that pass the test implemented by the provided function
|
|
87
|
+
*/
|
|
88
|
+
filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S[];
|
|
89
|
+
filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[];
|
|
90
|
+
/**
|
|
91
|
+
* Executes a reducer function on each element of the array, resulting in a single output value
|
|
92
|
+
*/
|
|
93
|
+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
|
|
94
|
+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
|
|
95
|
+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
|
|
96
|
+
/**
|
|
97
|
+
* Executes a reducer function on each element of the array (right-to-left), resulting in a single output value
|
|
98
|
+
*/
|
|
99
|
+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
|
|
100
|
+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
|
|
101
|
+
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
|
|
102
|
+
/**
|
|
103
|
+
* Executes a provided function once for each array element
|
|
104
|
+
*/
|
|
105
|
+
forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the value of the first element in the array that satisfies the provided testing function
|
|
108
|
+
*/
|
|
109
|
+
find<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S | undefined;
|
|
110
|
+
find(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Returns the index of the first element in the array that satisfies the provided testing function
|
|
113
|
+
*/
|
|
114
|
+
findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): number;
|
|
115
|
+
/**
|
|
116
|
+
* Returns the value of the last element in the array that satisfies the provided testing function
|
|
117
|
+
*/
|
|
118
|
+
findLast<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S | undefined;
|
|
119
|
+
findLast(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the index of the last element in the array that satisfies the provided testing function
|
|
122
|
+
*/
|
|
123
|
+
findLastIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): number;
|
|
124
|
+
/**
|
|
125
|
+
* Determines whether an array includes a certain value among its entries
|
|
126
|
+
*/
|
|
127
|
+
includes(searchElement: T, fromIndex?: number): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Returns the first index at which a given element can be found in the array
|
|
130
|
+
*/
|
|
131
|
+
indexOf(searchElement: T, fromIndex?: number): number;
|
|
132
|
+
/**
|
|
133
|
+
* Returns the last index at which a given element can be found in the array
|
|
134
|
+
*/
|
|
135
|
+
lastIndexOf(searchElement: T, fromIndex?: number): number;
|
|
136
|
+
/**
|
|
137
|
+
* Returns a shallow copy of a portion of an array into a new array object
|
|
138
|
+
*/
|
|
139
|
+
slice(start?: number, end?: number): T[];
|
|
140
|
+
/**
|
|
141
|
+
* Returns a new array comprised of this array joined with other array(s) and/or value(s)
|
|
142
|
+
*/
|
|
143
|
+
concat(...items: ConcatArray<T>[]): T[];
|
|
144
|
+
concat(...items: (T | ConcatArray<T>)[]): T[];
|
|
145
|
+
/**
|
|
146
|
+
* Tests whether all elements in the array pass the test implemented by the provided function
|
|
147
|
+
*/
|
|
148
|
+
every(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Tests whether at least one element in the array passes the test implemented by the provided function
|
|
151
|
+
*/
|
|
152
|
+
some(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Joins all elements of an array into a string
|
|
155
|
+
*/
|
|
156
|
+
join(separator?: string): string;
|
|
157
|
+
/**
|
|
158
|
+
* Returns a new array iterator that contains the keys for each index in the array
|
|
159
|
+
*/
|
|
160
|
+
keys(): IterableIterator<number>;
|
|
161
|
+
/**
|
|
162
|
+
* Returns a new array iterator that contains the values for each index in the array
|
|
163
|
+
*/
|
|
164
|
+
values(): IterableIterator<T>;
|
|
165
|
+
/**
|
|
166
|
+
* Returns a new array iterator that contains the key/value pairs for each index in the array
|
|
167
|
+
*/
|
|
168
|
+
entries(): IterableIterator<[number, T]>;
|
|
169
|
+
/**
|
|
170
|
+
* Returns a string representation of the array
|
|
171
|
+
*/
|
|
172
|
+
toString(): string;
|
|
173
|
+
/**
|
|
174
|
+
* Returns a localized string representing the array
|
|
175
|
+
*/
|
|
176
|
+
toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions): string;
|
|
177
|
+
/**
|
|
178
|
+
* Returns the element at the specified index, or undefined if the index is out of bounds
|
|
179
|
+
*/
|
|
180
|
+
at(index: number): T | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
|
|
183
|
+
*/
|
|
184
|
+
flat(depth?: number): T[];
|
|
185
|
+
/**
|
|
186
|
+
* Returns a new array formed by applying a given callback function to each element of the array,
|
|
187
|
+
* and then flattening the result by one level
|
|
188
|
+
*/
|
|
189
|
+
flatMap<U, This = undefined>(callback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>, thisArg?: This): U[];
|
|
190
|
+
/**
|
|
191
|
+
* Returns a new array with elements in reversed order (ES2023)
|
|
192
|
+
*/
|
|
193
|
+
toReversed(): T[];
|
|
194
|
+
/**
|
|
195
|
+
* Returns a new array with elements sorted (ES2023)
|
|
196
|
+
*/
|
|
197
|
+
toSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[];
|
|
198
|
+
/**
|
|
199
|
+
* Returns a new array with some elements removed and/or replaced at a given index (ES2023)
|
|
200
|
+
*/
|
|
201
|
+
toSpliced(start: number, deleteCount?: number, ...items: T[]): T[];
|
|
202
|
+
/**
|
|
203
|
+
* Returns a new array with the element at the given index replaced with the given value (ES2023)
|
|
204
|
+
*/
|
|
205
|
+
with(index: number, value: T): T[];
|
|
206
|
+
get [Symbol.unscopables](): {
|
|
207
|
+
readonly [x: number]: boolean;
|
|
208
|
+
readonly length?: boolean;
|
|
209
|
+
toString?: boolean;
|
|
210
|
+
toLocaleString?: boolean;
|
|
211
|
+
concat?: boolean;
|
|
212
|
+
join?: boolean;
|
|
213
|
+
slice?: boolean;
|
|
214
|
+
indexOf?: boolean;
|
|
215
|
+
lastIndexOf?: boolean;
|
|
216
|
+
every?: boolean;
|
|
217
|
+
some?: boolean;
|
|
218
|
+
forEach?: boolean;
|
|
219
|
+
map?: boolean;
|
|
220
|
+
filter?: boolean;
|
|
221
|
+
reduce?: boolean;
|
|
222
|
+
reduceRight?: boolean;
|
|
223
|
+
find?: boolean;
|
|
224
|
+
findIndex?: boolean;
|
|
225
|
+
entries?: boolean;
|
|
226
|
+
keys?: boolean;
|
|
227
|
+
values?: boolean;
|
|
228
|
+
includes?: boolean;
|
|
229
|
+
flatMap?: boolean;
|
|
230
|
+
flat?: boolean;
|
|
231
|
+
at?: boolean;
|
|
232
|
+
findLast?: boolean;
|
|
233
|
+
findLastIndex?: boolean;
|
|
234
|
+
toReversed?: boolean;
|
|
235
|
+
toSorted?: boolean;
|
|
236
|
+
toSpliced?: boolean;
|
|
237
|
+
with?: boolean;
|
|
238
|
+
[Symbol.iterator]?: boolean;
|
|
239
|
+
readonly [Symbol.unscopables]?: boolean;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
56
242
|
|
|
57
|
-
export { Indexable, getAt, setAt };
|
|
243
|
+
export { ArrayReadForward, Indexable, forwardArray, getAt, setAt };
|
package/dist/indexable.esm.js
CHANGED
|
@@ -68,9 +68,8 @@ function Indexable(base, accessor) {
|
|
|
68
68
|
}
|
|
69
69
|
const numProp = Number(prop);
|
|
70
70
|
if (!Number.isNaN(numProp)) {
|
|
71
|
-
if (!accessor.set)
|
|
71
|
+
if (!accessor.set)
|
|
72
72
|
throw new Error('Indexable class has read-only numeric index access');
|
|
73
|
-
}
|
|
74
73
|
accessor.set.call(receiver, numProp, value);
|
|
75
74
|
return true;
|
|
76
75
|
}
|
|
@@ -86,6 +85,201 @@ function Indexable(base, accessor) {
|
|
|
86
85
|
}));
|
|
87
86
|
return Indexable;
|
|
88
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
|
+
}
|
|
89
283
|
|
|
90
|
-
export { Indexable, getAt, setAt };
|
|
284
|
+
export { ArrayReadForward, Indexable, forwardArray, getAt, setAt };
|
|
91
285
|
//# sourceMappingURL=indexable.esm.js.map
|