ts-data-forge 6.4.0 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/array/impl/array-utils-element-access.d.mts +5 -5
- package/dist/array/impl/array-utils-element-access.mjs +4 -4
- package/dist/array/impl/array-utils-iterators.d.mts +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +4 -4
- package/dist/array/impl/array-utils-reducing-value.d.mts +5 -5
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +1 -0
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +8 -8
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +3 -1
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +1 -1
- package/dist/array/impl/array-utils-size.mjs +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +3 -3
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +7 -7
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +22 -12
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.d.mts +5 -12
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +24 -28
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +8 -14
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +9 -23
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +1 -0
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +6 -5
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -1
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +1 -1
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -0
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +3 -1
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +6 -2
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +3 -1
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +2 -2
- package/dist/guard/is-record.mjs +2 -2
- package/dist/guard/is-type.d.mts +15 -15
- package/dist/guard/is-type.mjs +15 -15
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -1
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/json/json.d.mts +3 -3
- package/dist/json/json.mjs +4 -3
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-safe-int.mjs +1 -1
- package/dist/number/branded-types/safe-int.mjs +2 -2
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/num.mjs +1 -1
- package/dist/object/object.d.mts +36 -8
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +28 -6
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts +8 -0
- package/dist/others/fast-deep-equal.d.mts.map +1 -0
- package/dist/others/fast-deep-equal.mjs +72 -0
- package/dist/others/fast-deep-equal.mjs.map +1 -0
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/package.json +34 -29
- package/src/array/impl/array-utils-creation.test.mts +13 -10
- package/src/array/impl/array-utils-element-access.mts +5 -5
- package/src/array/impl/array-utils-element-access.test.mts +5 -5
- package/src/array/impl/array-utils-iterators.mts +1 -1
- package/src/array/impl/array-utils-iterators.test.mts +6 -6
- package/src/array/impl/array-utils-modification.mts +4 -4
- package/src/array/impl/array-utils-modification.test.mts +12 -12
- package/src/array/impl/array-utils-overload-type-error.test.mts +1 -1
- package/src/array/impl/array-utils-reducing-value.mts +6 -5
- package/src/array/impl/array-utils-reducing-value.test.mts +9 -9
- package/src/array/impl/array-utils-search.mts +8 -8
- package/src/array/impl/array-utils-search.test.mts +35 -35
- package/src/array/impl/array-utils-set-op.mts +1 -0
- package/src/array/impl/array-utils-set-op.test.mts +2 -2
- package/src/array/impl/array-utils-size.mts +1 -1
- package/src/array/impl/array-utils-size.test.mts +1 -1
- package/src/array/impl/array-utils-slice-clamped.mts +1 -1
- package/src/array/impl/array-utils-slice-clamped.test.mts +5 -5
- package/src/array/impl/array-utils-slicing.mts +3 -3
- package/src/array/impl/array-utils-slicing.test.mts +5 -5
- package/src/array/impl/array-utils-transformation.mts +1 -1
- package/src/array/impl/array-utils-transformation.test.mts +53 -53
- package/src/array/impl/array-utils-validation.mts +18 -10
- package/src/array/impl/array-utils-validation.test.mts +34 -29
- package/src/array/impl/array.test.mts +1 -1
- package/src/collections/imap-mapped.mts +4 -10
- package/src/collections/imap-mapped.test.mts +9 -9
- package/src/collections/imap.mts +24 -27
- package/src/collections/imap.test.mts +6 -6
- package/src/collections/iset-mapped.mts +12 -16
- package/src/collections/iset-mapped.test.mts +6 -6
- package/src/collections/iset.mts +14 -25
- package/src/collections/queue.test.mts +2 -1
- package/src/collections/stack.test.mts +3 -3
- package/src/functional/optional/impl/optional-is-optional.mts +6 -6
- package/src/functional/optional/impl/optional-some.mts +5 -4
- package/src/functional/optional/impl/optional-zip.mts +1 -1
- package/src/functional/result/impl/result-err.mts +5 -4
- package/src/functional/result/impl/result-is-result.mts +1 -1
- package/src/functional/result/impl/result-ok.mts +5 -4
- package/src/functional/result.test.mts +2 -2
- package/src/functional/ternary-result/impl/ternary-result-err.mts +5 -4
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +5 -4
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +6 -5
- package/src/guard/has-key.mts +6 -2
- package/src/guard/is-error.test.mts +1 -1
- package/src/guard/is-non-empty-string.test.mts +1 -1
- package/src/guard/is-non-null-object.mts +1 -0
- package/src/guard/is-non-null-object.test.mts +4 -3
- package/src/guard/is-primitive.test.mts +1 -1
- package/src/guard/is-record.mts +2 -2
- package/src/guard/is-record.test.mts +2 -2
- package/src/guard/is-type.mts +15 -15
- package/src/guard/is-type.test.mts +2 -2
- package/src/guard/key-is-in.mts +3 -1
- package/src/json/json.mts +4 -3
- package/src/json/json.test.mts +20 -19
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/positive-safe-int.mts +1 -1
- package/src/number/branded-types/safe-int.mts +2 -2
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/num.mts +1 -1
- package/src/object/object.mts +54 -8
- package/src/object/object.test.mts +70 -7
- package/src/others/cast-mutable.test.mts +3 -3
- package/src/others/cast-readonly.test.mts +10 -5
- package/src/others/fast-deep-equal.mts +98 -0
- package/src/others/fast-deep-equal.test.mts +771 -0
- package/src/others/index.mts +1 -0
- package/src/others/map-nullable.test.mts +8 -8
- package/src/others/memoize-function.test.mts +20 -8
- package/src/others/unknown-to-string.test.mts +8 -8
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
describe('Arr search operations', () => {
|
|
15
15
|
describe(find, () => {
|
|
16
16
|
test('should find first element matching predicate', () => {
|
|
17
|
-
const numbers = [1, 2, 3, 4, 5];
|
|
17
|
+
const numbers = [1, 2, 3, 4, 5] as const;
|
|
18
18
|
|
|
19
19
|
const firstEven = find(numbers, (n) => n % 2 === 0);
|
|
20
20
|
|
|
@@ -24,7 +24,7 @@ describe('Arr search operations', () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
test('should return None when no element matches', () => {
|
|
27
|
-
const odds = [1, 3, 5];
|
|
27
|
+
const odds = [1, 3, 5] as const;
|
|
28
28
|
|
|
29
29
|
const firstEven = find(odds, (n) => n % 2 === 0);
|
|
30
30
|
|
|
@@ -48,7 +48,7 @@ describe('Arr search operations', () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
test('should work with type guard predicate', () => {
|
|
51
|
-
const values: readonly (string | number)[] = [1, 'a', 2, 'b'];
|
|
51
|
+
const values: readonly (string | number)[] = [1, 'a', 2, 'b'] as const;
|
|
52
52
|
|
|
53
53
|
const firstString = find(
|
|
54
54
|
values,
|
|
@@ -63,7 +63,7 @@ describe('Arr search operations', () => {
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
test('should provide index and array to predicate', () => {
|
|
66
|
-
const numbers = [10, 20, 30];
|
|
66
|
+
const numbers = [10, 20, 30] as readonly number[];
|
|
67
67
|
|
|
68
68
|
const foundWithIndex = find(numbers, (value, index, arr) => {
|
|
69
69
|
expect(arr).toBe(numbers);
|
|
@@ -75,7 +75,7 @@ describe('Arr search operations', () => {
|
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
test('should return first match when multiple elements match', () => {
|
|
78
|
-
const numbers = [2, 4, 6, 8];
|
|
78
|
+
const numbers = [2, 4, 6, 8] as const;
|
|
79
79
|
|
|
80
80
|
const firstEven = find(numbers, (n) => n % 2 === 0);
|
|
81
81
|
|
|
@@ -83,7 +83,7 @@ describe('Arr search operations', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
test('should work with empty array', () => {
|
|
86
|
-
const empty: readonly number[] = [];
|
|
86
|
+
const empty: readonly number[] = [] as const;
|
|
87
87
|
|
|
88
88
|
const result = find(empty, () => true);
|
|
89
89
|
|
|
@@ -93,7 +93,7 @@ describe('Arr search operations', () => {
|
|
|
93
93
|
|
|
94
94
|
describe(findLast, () => {
|
|
95
95
|
test('should find last element matching predicate', () => {
|
|
96
|
-
const numbers = [1, 2, 3, 4, 5];
|
|
96
|
+
const numbers = [1, 2, 3, 4, 5] as const;
|
|
97
97
|
|
|
98
98
|
const lastEven = findLast(numbers, (n) => n % 2 === 0);
|
|
99
99
|
|
|
@@ -103,7 +103,7 @@ describe('Arr search operations', () => {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
test('should return None when no element matches', () => {
|
|
106
|
-
const odds = [1, 3, 5];
|
|
106
|
+
const odds = [1, 3, 5] as const;
|
|
107
107
|
|
|
108
108
|
const lastEven = findLast(odds, (n) => n % 2 === 0);
|
|
109
109
|
|
|
@@ -123,7 +123,7 @@ describe('Arr search operations', () => {
|
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
test('should work with empty array', () => {
|
|
126
|
-
const empty: readonly number[] = [];
|
|
126
|
+
const empty: readonly number[] = [] as const;
|
|
127
127
|
|
|
128
128
|
const result = findLast(empty, (n) => n > 0);
|
|
129
129
|
|
|
@@ -131,7 +131,7 @@ describe('Arr search operations', () => {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
test('should pass index and array to predicate', () => {
|
|
134
|
-
const numbers = [10, 20, 30, 40];
|
|
134
|
+
const numbers = [10, 20, 30, 40] as readonly number[];
|
|
135
135
|
|
|
136
136
|
const lastWithIndex2 = findLast(numbers, (_, idx, arr) => {
|
|
137
137
|
expect(arr).toBe(numbers);
|
|
@@ -143,7 +143,7 @@ describe('Arr search operations', () => {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
test('should find last occurrence', () => {
|
|
146
|
-
const numbers = [1, 2, 2, 3, 2, 4];
|
|
146
|
+
const numbers = [1, 2, 2, 3, 2, 4] as const;
|
|
147
147
|
|
|
148
148
|
const lastTwo = findLast(numbers, (n) => n === 2);
|
|
149
149
|
|
|
@@ -158,7 +158,7 @@ describe('Arr search operations', () => {
|
|
|
158
158
|
|
|
159
159
|
describe(findIndex, () => {
|
|
160
160
|
test('should find index of matching element', () => {
|
|
161
|
-
const arr = ['a', 'b', 'c'];
|
|
161
|
+
const arr = ['a', 'b', 'c'] as readonly string[];
|
|
162
162
|
|
|
163
163
|
const result = findIndex(arr, (x) => x === 'b');
|
|
164
164
|
|
|
@@ -170,7 +170,7 @@ describe('Arr search operations', () => {
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
test('should return None for no match', () => {
|
|
173
|
-
const arr = ['a', 'b', 'c'];
|
|
173
|
+
const arr = ['a', 'b', 'c'] as readonly string[];
|
|
174
174
|
|
|
175
175
|
const result = findIndex(arr, (x) => x === 'd');
|
|
176
176
|
|
|
@@ -180,7 +180,7 @@ describe('Arr search operations', () => {
|
|
|
180
180
|
|
|
181
181
|
describe(findLastIndex, () => {
|
|
182
182
|
test('should find last index matching predicate', () => {
|
|
183
|
-
const numbers = [1, 2, 3, 4, 2, 5];
|
|
183
|
+
const numbers = [1, 2, 3, 4, 2, 5] as const;
|
|
184
184
|
|
|
185
185
|
const lastTwoIndex = findLastIndex(numbers, (n) => n === 2);
|
|
186
186
|
|
|
@@ -188,7 +188,7 @@ describe('Arr search operations', () => {
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
test('should return -1 when no element matches', () => {
|
|
191
|
-
const odds = [1, 3, 5];
|
|
191
|
+
const odds = [1, 3, 5] as const;
|
|
192
192
|
|
|
193
193
|
const lastEvenIndex = findLastIndex(odds, (n) => n % 2 === 0);
|
|
194
194
|
|
|
@@ -206,7 +206,7 @@ describe('Arr search operations', () => {
|
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
test('should work with empty array', () => {
|
|
209
|
-
const empty: readonly number[] = [];
|
|
209
|
+
const empty: readonly number[] = [] as const;
|
|
210
210
|
|
|
211
211
|
const result = findLastIndex(empty, (n) => n > 0);
|
|
212
212
|
|
|
@@ -214,7 +214,7 @@ describe('Arr search operations', () => {
|
|
|
214
214
|
});
|
|
215
215
|
|
|
216
216
|
test('should pass index and array to predicate', () => {
|
|
217
|
-
const numbers = [10, 20, 30, 40];
|
|
217
|
+
const numbers = [10, 20, 30, 40] as const;
|
|
218
218
|
|
|
219
219
|
const lastWithIndex2OrHigher = findLastIndex(numbers, (_, idx, arr) => {
|
|
220
220
|
expect(arr).toBe(numbers);
|
|
@@ -232,7 +232,7 @@ describe('Arr search operations', () => {
|
|
|
232
232
|
{ id: 3, active: true },
|
|
233
233
|
{ id: 4, active: false },
|
|
234
234
|
{ id: 5, active: true },
|
|
235
|
-
];
|
|
235
|
+
] as const;
|
|
236
236
|
|
|
237
237
|
const lastActiveIndex = findLastIndex(data, (item) => item.active);
|
|
238
238
|
|
|
@@ -249,7 +249,7 @@ describe('Arr search operations', () => {
|
|
|
249
249
|
|
|
250
250
|
test('should search from end to beginning', () => {
|
|
251
251
|
// Verify search order by using side effects
|
|
252
|
-
const numbers = [1, 2, 3, 4, 5];
|
|
252
|
+
const numbers = [1, 2, 3, 4, 5] as const;
|
|
253
253
|
|
|
254
254
|
const mut_searchOrder: number[] = [];
|
|
255
255
|
|
|
@@ -264,7 +264,7 @@ describe('Arr search operations', () => {
|
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
test('should handle single element array', () => {
|
|
267
|
-
const single = [42];
|
|
267
|
+
const single = [42] as readonly number[];
|
|
268
268
|
|
|
269
269
|
const foundIndex = findLastIndex(single, (n) => n === 42);
|
|
270
270
|
|
|
@@ -276,7 +276,7 @@ describe('Arr search operations', () => {
|
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
test('should work with string arrays', () => {
|
|
279
|
-
const words = ['hello', 'world', 'test', 'hello', 'end'];
|
|
279
|
+
const words = ['hello', 'world', 'test', 'hello', 'end'] as const;
|
|
280
280
|
|
|
281
281
|
const lastHelloIndex = findLastIndex(words, (word) => word === 'hello');
|
|
282
282
|
|
|
@@ -286,7 +286,7 @@ describe('Arr search operations', () => {
|
|
|
286
286
|
|
|
287
287
|
describe(indexOf, () => {
|
|
288
288
|
test('should find index of element', () => {
|
|
289
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
289
|
+
const arr = ['a', 'b', 'c', 'b'] as readonly string[];
|
|
290
290
|
|
|
291
291
|
const result = indexOf(arr, 'b');
|
|
292
292
|
|
|
@@ -300,7 +300,7 @@ describe('Arr search operations', () => {
|
|
|
300
300
|
});
|
|
301
301
|
|
|
302
302
|
test('should return -1 for non-existent element', () => {
|
|
303
|
-
const arr = ['a', 'b', 'c'];
|
|
303
|
+
const arr = ['a', 'b', 'c'] as readonly string[];
|
|
304
304
|
|
|
305
305
|
const result = indexOf(arr, 'd');
|
|
306
306
|
|
|
@@ -310,7 +310,7 @@ describe('Arr search operations', () => {
|
|
|
310
310
|
|
|
311
311
|
describe(indexOfFrom, () => {
|
|
312
312
|
test('should find index of element from specified index', () => {
|
|
313
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
313
|
+
const arr = ['a', 'b', 'c', 'b'] as readonly string[];
|
|
314
314
|
|
|
315
315
|
const result = indexOfFrom(arr, 'b', 2);
|
|
316
316
|
|
|
@@ -324,7 +324,7 @@ describe('Arr search operations', () => {
|
|
|
324
324
|
});
|
|
325
325
|
|
|
326
326
|
test('should return -1 when element not found from index', () => {
|
|
327
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
327
|
+
const arr = ['a', 'b', 'c', 'b'] as const;
|
|
328
328
|
|
|
329
329
|
const result = indexOfFrom(arr, 'a', 1);
|
|
330
330
|
|
|
@@ -332,7 +332,7 @@ describe('Arr search operations', () => {
|
|
|
332
332
|
});
|
|
333
333
|
|
|
334
334
|
test('should find first occurrence when fromIndex is 0', () => {
|
|
335
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
335
|
+
const arr = ['a', 'b', 'c', 'b'] as const;
|
|
336
336
|
|
|
337
337
|
const result = indexOfFrom(arr, 'b', 0);
|
|
338
338
|
|
|
@@ -340,7 +340,7 @@ describe('Arr search operations', () => {
|
|
|
340
340
|
});
|
|
341
341
|
|
|
342
342
|
test('should handle negative fromIndex', () => {
|
|
343
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
343
|
+
const arr = ['a', 'b', 'c', 'b'] as const;
|
|
344
344
|
|
|
345
345
|
const result = indexOfFrom(arr, 'b', -2);
|
|
346
346
|
|
|
@@ -348,7 +348,7 @@ describe('Arr search operations', () => {
|
|
|
348
348
|
});
|
|
349
349
|
|
|
350
350
|
test('should handle fromIndex beyond array length', () => {
|
|
351
|
-
const arr = ['a', 'b', 'c'];
|
|
351
|
+
const arr = ['a', 'b', 'c'] as readonly string[];
|
|
352
352
|
|
|
353
353
|
const result = indexOfFrom(arr, 'a', 10);
|
|
354
354
|
|
|
@@ -358,7 +358,7 @@ describe('Arr search operations', () => {
|
|
|
358
358
|
|
|
359
359
|
describe(lastIndexOf, () => {
|
|
360
360
|
test('should find last index of element', () => {
|
|
361
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
361
|
+
const arr = ['a', 'b', 'c', 'b'] as readonly string[];
|
|
362
362
|
|
|
363
363
|
const result = lastIndexOf(arr, 'b');
|
|
364
364
|
|
|
@@ -372,7 +372,7 @@ describe('Arr search operations', () => {
|
|
|
372
372
|
});
|
|
373
373
|
|
|
374
374
|
test('should return -1 for non-existent element', () => {
|
|
375
|
-
const arr = ['a', 'b', 'c'];
|
|
375
|
+
const arr = ['a', 'b', 'c'] as readonly string[];
|
|
376
376
|
|
|
377
377
|
const result = lastIndexOf(arr, 'd');
|
|
378
378
|
|
|
@@ -382,7 +382,7 @@ describe('Arr search operations', () => {
|
|
|
382
382
|
|
|
383
383
|
describe(lastIndexOfFrom, () => {
|
|
384
384
|
test('should find last index of element from specified index', () => {
|
|
385
|
-
const arr = ['a', 'b', 'c', 'b', 'e'];
|
|
385
|
+
const arr = ['a', 'b', 'c', 'b', 'e'] as readonly string[];
|
|
386
386
|
|
|
387
387
|
const result = lastIndexOfFrom(arr, 'b', 2);
|
|
388
388
|
|
|
@@ -396,7 +396,7 @@ describe('Arr search operations', () => {
|
|
|
396
396
|
});
|
|
397
397
|
|
|
398
398
|
test('should return -1 when element not found before index', () => {
|
|
399
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
399
|
+
const arr = ['a', 'b', 'c', 'b'] as const;
|
|
400
400
|
|
|
401
401
|
const result = lastIndexOfFrom(arr, 'b', 0);
|
|
402
402
|
|
|
@@ -404,7 +404,7 @@ describe('Arr search operations', () => {
|
|
|
404
404
|
});
|
|
405
405
|
|
|
406
406
|
test('should find last occurrence when fromIndex covers all elements', () => {
|
|
407
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
407
|
+
const arr = ['a', 'b', 'c', 'b'] as readonly string[];
|
|
408
408
|
|
|
409
409
|
const result = lastIndexOfFrom(arr, 'b', 10);
|
|
410
410
|
|
|
@@ -412,7 +412,7 @@ describe('Arr search operations', () => {
|
|
|
412
412
|
});
|
|
413
413
|
|
|
414
414
|
test('should handle negative fromIndex', () => {
|
|
415
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
415
|
+
const arr = ['a', 'b', 'c', 'b'] as const;
|
|
416
416
|
|
|
417
417
|
const result = lastIndexOfFrom(arr, 'b', -1);
|
|
418
418
|
|
|
@@ -420,7 +420,7 @@ describe('Arr search operations', () => {
|
|
|
420
420
|
});
|
|
421
421
|
|
|
422
422
|
test('should handle fromIndex of 0', () => {
|
|
423
|
-
const arr = ['a', 'b', 'c', 'b'];
|
|
423
|
+
const arr = ['a', 'b', 'c', 'b'] as const;
|
|
424
424
|
|
|
425
425
|
const result = lastIndexOfFrom(arr, 'a', 0);
|
|
426
426
|
|
|
@@ -20,6 +20,7 @@ export const eq = <E,>(
|
|
|
20
20
|
array2: readonly E[],
|
|
21
21
|
equality: (a: E, b: E) => boolean = Object.is,
|
|
22
22
|
): boolean =>
|
|
23
|
+
// eslint-disable-next-line ts-data-forge/prefer-arr-is-array-of-length
|
|
23
24
|
array1.length === array2.length &&
|
|
24
25
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
26
|
array1.every((v, i) => equality(v, array2[i]!));
|
|
@@ -116,7 +116,7 @@ describe('Arr', () => {
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
test('should slice with clamped indices', () => {
|
|
119
|
-
const array = [1, 2, 3, 4, 5];
|
|
119
|
+
const array = [1, 2, 3, 4, 5] as const;
|
|
120
120
|
|
|
121
121
|
const result = sliceClamped(array, 1, 3);
|
|
122
122
|
|
|
@@ -124,7 +124,7 @@ describe('Arr', () => {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
test('should clamp start index below 0', () => {
|
|
127
|
-
const array = [1, 2, 3, 4, 5];
|
|
127
|
+
const array = [1, 2, 3, 4, 5] as readonly number[];
|
|
128
128
|
|
|
129
129
|
const result = sliceClamped(array, -10, 3);
|
|
130
130
|
|
|
@@ -132,7 +132,7 @@ describe('Arr', () => {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
test('should clamp end index above length', () => {
|
|
135
|
-
const array = [1, 2, 3, 4, 5];
|
|
135
|
+
const array = [1, 2, 3, 4, 5] as readonly number[];
|
|
136
136
|
|
|
137
137
|
const result = sliceClamped(array, asUint32(2), asUint32(100));
|
|
138
138
|
|
|
@@ -140,7 +140,7 @@ describe('Arr', () => {
|
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
test('should work with both indices out of range', () => {
|
|
143
|
-
const array = [1, 2, 3];
|
|
143
|
+
const array = [1, 2, 3] as readonly number[];
|
|
144
144
|
|
|
145
145
|
const result = sliceClamped(array, asInt32(-10), asUint32(100));
|
|
146
146
|
|
|
@@ -148,7 +148,7 @@ describe('Arr', () => {
|
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
test('should work with empty array', () => {
|
|
151
|
-
const array: readonly number[] = [];
|
|
151
|
+
const array: readonly number[] = [] as const;
|
|
152
152
|
|
|
153
153
|
const result = sliceClamped(array, 0, 5);
|
|
154
154
|
|
|
@@ -65,7 +65,7 @@ export const butLast = <const Ar extends readonly unknown[]>(
|
|
|
65
65
|
* @example
|
|
66
66
|
*
|
|
67
67
|
* ```ts
|
|
68
|
-
* const values = [1, 2, 3, 4];
|
|
68
|
+
* const values = [1, 2, 3, 4] as const;
|
|
69
69
|
*
|
|
70
70
|
* const firstTwo = Arr.take(values, 2);
|
|
71
71
|
*
|
|
@@ -128,7 +128,7 @@ export function take<E>(
|
|
|
128
128
|
* @example
|
|
129
129
|
*
|
|
130
130
|
* ```ts
|
|
131
|
-
* const values = [1, 2, 3, 4];
|
|
131
|
+
* const values = [1, 2, 3, 4] as const;
|
|
132
132
|
*
|
|
133
133
|
* const lastTwo = Arr.takeLast(values, 2);
|
|
134
134
|
*
|
|
@@ -241,7 +241,7 @@ export function skip<E>(
|
|
|
241
241
|
* @example
|
|
242
242
|
*
|
|
243
243
|
* ```ts
|
|
244
|
-
* const values = ['a', 'b', 'c', 'd'];
|
|
244
|
+
* const values = ['a', 'b', 'c', 'd'] as const;
|
|
245
245
|
*
|
|
246
246
|
* const withoutLastTwo = Arr.skipLast(values, 2);
|
|
247
247
|
*
|
|
@@ -43,7 +43,7 @@ describe('Arr slicing', () => {
|
|
|
43
43
|
|
|
44
44
|
describe(butLast, () => {
|
|
45
45
|
test('readonly number[] type', () => {
|
|
46
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
46
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
47
47
|
|
|
48
48
|
const bl = butLast(xs);
|
|
49
49
|
|
|
@@ -97,7 +97,7 @@ describe('Arr slicing', () => {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
{
|
|
100
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
100
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
101
101
|
|
|
102
102
|
const t = take(xs, 2);
|
|
103
103
|
|
|
@@ -131,7 +131,7 @@ describe('Arr slicing', () => {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
{
|
|
134
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
134
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
135
135
|
|
|
136
136
|
const t = takeLast(xs, 2);
|
|
137
137
|
|
|
@@ -165,7 +165,7 @@ describe('Arr slicing', () => {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
{
|
|
168
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
168
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
169
169
|
|
|
170
170
|
const t = skip(xs, 2);
|
|
171
171
|
|
|
@@ -199,7 +199,7 @@ describe('Arr slicing', () => {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
{
|
|
202
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
202
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
203
203
|
|
|
204
204
|
const t = skipLast(xs, 2);
|
|
205
205
|
|
|
@@ -679,7 +679,7 @@ export const concat = <
|
|
|
679
679
|
>(
|
|
680
680
|
array1: Ar1,
|
|
681
681
|
array2: Ar2,
|
|
682
|
-
): readonly [...Ar1, ...Ar2] => [...array1, ...array2];
|
|
682
|
+
): readonly [...Ar1, ...Ar2] => [...array1, ...array2] as const;
|
|
683
683
|
|
|
684
684
|
/**
|
|
685
685
|
* Groups elements by a key derived from each element.
|