@rimbu/base 2.0.2 → 2.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 +161 -6
- package/dist/bun/arr.mts +184 -19
- package/dist/bun/entry.mts +14 -2
- package/dist/bun/index.mts +10 -0
- package/dist/bun/rimbu-error.mts +25 -0
- package/dist/bun/token.mts +7 -0
- package/dist/cjs/arr.cjs +184 -19
- package/dist/cjs/arr.cjs.map +1 -1
- package/dist/cjs/arr.d.cts +184 -0
- package/dist/cjs/entry.cjs +14 -2
- package/dist/cjs/entry.cjs.map +1 -1
- package/dist/cjs/entry.d.cts +14 -0
- package/dist/cjs/index.cjs +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +9 -0
- package/dist/cjs/rimbu-error.cjs +25 -0
- package/dist/cjs/rimbu-error.cjs.map +1 -1
- package/dist/cjs/rimbu-error.d.cts +25 -0
- package/dist/cjs/token.cjs +4 -0
- package/dist/cjs/token.cjs.map +1 -1
- package/dist/cjs/token.d.cts +7 -0
- package/dist/esm/arr.d.mts +184 -0
- package/dist/esm/arr.mjs +184 -19
- package/dist/esm/arr.mjs.map +1 -1
- package/dist/esm/entry.d.mts +14 -0
- package/dist/esm/entry.mjs +14 -2
- package/dist/esm/entry.mjs.map +1 -1
- package/dist/esm/index.d.mts +9 -0
- package/dist/esm/index.mjs +10 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/rimbu-error.d.mts +25 -0
- package/dist/esm/rimbu-error.mjs +25 -0
- package/dist/esm/rimbu-error.mjs.map +1 -1
- package/dist/esm/token.d.mts +7 -0
- package/dist/esm/token.mjs +4 -0
- package/dist/esm/token.mjs.map +1 -1
- package/package.json +3 -3
- package/src/arr.mts +184 -19
- package/src/entry.mts +14 -2
- package/src/index.mts +10 -0
- package/src/rimbu-error.mts +25 -0
- package/src/token.mts +7 -0
package/dist/cjs/arr.cjs
CHANGED
|
@@ -27,17 +27,46 @@ exports.copySparse = copySparse;
|
|
|
27
27
|
exports.mapSparse = mapSparse;
|
|
28
28
|
var tslib_1 = require("tslib");
|
|
29
29
|
var common_1 = require("@rimbu/common");
|
|
30
|
+
/**
|
|
31
|
+
* Internal helper that appends a value using the modern immutable `toSpliced` API.
|
|
32
|
+
* @internal
|
|
33
|
+
* @typeparam T - the array element type
|
|
34
|
+
* @param array - the source array (not mutated)
|
|
35
|
+
* @param value - the value to append
|
|
36
|
+
* @returns a new non-empty array with the value at the end
|
|
37
|
+
*/
|
|
30
38
|
function _appendNew(array, value) {
|
|
31
39
|
return array.toSpliced(array.length, 0, value);
|
|
32
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Internal helper that appends a value by cloning and pushing (legacy fallback).
|
|
43
|
+
* @internal
|
|
44
|
+
* @typeparam T - the array element type
|
|
45
|
+
* @param array - the source array (not mutated)
|
|
46
|
+
* @param value - the value to append
|
|
47
|
+
* @returns a new non-empty array with the value at the end
|
|
48
|
+
*/
|
|
33
49
|
function _appendOld(array, value) {
|
|
34
50
|
var clone = array.slice();
|
|
35
51
|
clone.push(value);
|
|
36
52
|
return clone;
|
|
37
53
|
}
|
|
38
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Returns a copy of the array with the given value appended.
|
|
56
|
+
* Chooses an implementation depending on environment capabilities.
|
|
57
|
+
* @typeparam T - the array element type
|
|
58
|
+
* @param array - the source array (not mutated)
|
|
59
|
+
* @param value - the value to append
|
|
60
|
+
* @returns a new array with the value at the end
|
|
61
|
+
*/
|
|
39
62
|
exports.append = "toSpliced" in Array.prototype ? _appendNew : _appendOld;
|
|
40
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Returns the concatenation of two arrays, reusing an input array when the other is empty.
|
|
65
|
+
* @typeparam T - the array element type
|
|
66
|
+
* @param first - the first array
|
|
67
|
+
* @param second - the second array
|
|
68
|
+
* @returns a new array containing all elements of both arrays (or one of the originals if the other is empty)
|
|
69
|
+
*/
|
|
41
70
|
function concat(first, second) {
|
|
42
71
|
if (first.length === 0)
|
|
43
72
|
return second;
|
|
@@ -45,12 +74,20 @@ function concat(first, second) {
|
|
|
45
74
|
return first;
|
|
46
75
|
return first.concat(second);
|
|
47
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Internal helper to create a reversed copy using modern `toReversed` with optional slicing.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
48
81
|
function _reverseNew(array, start, end) {
|
|
49
82
|
var source = undefined !== start || undefined !== end
|
|
50
83
|
? array.slice(start !== null && start !== void 0 ? start : 0, (end !== null && end !== void 0 ? end : array.length - 1) + 1)
|
|
51
84
|
: array;
|
|
52
85
|
return source.toReversed();
|
|
53
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Internal helper to create a reversed copy using manual iteration (legacy fallback).
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
54
91
|
function _reverseOld(array, start, end) {
|
|
55
92
|
var _start = start !== null && start !== void 0 ? start : 0;
|
|
56
93
|
var _end = end !== null && end !== void 0 ? end : array.length - 1;
|
|
@@ -62,9 +99,23 @@ function _reverseOld(array, start, end) {
|
|
|
62
99
|
res[resIndex--] = array[arrayIndex];
|
|
63
100
|
return res;
|
|
64
101
|
}
|
|
65
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Returns a copy of the array (or a slice) with elements in reversed order.
|
|
104
|
+
* @typeparam T - array element type
|
|
105
|
+
* @param array - the source array
|
|
106
|
+
* @param start - optional start index (inclusive)
|
|
107
|
+
* @param end - optional end index (inclusive)
|
|
108
|
+
*/
|
|
66
109
|
exports.reverse = 'toReversed' in Array.prototype ? _reverseNew : _reverseOld;
|
|
67
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Performs the given function for each element of the array, optionally in reverse order.
|
|
112
|
+
* Halting is supported through the provided `TraverseState`.
|
|
113
|
+
* @typeparam T - element type
|
|
114
|
+
* @param array - the source array
|
|
115
|
+
* @param f - callback receiving (value, sequential index, halt)
|
|
116
|
+
* @param state - traversal state (created if omitted)
|
|
117
|
+
* @param reversed - whether to traverse in reverse order
|
|
118
|
+
*/
|
|
68
119
|
function forEach(array, f, state, reversed) {
|
|
69
120
|
if (state === void 0) { state = (0, common_1.TraverseState)(); }
|
|
70
121
|
if (reversed === void 0) { reversed = false; }
|
|
@@ -85,7 +136,15 @@ function forEach(array, f, state, reversed) {
|
|
|
85
136
|
}
|
|
86
137
|
}
|
|
87
138
|
}
|
|
88
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Returns a copy of the array where the given function is applied to each element.
|
|
141
|
+
* Supports an index offset useful for composed traversals.
|
|
142
|
+
* @typeparam T - source element type
|
|
143
|
+
* @typeparam R - result element type
|
|
144
|
+
* @param array - the source array
|
|
145
|
+
* @param f - the mapping function
|
|
146
|
+
* @param indexOffset - optional start index value passed to `f`
|
|
147
|
+
*/
|
|
89
148
|
function map(array, f, indexOffset) {
|
|
90
149
|
if (indexOffset === void 0) { indexOffset = 0; }
|
|
91
150
|
if (indexOffset === 0) {
|
|
@@ -101,7 +160,14 @@ function map(array, f, indexOffset) {
|
|
|
101
160
|
}
|
|
102
161
|
return result;
|
|
103
162
|
}
|
|
104
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Returns a copy of the array where the given function is applied to each element in reverse order.
|
|
165
|
+
* @typeparam T - source element type
|
|
166
|
+
* @typeparam R - result element type
|
|
167
|
+
* @param array - the source array
|
|
168
|
+
* @param f - the mapping function
|
|
169
|
+
* @param indexOffset - optional index offset passed to `f`
|
|
170
|
+
*/
|
|
105
171
|
function reverseMap(array, f, indexOffset) {
|
|
106
172
|
if (indexOffset === void 0) { indexOffset = 0; }
|
|
107
173
|
var result = [];
|
|
@@ -112,24 +178,53 @@ function reverseMap(array, f, indexOffset) {
|
|
|
112
178
|
result[resultIndex++] = f(array[arrayIndex], index++);
|
|
113
179
|
return result;
|
|
114
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Internal helper to prepend a value using `toSpliced`.
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
115
185
|
function _prependNew(array, value) {
|
|
116
186
|
return array.toSpliced(0, 0, value);
|
|
117
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Internal helper to prepend a value using legacy cloning.
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
118
192
|
function _prependOld(array, value) {
|
|
119
193
|
var clone = array.slice();
|
|
120
194
|
clone.unshift(value);
|
|
121
195
|
return clone;
|
|
122
196
|
}
|
|
123
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Returns a copy of the array with the given value inserted at the start.
|
|
199
|
+
* @typeparam T - element type
|
|
200
|
+
* @param array - the source array
|
|
201
|
+
* @param value - value to insert at index 0
|
|
202
|
+
*/
|
|
124
203
|
exports.prepend = "toSpliced" in Array.prototype ? _prependNew : _prependOld;
|
|
204
|
+
/**
|
|
205
|
+
* Internal helper to obtain the last element using modern `at`.
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
125
208
|
function _lastNew(arr) {
|
|
126
209
|
return arr.at(-1);
|
|
127
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Internal helper to obtain the last element using index arithmetic.
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
128
215
|
function _lastOld(arr) {
|
|
129
216
|
return arr[arr.length - 1];
|
|
130
217
|
}
|
|
131
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Returns the last element of the array.
|
|
220
|
+
* @typeparam T - element type
|
|
221
|
+
* @param arr - the array
|
|
222
|
+
*/
|
|
132
223
|
exports.last = "at" in Array.prototype ? _lastNew : _lastOld;
|
|
224
|
+
/**
|
|
225
|
+
* Internal helper implementing an immutable index update via `with`.
|
|
226
|
+
* @internal
|
|
227
|
+
*/
|
|
133
228
|
function _updateNew(arr, index, updater) {
|
|
134
229
|
if (index < 0 || index >= arr.length) {
|
|
135
230
|
return arr;
|
|
@@ -141,6 +236,10 @@ function _updateNew(arr, index, updater) {
|
|
|
141
236
|
}
|
|
142
237
|
return arr.with(index, newValue);
|
|
143
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Internal helper implementing an immutable index update via cloning.
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
144
243
|
function _updateOld(arr, index, updater) {
|
|
145
244
|
if (index < 0 || index >= arr.length) {
|
|
146
245
|
return arr;
|
|
@@ -154,9 +253,19 @@ function _updateOld(arr, index, updater) {
|
|
|
154
253
|
newArr[index] = newValue;
|
|
155
254
|
return newArr;
|
|
156
255
|
}
|
|
157
|
-
|
|
158
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Returns a copy of the array where the element at the given index is replaced using the provided updater.
|
|
258
|
+
* If the result value is identical (by `Object.is`) the original array is returned.
|
|
259
|
+
* @typeparam T - element type
|
|
260
|
+
* @param arr - the source array
|
|
261
|
+
* @param index - the index to update
|
|
262
|
+
* @param updater - value or function update description
|
|
263
|
+
*/
|
|
159
264
|
exports.update = "with" in Array.prototype ? _updateNew : _updateOld;
|
|
265
|
+
/**
|
|
266
|
+
* Internal helper applying a modifier function via `with`.
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
160
269
|
function _modNew(arr, index, f) {
|
|
161
270
|
if (index < 0 || index >= arr.length) {
|
|
162
271
|
return arr;
|
|
@@ -168,6 +277,10 @@ function _modNew(arr, index, f) {
|
|
|
168
277
|
}
|
|
169
278
|
return arr.with(index, newValue);
|
|
170
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Internal helper applying a modifier function via cloning.
|
|
282
|
+
* @internal
|
|
283
|
+
*/
|
|
171
284
|
function _modOld(arr, index, f) {
|
|
172
285
|
if (index < 0 || index >= arr.length) {
|
|
173
286
|
return arr;
|
|
@@ -181,27 +294,59 @@ function _modOld(arr, index, f) {
|
|
|
181
294
|
newArr[index] = newValue;
|
|
182
295
|
return newArr;
|
|
183
296
|
}
|
|
184
|
-
|
|
185
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Returns a copy of the array where the element at the given index is transformed by a modifier function.
|
|
299
|
+
* If the result value is identical (by `Object.is`) the original array is returned.
|
|
300
|
+
* @typeparam T - element type
|
|
301
|
+
* @param arr - the source array
|
|
302
|
+
* @param index - the index to modify
|
|
303
|
+
* @param f - modifier function receiving the current value
|
|
304
|
+
*/
|
|
186
305
|
exports.mod = "with" in Array.prototype ? _modNew : _modOld;
|
|
306
|
+
/**
|
|
307
|
+
* Internal helper for inserting a value using `toSpliced`.
|
|
308
|
+
* @internal
|
|
309
|
+
*/
|
|
187
310
|
function _insertNew(arr, index, value) {
|
|
188
311
|
return arr.toSpliced(index, 0, value);
|
|
189
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Internal helper for inserting a value using legacy `splice` on a clone.
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
190
317
|
function _insertOld(arr, index, value) {
|
|
191
318
|
var clone = arr.slice();
|
|
192
319
|
clone.splice(index, 0, value);
|
|
193
320
|
return clone;
|
|
194
321
|
}
|
|
195
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Returns a copy of the array where at the given index the provided value is inserted.
|
|
324
|
+
* @typeparam T - element type
|
|
325
|
+
* @param arr - the source array
|
|
326
|
+
* @param index - insertion index
|
|
327
|
+
* @param value - value to insert
|
|
328
|
+
*/
|
|
196
329
|
exports.insert = "toSpliced" in Array.prototype ? _insertNew : _insertOld;
|
|
197
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Returns a copy of the array without its first element.
|
|
332
|
+
* @typeparam T - element type
|
|
333
|
+
* @param arr - the source array
|
|
334
|
+
*/
|
|
198
335
|
function tail(arr) {
|
|
199
336
|
return arr.slice(1);
|
|
200
337
|
}
|
|
201
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Returns a copy of the array without its last element.
|
|
340
|
+
* @typeparam T - element type
|
|
341
|
+
* @param arr - the source array
|
|
342
|
+
*/
|
|
202
343
|
function init(arr) {
|
|
203
344
|
return arr.slice(0, arr.length - 1);
|
|
204
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Internal helper providing an immutable `splice` using `toSpliced`.
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
205
350
|
function _spliceNew(arr, start, deleteCount) {
|
|
206
351
|
var items = [];
|
|
207
352
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
@@ -209,6 +354,10 @@ function _spliceNew(arr, start, deleteCount) {
|
|
|
209
354
|
}
|
|
210
355
|
return arr.toSpliced.apply(arr, tslib_1.__spreadArray([start, deleteCount], tslib_1.__read(items), false));
|
|
211
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Internal helper providing an immutable `splice` via cloning.
|
|
359
|
+
* @internal
|
|
360
|
+
*/
|
|
212
361
|
function _spliceOld(arr, start, deleteCount) {
|
|
213
362
|
var items = [];
|
|
214
363
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
@@ -218,9 +367,20 @@ function _spliceOld(arr, start, deleteCount) {
|
|
|
218
367
|
clone.splice.apply(clone, tslib_1.__spreadArray([start, deleteCount], tslib_1.__read(items), false));
|
|
219
368
|
return clone;
|
|
220
369
|
}
|
|
221
|
-
|
|
370
|
+
/**
|
|
371
|
+
* Immutable version of the array `.splice` command, always returning a new array.
|
|
372
|
+
* @typeparam T - element type
|
|
373
|
+
* @param arr - the source array
|
|
374
|
+
* @param start - start index
|
|
375
|
+
* @param deleteCount - number of elements to delete
|
|
376
|
+
* @param items - optional items to insert
|
|
377
|
+
*/
|
|
222
378
|
exports.splice = "toSpliced" in Array.prototype ? _spliceNew : _spliceOld;
|
|
223
|
-
|
|
379
|
+
/**
|
|
380
|
+
* Returns a copy of a (potentially) sparse array preserving sparsity (skips holes).
|
|
381
|
+
* @typeparam T - element type
|
|
382
|
+
* @param arr - the source sparse array
|
|
383
|
+
*/
|
|
224
384
|
function copySparse(arr) {
|
|
225
385
|
var clone = [];
|
|
226
386
|
for (var key in arr) {
|
|
@@ -228,8 +388,13 @@ function copySparse(arr) {
|
|
|
228
388
|
}
|
|
229
389
|
return clone;
|
|
230
390
|
}
|
|
231
|
-
|
|
232
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Returns a copy of a sparse array applying the given function to each present element, preserving holes.
|
|
393
|
+
* @typeparam T - source element type
|
|
394
|
+
* @typeparam T2 - result element type
|
|
395
|
+
* @param arr - the source sparse array
|
|
396
|
+
* @param f - mapping function
|
|
397
|
+
*/
|
|
233
398
|
function mapSparse(arr, f) {
|
|
234
399
|
var result = Array(arr.length);
|
|
235
400
|
for (var key in arr) {
|
package/dist/cjs/arr.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arr.cjs","sourceRoot":"","sources":["../../_cjs_prepare/arr.cts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"arr.cjs","sourceRoot":"","sources":["../../_cjs_prepare/arr.cts"],"names":[],"mappings":";;;AAUA,gCAEC;AAUD,gCAIC;AAmBD,wBAOC;AAMD,kCAWC;AAMD,kCAgBC;AAqBD,0BAwBC;AAWD,kBAmBC;AAUD,gCAcC;AAMD,kCAKC;AAMD,kCAOC;AAeD,4BAEC;AAMD,4BAEC;AAaD,gCAgBC;AAMD,gCAkBC;AAgBD,0BAiBC;AAMD,0BAmBC;AAgBD,gCAEC;AAMD,gCAIC;AAgBD,oBAEC;AAOD,oBAEC;AAMD,gCAOC;AAMD,gCASC;AAiBD,gCAMC;AASD,8BAWC;;AA5dD,wCAA0E;AAE1E;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAI,KAAmB,EAAE,KAAQ;IACzD,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAqB,CAAC;AACrE,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAI,KAAmB,EAAE,KAAQ;IACzD,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,OAAO,KAAyB,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACU,QAAA,MAAM,GAAG,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
|
|
2
|
+
/**
|
|
3
|
+
* Internal helper that appends a value using the modern immutable `toSpliced` API.
|
|
4
|
+
* @internal
|
|
5
|
+
* @typeparam T - the array element type
|
|
6
|
+
* @param array - the source array (not mutated)
|
|
7
|
+
* @param value - the value to append
|
|
8
|
+
* @returns a new non-empty array with the value at the end
|
|
9
|
+
*/
|
|
2
10
|
export declare function _appendNew<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Internal helper that appends a value by cloning and pushing (legacy fallback).
|
|
13
|
+
* @internal
|
|
14
|
+
* @typeparam T - the array element type
|
|
15
|
+
* @param array - the source array (not mutated)
|
|
16
|
+
* @param value - the value to append
|
|
17
|
+
* @returns a new non-empty array with the value at the end
|
|
18
|
+
*/
|
|
3
19
|
export declare function _appendOld<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Returns a copy of the array with the given value appended.
|
|
22
|
+
* Chooses an implementation depending on environment capabilities.
|
|
23
|
+
* @typeparam T - the array element type
|
|
24
|
+
* @param array - the source array (not mutated)
|
|
25
|
+
* @param value - the value to append
|
|
26
|
+
* @returns a new array with the value at the end
|
|
27
|
+
*/
|
|
4
28
|
export declare const append: typeof _appendNew;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the concatenation of two arrays, reusing an input array when the other is empty.
|
|
31
|
+
* @typeparam T - the array element type
|
|
32
|
+
* @param first - the first array
|
|
33
|
+
* @param second - the second array
|
|
34
|
+
* @returns a new array containing all elements of both arrays (or one of the originals if the other is empty)
|
|
35
|
+
*/
|
|
5
36
|
export declare function concat<T>(first: readonly T[], second: readonly T[]): readonly T[];
|
|
37
|
+
/**
|
|
38
|
+
* Internal helper to create a reversed copy using modern `toReversed` with optional slicing.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
6
41
|
export declare function _reverseNew<T>(array: readonly T[], start?: number, end?: number): T[];
|
|
42
|
+
/**
|
|
43
|
+
* Internal helper to create a reversed copy using manual iteration (legacy fallback).
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
7
46
|
export declare function _reverseOld<T>(array: readonly T[], start?: number, end?: number): T[];
|
|
47
|
+
/**
|
|
48
|
+
* Returns a copy of the array (or a slice) with elements in reversed order.
|
|
49
|
+
* @typeparam T - array element type
|
|
50
|
+
* @param array - the source array
|
|
51
|
+
* @param start - optional start index (inclusive)
|
|
52
|
+
* @param end - optional end index (inclusive)
|
|
53
|
+
*/
|
|
8
54
|
export declare const reverse: typeof _reverseNew;
|
|
55
|
+
/**
|
|
56
|
+
* Performs the given function for each element of the array, optionally in reverse order.
|
|
57
|
+
* Halting is supported through the provided `TraverseState`.
|
|
58
|
+
* @typeparam T - element type
|
|
59
|
+
* @param array - the source array
|
|
60
|
+
* @param f - callback receiving (value, sequential index, halt)
|
|
61
|
+
* @param state - traversal state (created if omitted)
|
|
62
|
+
* @param reversed - whether to traverse in reverse order
|
|
63
|
+
*/
|
|
9
64
|
export declare function forEach<T>(array: readonly T[], f: (value: T, index: number, halt: () => void) => void, state?: TraverseState, reversed?: boolean): void;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a copy of the array where the given function is applied to each element.
|
|
67
|
+
* Supports an index offset useful for composed traversals.
|
|
68
|
+
* @typeparam T - source element type
|
|
69
|
+
* @typeparam R - result element type
|
|
70
|
+
* @param array - the source array
|
|
71
|
+
* @param f - the mapping function
|
|
72
|
+
* @param indexOffset - optional start index value passed to `f`
|
|
73
|
+
*/
|
|
10
74
|
export declare function map<T, R>(array: readonly T[], f: (value: T, index: number) => R, indexOffset?: number): R[];
|
|
75
|
+
/**
|
|
76
|
+
* Returns a copy of the array where the given function is applied to each element in reverse order.
|
|
77
|
+
* @typeparam T - source element type
|
|
78
|
+
* @typeparam R - result element type
|
|
79
|
+
* @param array - the source array
|
|
80
|
+
* @param f - the mapping function
|
|
81
|
+
* @param indexOffset - optional index offset passed to `f`
|
|
82
|
+
*/
|
|
11
83
|
export declare function reverseMap<T, R>(array: readonly T[], f: (value: T, index: number) => R, indexOffset?: number): R[];
|
|
84
|
+
/**
|
|
85
|
+
* Internal helper to prepend a value using `toSpliced`.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
12
88
|
export declare function _prependNew<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Internal helper to prepend a value using legacy cloning.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
13
93
|
export declare function _prependOld<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a copy of the array with the given value inserted at the start.
|
|
96
|
+
* @typeparam T - element type
|
|
97
|
+
* @param array - the source array
|
|
98
|
+
* @param value - value to insert at index 0
|
|
99
|
+
*/
|
|
14
100
|
export declare const prepend: typeof _prependNew;
|
|
101
|
+
/**
|
|
102
|
+
* Internal helper to obtain the last element using modern `at`.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
15
105
|
export declare function _lastNew<T>(arr: readonly T[]): T;
|
|
106
|
+
/**
|
|
107
|
+
* Internal helper to obtain the last element using index arithmetic.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
16
110
|
export declare function _lastOld<T>(arr: readonly T[]): T;
|
|
111
|
+
/**
|
|
112
|
+
* Returns the last element of the array.
|
|
113
|
+
* @typeparam T - element type
|
|
114
|
+
* @param arr - the array
|
|
115
|
+
*/
|
|
17
116
|
export declare const last: typeof _lastNew;
|
|
117
|
+
/**
|
|
118
|
+
* Internal helper implementing an immutable index update via `with`.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
18
121
|
export declare function _updateNew<T>(arr: readonly T[], index: number, updater: Update<T>): readonly T[];
|
|
122
|
+
/**
|
|
123
|
+
* Internal helper implementing an immutable index update via cloning.
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
19
126
|
export declare function _updateOld<T>(arr: readonly T[], index: number, updater: Update<T>): readonly T[];
|
|
127
|
+
/**
|
|
128
|
+
* Returns a copy of the array where the element at the given index is replaced using the provided updater.
|
|
129
|
+
* If the result value is identical (by `Object.is`) the original array is returned.
|
|
130
|
+
* @typeparam T - element type
|
|
131
|
+
* @param arr - the source array
|
|
132
|
+
* @param index - the index to update
|
|
133
|
+
* @param updater - value or function update description
|
|
134
|
+
*/
|
|
20
135
|
export declare const update: typeof _updateNew;
|
|
136
|
+
/**
|
|
137
|
+
* Internal helper applying a modifier function via `with`.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
21
140
|
export declare function _modNew<T>(arr: readonly T[], index: number, f: (value: T) => T): readonly T[];
|
|
141
|
+
/**
|
|
142
|
+
* Internal helper applying a modifier function via cloning.
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
22
145
|
export declare function _modOld<T>(arr: readonly T[], index: number, f: (value: T) => T): readonly T[];
|
|
146
|
+
/**
|
|
147
|
+
* Returns a copy of the array where the element at the given index is transformed by a modifier function.
|
|
148
|
+
* If the result value is identical (by `Object.is`) the original array is returned.
|
|
149
|
+
* @typeparam T - element type
|
|
150
|
+
* @param arr - the source array
|
|
151
|
+
* @param index - the index to modify
|
|
152
|
+
* @param f - modifier function receiving the current value
|
|
153
|
+
*/
|
|
23
154
|
export declare const mod: typeof _modNew;
|
|
155
|
+
/**
|
|
156
|
+
* Internal helper for inserting a value using `toSpliced`.
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
24
159
|
export declare function _insertNew<T>(arr: readonly T[], index: number, value: T): T[];
|
|
160
|
+
/**
|
|
161
|
+
* Internal helper for inserting a value using legacy `splice` on a clone.
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
25
164
|
export declare function _insertOld<T>(arr: readonly T[], index: number, value: T): T[];
|
|
165
|
+
/**
|
|
166
|
+
* Returns a copy of the array where at the given index the provided value is inserted.
|
|
167
|
+
* @typeparam T - element type
|
|
168
|
+
* @param arr - the source array
|
|
169
|
+
* @param index - insertion index
|
|
170
|
+
* @param value - value to insert
|
|
171
|
+
*/
|
|
26
172
|
export declare const insert: typeof _insertNew;
|
|
173
|
+
/**
|
|
174
|
+
* Returns a copy of the array without its first element.
|
|
175
|
+
* @typeparam T - element type
|
|
176
|
+
* @param arr - the source array
|
|
177
|
+
*/
|
|
27
178
|
export declare function tail<T>(arr: readonly T[]): T[];
|
|
179
|
+
/**
|
|
180
|
+
* Returns a copy of the array without its last element.
|
|
181
|
+
* @typeparam T - element type
|
|
182
|
+
* @param arr - the source array
|
|
183
|
+
*/
|
|
28
184
|
export declare function init<T>(arr: readonly T[]): T[];
|
|
185
|
+
/**
|
|
186
|
+
* Internal helper providing an immutable `splice` using `toSpliced`.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
29
189
|
export declare function _spliceNew<T>(arr: readonly T[], start: number, deleteCount: number, ...items: T[]): T[];
|
|
190
|
+
/**
|
|
191
|
+
* Internal helper providing an immutable `splice` via cloning.
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
30
194
|
export declare function _spliceOld<T>(arr: readonly T[], start: number, deleteCount: number, ...items: T[]): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Immutable version of the array `.splice` command, always returning a new array.
|
|
197
|
+
* @typeparam T - element type
|
|
198
|
+
* @param arr - the source array
|
|
199
|
+
* @param start - start index
|
|
200
|
+
* @param deleteCount - number of elements to delete
|
|
201
|
+
* @param items - optional items to insert
|
|
202
|
+
*/
|
|
31
203
|
export declare const splice: typeof _spliceNew;
|
|
204
|
+
/**
|
|
205
|
+
* Returns a copy of a (potentially) sparse array preserving sparsity (skips holes).
|
|
206
|
+
* @typeparam T - element type
|
|
207
|
+
* @param arr - the source sparse array
|
|
208
|
+
*/
|
|
32
209
|
export declare function copySparse<T>(arr: readonly T[]): T[];
|
|
210
|
+
/**
|
|
211
|
+
* Returns a copy of a sparse array applying the given function to each present element, preserving holes.
|
|
212
|
+
* @typeparam T - source element type
|
|
213
|
+
* @typeparam T2 - result element type
|
|
214
|
+
* @param arr - the source sparse array
|
|
215
|
+
* @param f - mapping function
|
|
216
|
+
*/
|
|
33
217
|
export declare function mapSparse<T, T2>(arr: readonly T[], f: (value: T, index: number) => T2): T2[];
|
package/dist/cjs/entry.cjs
CHANGED
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.first = first;
|
|
4
4
|
exports.second = second;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Returns the first element of a 2-tuple.
|
|
7
|
+
* @typeparam K - the first element type
|
|
8
|
+
* @typeparam V - the second element type
|
|
9
|
+
* @param entry - the tuple
|
|
10
|
+
* @returns the first element
|
|
11
|
+
*/
|
|
6
12
|
function first(entry) {
|
|
7
13
|
return entry[0];
|
|
8
14
|
}
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Returns the second element of a 2-tuple.
|
|
17
|
+
* @typeparam K - the first element type
|
|
18
|
+
* @typeparam V - the second element type
|
|
19
|
+
* @param entry - the tuple
|
|
20
|
+
* @returns the second element
|
|
21
|
+
*/
|
|
10
22
|
function second(entry) {
|
|
11
23
|
return entry[1];
|
|
12
24
|
}
|
package/dist/cjs/entry.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.cjs","sourceRoot":"","sources":["../../_cjs_prepare/entry.cts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"entry.cjs","sourceRoot":"","sources":["../../_cjs_prepare/entry.cts"],"names":[],"mappings":";;AAOA,sBAEC;AASD,wBAEC;AApBD;;;;;;GAMG;AACH,SAAgB,KAAK,CAAO,KAAsB;IAChD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,MAAM,CAAO,KAAsB;IACjD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/cjs/entry.d.cts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first element of a 2-tuple.
|
|
3
|
+
* @typeparam K - the first element type
|
|
4
|
+
* @typeparam V - the second element type
|
|
5
|
+
* @param entry - the tuple
|
|
6
|
+
* @returns the first element
|
|
7
|
+
*/
|
|
1
8
|
export declare function first<K, V>(entry: readonly [K, V]): K;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the second element of a 2-tuple.
|
|
11
|
+
* @typeparam K - the first element type
|
|
12
|
+
* @typeparam V - the second element type
|
|
13
|
+
* @param entry - the tuple
|
|
14
|
+
* @returns the second element
|
|
15
|
+
*/
|
|
2
16
|
export declare function second<K, V>(entry: readonly [K, V]): V;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RimbuError = exports.Entry = exports.Arr = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*
|
|
8
|
+
* The `@rimbu/base` package provides foundational immutable array utilities, tuple helpers,
|
|
9
|
+
* plain‑object type predicates and structured error types that power all other Rimbu collections.<br/>
|
|
10
|
+
* Use it directly when you need low‑level, performance‑aware primitives for persistent data
|
|
11
|
+
* structures without pulling in the higher‑level collection packages.<br/>
|
|
12
|
+
* See the Rimbu docs and API reference for more information.
|
|
13
|
+
*/
|
|
5
14
|
exports.Arr = tslib_1.__importStar(require("./arr.cjs"));
|
|
6
15
|
exports.Entry = tslib_1.__importStar(require("./entry.cjs"));
|
|
7
16
|
exports.RimbuError = tslib_1.__importStar(require("./rimbu-error.cjs"));
|
|
8
17
|
tslib_1.__exportStar(require("./plain-object.cjs"), exports);
|
|
18
|
+
// Internal exports (may change without notice)
|
|
9
19
|
tslib_1.__exportStar(require("./internal.cjs"), exports);
|
|
10
20
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../_cjs_prepare/index.cts"],"names":[],"mappings":";;;;AAAA,yDAAiC;AACjC,6DAAqC;AACrC,wEAAgD;AAChD,6DAAmC;AAEnC,yDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../_cjs_prepare/index.cts"],"names":[],"mappings":";;;;AAAA;;;;;;;;GAQG;AACH,yDAAiC;AACjC,6DAAqC;AACrC,wEAAgD;AAChD,6DAAmC;AAEnC,+CAA+C;AAC/C,yDAA+B"}
|