mutts 1.0.6 → 1.0.8

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.
Files changed (196) hide show
  1. package/README.md +61 -23
  2. package/dist/async/browser.d.ts +2 -0
  3. package/dist/async/browser.d.ts.map +1 -0
  4. package/dist/async/index.d.ts +18 -0
  5. package/dist/async/index.d.ts.map +1 -0
  6. package/dist/async/node.d.ts +2 -0
  7. package/dist/async/node.d.ts.map +1 -0
  8. package/dist/{chunks/index-CDCOjzTy.js → browser.cjs} +5913 -4382
  9. package/dist/browser.cjs.map +1 -0
  10. package/dist/browser.d.ts +1655 -0
  11. package/dist/browser.esm.js +305 -0
  12. package/dist/browser.esm.js.map +1 -0
  13. package/dist/chunks/async-browser-CA0jPWIi.cjs +304 -0
  14. package/dist/chunks/async-browser-CA0jPWIi.cjs.map +1 -0
  15. package/dist/chunks/async-core-UqHzvJ-S.cjs +25 -0
  16. package/dist/chunks/async-core-UqHzvJ-S.cjs.map +1 -0
  17. package/dist/chunks/async-node-BYHuGTni.cjs +103 -0
  18. package/dist/chunks/async-node-BYHuGTni.cjs.map +1 -0
  19. package/dist/chunks/{index-DiP0RXoZ.esm.js → index-DhaOVusv.esm.js} +5851 -4345
  20. package/dist/chunks/index-DhaOVusv.esm.js.map +1 -0
  21. package/dist/decorator.d.ts +17 -18
  22. package/dist/decorator.d.ts.map +1 -0
  23. package/dist/destroyable.d.ts +12 -15
  24. package/dist/destroyable.d.ts.map +1 -0
  25. package/dist/devtools/devtool/devtools.d.ts +1 -0
  26. package/dist/devtools/devtool/devtools.d.ts.map +1 -0
  27. package/dist/devtools/devtool/panel.d.ts +2 -0
  28. package/dist/devtools/devtool/panel.d.ts.map +1 -0
  29. package/dist/devtools/panel.js.map +1 -1
  30. package/dist/entry-browser.d.ts +3 -0
  31. package/dist/entry-browser.d.ts.map +1 -0
  32. package/dist/entry-node.d.ts +3 -0
  33. package/dist/entry-node.d.ts.map +1 -0
  34. package/dist/eventful.d.ts +3 -5
  35. package/dist/eventful.d.ts.map +1 -0
  36. package/dist/index.d.ts +13 -19
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/indexable.d.ts +10 -10
  39. package/dist/indexable.d.ts.map +1 -0
  40. package/dist/introspection.d.ts +27 -0
  41. package/dist/introspection.d.ts.map +1 -0
  42. package/dist/iterableWeak.d.ts +53 -0
  43. package/dist/iterableWeak.d.ts.map +1 -0
  44. package/dist/mixins.d.ts +25 -0
  45. package/dist/mixins.d.ts.map +1 -0
  46. package/dist/mutts.umd.js +1 -1
  47. package/dist/mutts.umd.js.map +1 -1
  48. package/dist/mutts.umd.min.js +1 -1
  49. package/dist/mutts.umd.min.js.map +1 -1
  50. package/dist/node.cjs +105 -0
  51. package/dist/node.cjs.map +1 -0
  52. package/dist/node.d.ts +1 -0
  53. package/dist/node.esm.js +104 -0
  54. package/dist/node.esm.js.map +1 -0
  55. package/dist/promiseChain.d.ts +4 -5
  56. package/dist/promiseChain.d.ts.map +1 -0
  57. package/dist/reactive/array.d.ts +49 -0
  58. package/dist/reactive/array.d.ts.map +1 -0
  59. package/dist/reactive/buffer.d.ts +44 -0
  60. package/dist/reactive/buffer.d.ts.map +1 -0
  61. package/dist/reactive/change.d.ts +29 -0
  62. package/dist/reactive/change.d.ts.map +1 -0
  63. package/dist/reactive/debug.d.ts +111 -0
  64. package/dist/reactive/debug.d.ts.map +1 -0
  65. package/dist/reactive/deep-touch.d.ts +28 -0
  66. package/dist/reactive/deep-touch.d.ts.map +1 -0
  67. package/dist/reactive/deep-watch-state.d.ts +25 -0
  68. package/dist/reactive/deep-watch-state.d.ts.map +1 -0
  69. package/dist/reactive/deep-watch.d.ts +19 -0
  70. package/dist/reactive/deep-watch.d.ts.map +1 -0
  71. package/dist/reactive/effect-context.d.ts +7 -0
  72. package/dist/reactive/effect-context.d.ts.map +1 -0
  73. package/dist/reactive/effects.d.ts +151 -0
  74. package/dist/reactive/effects.d.ts.map +1 -0
  75. package/dist/reactive/index.d.ts +20 -0
  76. package/dist/reactive/index.d.ts.map +1 -0
  77. package/dist/reactive/interface.d.ts +64 -0
  78. package/dist/reactive/interface.d.ts.map +1 -0
  79. package/dist/reactive/map.d.ts +30 -0
  80. package/dist/reactive/map.d.ts.map +1 -0
  81. package/dist/reactive/memoize.d.ts +5 -0
  82. package/dist/reactive/memoize.d.ts.map +1 -0
  83. package/dist/reactive/non-reactive-state.d.ts +9 -0
  84. package/dist/reactive/non-reactive-state.d.ts.map +1 -0
  85. package/dist/reactive/non-reactive.d.ts +11 -0
  86. package/dist/reactive/non-reactive.d.ts.map +1 -0
  87. package/dist/reactive/project.d.ts +41 -0
  88. package/dist/reactive/project.d.ts.map +1 -0
  89. package/dist/reactive/proxy-state.d.ts +8 -0
  90. package/dist/reactive/proxy-state.d.ts.map +1 -0
  91. package/dist/reactive/proxy.d.ts +23 -0
  92. package/dist/reactive/proxy.d.ts.map +1 -0
  93. package/dist/reactive/record.d.ts +116 -0
  94. package/dist/reactive/record.d.ts.map +1 -0
  95. package/dist/reactive/register.d.ts +64 -0
  96. package/dist/reactive/register.d.ts.map +1 -0
  97. package/dist/reactive/registry.d.ts +20 -0
  98. package/dist/reactive/registry.d.ts.map +1 -0
  99. package/dist/reactive/set.d.ts +28 -0
  100. package/dist/reactive/set.d.ts.map +1 -0
  101. package/dist/reactive/tracking.d.ts +7 -0
  102. package/dist/reactive/tracking.d.ts.map +1 -0
  103. package/dist/reactive/types.d.ts +376 -0
  104. package/dist/reactive/types.d.ts.map +1 -0
  105. package/dist/std-decorators.d.ts +9 -11
  106. package/dist/std-decorators.d.ts.map +1 -0
  107. package/dist/utils.d.ts +49 -0
  108. package/dist/utils.d.ts.map +1 -0
  109. package/dist/zone.d.ts +40 -0
  110. package/dist/zone.d.ts.map +1 -0
  111. package/docs/ai/api-reference.md +0 -2
  112. package/docs/reactive/advanced.md +2 -5
  113. package/docs/reactive/collections.md +0 -125
  114. package/docs/reactive/core.md +27 -24
  115. package/docs/reactive/debugging.md +12 -2
  116. package/docs/reactive/project.md +1 -1
  117. package/docs/reactive/scan.md +78 -0
  118. package/docs/reactive.md +2 -1
  119. package/docs/std-decorators.md +69 -0
  120. package/docs/zone.md +95 -0
  121. package/package.json +67 -23
  122. package/src/async/browser.ts +319 -0
  123. package/src/async/index.ts +23 -0
  124. package/src/async/node.ts +104 -0
  125. package/src/decorator.ts +5 -1
  126. package/src/destroyable.ts +1 -1
  127. package/src/entry-browser.ts +5 -0
  128. package/src/entry-node.ts +5 -0
  129. package/src/index.d.ts +12 -9
  130. package/src/index.ts +23 -14
  131. package/src/indexable.ts +42 -0
  132. package/src/mixins.ts +2 -2
  133. package/src/reactive/array.ts +274 -179
  134. package/src/reactive/buffer.ts +168 -0
  135. package/src/reactive/change.ts +2 -2
  136. package/src/reactive/effect-context.ts +15 -91
  137. package/src/reactive/effects.ts +119 -179
  138. package/src/reactive/index.ts +11 -13
  139. package/src/reactive/interface.ts +19 -33
  140. package/src/reactive/map.ts +49 -62
  141. package/src/reactive/memoize.ts +19 -9
  142. package/src/reactive/project.ts +43 -22
  143. package/src/reactive/proxy.ts +16 -41
  144. package/src/reactive/record.ts +3 -3
  145. package/src/reactive/register.ts +5 -7
  146. package/src/reactive/registry.ts +9 -17
  147. package/src/reactive/set.ts +43 -57
  148. package/src/reactive/tracking.ts +1 -29
  149. package/src/reactive/types.ts +46 -23
  150. package/src/utils.ts +80 -37
  151. package/src/zone.ts +138 -0
  152. package/dist/chunks/_tslib-BgjropY9.js +0 -81
  153. package/dist/chunks/_tslib-BgjropY9.js.map +0 -1
  154. package/dist/chunks/_tslib-MCKDzsSq.esm.js +0 -75
  155. package/dist/chunks/_tslib-MCKDzsSq.esm.js.map +0 -1
  156. package/dist/chunks/decorator-BGILvPtN.esm.js +0 -627
  157. package/dist/chunks/decorator-BGILvPtN.esm.js.map +0 -1
  158. package/dist/chunks/decorator-BQ2eBTCj.js +0 -651
  159. package/dist/chunks/decorator-BQ2eBTCj.js.map +0 -1
  160. package/dist/chunks/index-CDCOjzTy.js.map +0 -1
  161. package/dist/chunks/index-DiP0RXoZ.esm.js.map +0 -1
  162. package/dist/decorator.esm.js +0 -2
  163. package/dist/decorator.esm.js.map +0 -1
  164. package/dist/decorator.js +0 -11
  165. package/dist/decorator.js.map +0 -1
  166. package/dist/destroyable.esm.js +0 -109
  167. package/dist/destroyable.esm.js.map +0 -1
  168. package/dist/destroyable.js +0 -116
  169. package/dist/destroyable.js.map +0 -1
  170. package/dist/eventful.esm.js +0 -66
  171. package/dist/eventful.esm.js.map +0 -1
  172. package/dist/eventful.js +0 -68
  173. package/dist/eventful.js.map +0 -1
  174. package/dist/index.esm.js +0 -53
  175. package/dist/index.esm.js.map +0 -1
  176. package/dist/index.js +0 -139
  177. package/dist/index.js.map +0 -1
  178. package/dist/indexable.esm.js +0 -285
  179. package/dist/indexable.esm.js.map +0 -1
  180. package/dist/indexable.js +0 -291
  181. package/dist/indexable.js.map +0 -1
  182. package/dist/promiseChain.esm.js +0 -78
  183. package/dist/promiseChain.esm.js.map +0 -1
  184. package/dist/promiseChain.js +0 -80
  185. package/dist/promiseChain.js.map +0 -1
  186. package/dist/reactive.d.ts +0 -910
  187. package/dist/reactive.esm.js +0 -5
  188. package/dist/reactive.esm.js.map +0 -1
  189. package/dist/reactive.js +0 -59
  190. package/dist/reactive.js.map +0 -1
  191. package/dist/std-decorators.esm.js +0 -196
  192. package/dist/std-decorators.esm.js.map +0 -1
  193. package/dist/std-decorators.js +0 -204
  194. package/dist/std-decorators.js.map +0 -1
  195. package/src/reactive/mapped.ts +0 -129
  196. package/src/reactive/zone.ts +0 -208
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export * from './decorator'\nexport * from './destroyable'\nexport * from './eventful'\nexport * from './indexable'\nexport * from './iterableWeak'\nexport * from './mixins'\nexport * from './reactive'\nexport * from './std-decorators'\nexport * from './utils'\n\nimport pkg from '../package.json'\nconst { version } = pkg\n\n// Singleton verification\nconst GLOBAL_MUTTS_KEY = '__MUTTS_INSTANCE__'\nconst globalScope = \n\t(typeof globalThis !== 'undefined' ? globalThis : \n\t(typeof window !== 'undefined' ? window : \n\t(typeof global !== 'undefined' ? global : false))) as any\nif(globalScope) {\n\t// Detect the source of this instance safely across different environments\n\tlet source = 'mutts/index'\n\ttry {\n\t\t// @ts-ignore\n\t\tif (typeof __filename !== 'undefined') source = __filename\n\t\t// @ts-ignore\n\t\telse {\n\t\t\t// Using eval to avoid SyntaxError in CJS environments where import.meta is not allowed\n\t\t\tconst meta = eval('import.meta')\n\t\t\tif (meta && meta.url) source = meta.url\n\t\t}\n\t} catch (e) {\n\t\t// Fallback for environments where neither is available or accessible\n\t}\n\n\tconst currentSourceInfo = {\n\t\tversion,\n\t\tsource,\n\t\ttimestamp: Date.now()\n\t}\n\n\tif (globalScope[GLOBAL_MUTTS_KEY]) {\n\t\tconst existing = globalScope[GLOBAL_MUTTS_KEY]\n\t\tthrow new Error(\n\t\t\t`[Mutts] Multiple instances detected!\\n` + \n\t\t\t`Existing instance: ${JSON.stringify(existing, null, 2)}\\n` +\n\t\t\t`New instance: ${JSON.stringify(currentSourceInfo, null, 2)}\\n` +\n\t\t\t`This usually happens when 'mutts' is both installed as a dependency and bundled, ` +\n\t\t\t`or when different versions are loaded. ` +\n\t\t\t`Please check your build configuration (aliases, externals) to ensure a single source of truth.`\n\t\t)\n\t}\n\n\tglobalScope[GLOBAL_MUTTS_KEY] = currentSourceInfo\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAWA,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG;AAEvB;AACA,MAAM,gBAAgB,GAAG,oBAAoB;AAC7C,MAAM,WAAW,IACf,OAAO,UAAU,KAAK,WAAW,GAAG,UAAU;KAC9C,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM;AACvC,SAAC,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,CAAQ;AAC1D,IAAG,WAAW,EAAE;;IAEf,IAAI,MAAM,GAAG,aAAa;AAC1B,IAAA,IAAI;;QAEH,IAAI,OAAO,UAAU,KAAK,WAAW;YAAE,MAAM,GAAG,UAAU;;aAErD;;AAEJ,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;AAChC,YAAA,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG;AAAE,gBAAA,MAAM,GAAG,IAAI,CAAC,GAAG;QACxC;IACD;IAAE,OAAO,CAAC,EAAE;;IAEZ;AAEA,IAAA,MAAM,iBAAiB,GAAG;QACzB,OAAO;QACP,MAAM;AACN,QAAA,SAAS,EAAE,IAAI,CAAC,GAAG;KACnB;AAED,IAAA,IAAI,WAAW,CAAC,gBAAgB,CAAC,EAAE;AAClC,QAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,gBAAgB,CAAC;QAC9C,MAAM,IAAI,KAAK,CACd,CAAA,sCAAA,CAAwC;YACxC,CAAA,mBAAA,EAAsB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA,EAAA,CAAI;YAC3D,CAAA,cAAA,EAAiB,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA,EAAA,CAAI;YAC/D,CAAA,iFAAA,CAAmF;YACnF,CAAA,uCAAA,CAAyC;AACzC,YAAA,CAAA,8FAAA,CAAgG,CAChG;IACF;AAEA,IAAA,WAAW,CAAC,gBAAgB,CAAC,GAAG,iBAAiB;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,285 +0,0 @@
1
- /**
2
- * Symbol for defining custom getter logic for numeric index access
3
- */
4
- const getAt = Symbol('getAt');
5
- /**
6
- * Symbol for defining custom setter logic for numeric index access
7
- */
8
- const setAt = Symbol('setAt');
9
- function Indexable(base, accessor) {
10
- if (base && typeof base !== 'function') {
11
- accessor = base;
12
- base = undefined;
13
- }
14
- if (!base) {
15
- //@ts-expect-error
16
- base = class {
17
- };
18
- }
19
- if (!accessor) {
20
- accessor = {
21
- get(index) {
22
- if (typeof this[getAt] !== 'function') {
23
- throw new Error('Indexable class must have an [getAt] method');
24
- }
25
- return this[getAt](index);
26
- },
27
- set(index, value) {
28
- if (typeof this[setAt] !== 'function') {
29
- throw new Error('Indexable class has read-only numeric index access');
30
- }
31
- this[setAt](index, value);
32
- },
33
- };
34
- }
35
- class Indexable extends base {
36
- }
37
- Object.setPrototypeOf(Indexable.prototype, new Proxy(base.prototype, {
38
- //@ts-expect-error
39
- [Symbol.toStringTag]: 'MutTs Indexable',
40
- get(target, prop, receiver) {
41
- if (prop in target) {
42
- const getter = Object.getOwnPropertyDescriptor(target, prop)?.get;
43
- return getter ? getter.call(receiver) : target[prop];
44
- }
45
- if (typeof prop === 'string') {
46
- if (prop === 'length' && accessor.getLength)
47
- return accessor.getLength.call(receiver);
48
- const numProp = Number(prop);
49
- if (!Number.isNaN(numProp)) {
50
- return accessor.get.call(receiver, numProp);
51
- }
52
- }
53
- return undefined;
54
- },
55
- set(target, prop, value, receiver) {
56
- if (prop in target) {
57
- const setter = Object.getOwnPropertyDescriptor(target, prop)?.set;
58
- if (setter)
59
- setter.call(receiver, value);
60
- else
61
- target[prop] = value;
62
- return true;
63
- }
64
- if (typeof prop === 'string') {
65
- if (prop === 'length' && accessor.setLength) {
66
- accessor.setLength.call(receiver, value);
67
- return true;
68
- }
69
- const numProp = Number(prop);
70
- if (!Number.isNaN(numProp)) {
71
- if (!accessor.set)
72
- throw new Error('Indexable class has read-only numeric index access');
73
- accessor.set.call(receiver, numProp, value);
74
- return true;
75
- }
76
- }
77
- Object.defineProperty(receiver, prop, {
78
- value,
79
- writable: true,
80
- enumerable: true,
81
- configurable: true,
82
- });
83
- return true;
84
- },
85
- }));
86
- return Indexable;
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
- }
283
-
284
- export { ArrayReadForward, Indexable, forwardArray, getAt, setAt };
285
- //# sourceMappingURL=indexable.esm.js.map
@@ -1 +0,0 @@
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,EAAA;AAEh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C,WAAW,CAAC,GAAA;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;IAC9C;AACA;;;;"}
package/dist/indexable.js DELETED
@@ -1,291 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Symbol for defining custom getter logic for numeric index access
5
- */
6
- const getAt = Symbol('getAt');
7
- /**
8
- * Symbol for defining custom setter logic for numeric index access
9
- */
10
- const setAt = Symbol('setAt');
11
- function Indexable(base, accessor) {
12
- if (base && typeof base !== 'function') {
13
- accessor = base;
14
- base = undefined;
15
- }
16
- if (!base) {
17
- //@ts-expect-error
18
- base = class {
19
- };
20
- }
21
- if (!accessor) {
22
- accessor = {
23
- get(index) {
24
- if (typeof this[getAt] !== 'function') {
25
- throw new Error('Indexable class must have an [getAt] method');
26
- }
27
- return this[getAt](index);
28
- },
29
- set(index, value) {
30
- if (typeof this[setAt] !== 'function') {
31
- throw new Error('Indexable class has read-only numeric index access');
32
- }
33
- this[setAt](index, value);
34
- },
35
- };
36
- }
37
- class Indexable extends base {
38
- }
39
- Object.setPrototypeOf(Indexable.prototype, new Proxy(base.prototype, {
40
- //@ts-expect-error
41
- [Symbol.toStringTag]: 'MutTs Indexable',
42
- get(target, prop, receiver) {
43
- if (prop in target) {
44
- const getter = Object.getOwnPropertyDescriptor(target, prop)?.get;
45
- return getter ? getter.call(receiver) : target[prop];
46
- }
47
- if (typeof prop === 'string') {
48
- if (prop === 'length' && accessor.getLength)
49
- return accessor.getLength.call(receiver);
50
- const numProp = Number(prop);
51
- if (!Number.isNaN(numProp)) {
52
- return accessor.get.call(receiver, numProp);
53
- }
54
- }
55
- return undefined;
56
- },
57
- set(target, prop, value, receiver) {
58
- if (prop in target) {
59
- const setter = Object.getOwnPropertyDescriptor(target, prop)?.set;
60
- if (setter)
61
- setter.call(receiver, value);
62
- else
63
- target[prop] = value;
64
- return true;
65
- }
66
- if (typeof prop === 'string') {
67
- if (prop === 'length' && accessor.setLength) {
68
- accessor.setLength.call(receiver, value);
69
- return true;
70
- }
71
- const numProp = Number(prop);
72
- if (!Number.isNaN(numProp)) {
73
- if (!accessor.set)
74
- throw new Error('Indexable class has read-only numeric index access');
75
- accessor.set.call(receiver, numProp, value);
76
- return true;
77
- }
78
- }
79
- Object.defineProperty(receiver, prop, {
80
- value,
81
- writable: true,
82
- enumerable: true,
83
- configurable: true,
84
- });
85
- return true;
86
- },
87
- }));
88
- return Indexable;
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
- }
285
-
286
- exports.ArrayReadForward = ArrayReadForward;
287
- exports.Indexable = Indexable;
288
- exports.forwardArray = forwardArray;
289
- exports.getAt = getAt;
290
- exports.setAt = setAt;
291
- //# sourceMappingURL=indexable.js.map