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
|
@@ -4,7 +4,7 @@ import { entries, indices, values } from './array-utils-iterators.mjs';
|
|
|
4
4
|
|
|
5
5
|
describe(entries, () => {
|
|
6
6
|
test('should return array of index-value pairs', () => {
|
|
7
|
-
const fruits = ['apple', 'banana', 'cherry'];
|
|
7
|
+
const fruits = ['apple', 'banana', 'cherry'] as const;
|
|
8
8
|
|
|
9
9
|
const es = Array.from(entries(fruits));
|
|
10
10
|
|
|
@@ -31,7 +31,7 @@ describe(entries, () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('should work with empty array', () => {
|
|
34
|
-
const empty: readonly string[] = [];
|
|
34
|
+
const empty: readonly string[] = [] as const;
|
|
35
35
|
|
|
36
36
|
const es = Array.from(entries(empty));
|
|
37
37
|
|
|
@@ -56,7 +56,7 @@ describe(entries, () => {
|
|
|
56
56
|
|
|
57
57
|
describe(values, () => {
|
|
58
58
|
test('should return copy of array values', () => {
|
|
59
|
-
const numbers = [1, 2, 3];
|
|
59
|
+
const numbers = [1, 2, 3] as const;
|
|
60
60
|
|
|
61
61
|
const vs = Array.from(values(numbers));
|
|
62
62
|
|
|
@@ -77,7 +77,7 @@ describe(values, () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
test('should work with empty array', () => {
|
|
80
|
-
const empty: readonly number[] = [];
|
|
80
|
+
const empty: readonly number[] = [] as const;
|
|
81
81
|
|
|
82
82
|
const vs = Array.from(values(empty));
|
|
83
83
|
|
|
@@ -98,7 +98,7 @@ describe(values, () => {
|
|
|
98
98
|
|
|
99
99
|
describe(indices, () => {
|
|
100
100
|
test('should return array of indices', () => {
|
|
101
|
-
const fruits = ['apple', 'banana', 'cherry'];
|
|
101
|
+
const fruits = ['apple', 'banana', 'cherry'] as const;
|
|
102
102
|
|
|
103
103
|
const ks = Array.from(indices(fruits));
|
|
104
104
|
|
|
@@ -117,7 +117,7 @@ describe(indices, () => {
|
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
test('should work with empty array', () => {
|
|
120
|
-
const empty: readonly string[] = [];
|
|
120
|
+
const empty: readonly string[] = [] as const;
|
|
121
121
|
|
|
122
122
|
const ks = Array.from(indices(empty));
|
|
123
123
|
|
|
@@ -8,7 +8,7 @@ import { copy, create } from './array-utils-creation.mjs';
|
|
|
8
8
|
* @example
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* const scores: readonly number[] = [10, 20, 30];
|
|
11
|
+
* const scores: readonly number[] = [10, 20, 30] as const;
|
|
12
12
|
*
|
|
13
13
|
* const updated = Arr.set(scores, 1, 25);
|
|
14
14
|
*
|
|
@@ -63,7 +63,7 @@ export function set<E, const V = E>(
|
|
|
63
63
|
* @example
|
|
64
64
|
*
|
|
65
65
|
* ```ts
|
|
66
|
-
* const temperatures: readonly number[] = [20, 21, 22];
|
|
66
|
+
* const temperatures: readonly number[] = [20, 21, 22] as const;
|
|
67
67
|
*
|
|
68
68
|
* const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);
|
|
69
69
|
*
|
|
@@ -341,7 +341,7 @@ export function toUnshifted<Ar extends readonly unknown[], const V>(
|
|
|
341
341
|
* @example
|
|
342
342
|
*
|
|
343
343
|
* ```ts
|
|
344
|
-
* const base = [1, 2, 3];
|
|
344
|
+
* const base = [1, 2, 3] as const;
|
|
345
345
|
*
|
|
346
346
|
* const filled = Arr.toFilled(base, 0);
|
|
347
347
|
*
|
|
@@ -396,7 +396,7 @@ export function toFilled<E>(
|
|
|
396
396
|
* @example
|
|
397
397
|
*
|
|
398
398
|
* ```ts
|
|
399
|
-
* const base = [0, 1, 2, 3, 4];
|
|
399
|
+
* const base = [0, 1, 2, 3, 4] as const;
|
|
400
400
|
*
|
|
401
401
|
* const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);
|
|
402
402
|
*
|
|
@@ -104,7 +104,7 @@ describe('Arr modifications', () => {
|
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
test('case 4 (number[])', () => {
|
|
107
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
107
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
108
108
|
|
|
109
109
|
const result = toRemoved(xs, 5);
|
|
110
110
|
|
|
@@ -134,7 +134,7 @@ describe('Arr modifications', () => {
|
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
test('case 2', () => {
|
|
137
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
137
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
138
138
|
|
|
139
139
|
const result = toPushed(xs, 4 as const);
|
|
140
140
|
|
|
@@ -164,7 +164,7 @@ describe('Arr modifications', () => {
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
test('case 2', () => {
|
|
167
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
167
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
168
168
|
|
|
169
169
|
const result = toUnshifted(xs, 4 as const);
|
|
170
170
|
|
|
@@ -184,7 +184,7 @@ describe('Arr modifications', () => {
|
|
|
184
184
|
|
|
185
185
|
describe(toFilled, () => {
|
|
186
186
|
test('should fill entire array with value', () => {
|
|
187
|
-
const arr = [1, 2, 3, 4, 5];
|
|
187
|
+
const arr = [1, 2, 3, 4, 5] as const;
|
|
188
188
|
|
|
189
189
|
const result = toFilled(arr, 0);
|
|
190
190
|
|
|
@@ -194,7 +194,7 @@ describe('Arr modifications', () => {
|
|
|
194
194
|
test('should work with curried version', () => {
|
|
195
195
|
const fillWithZero = toFilled(0);
|
|
196
196
|
|
|
197
|
-
const arr = [1, 2, 3];
|
|
197
|
+
const arr = [1, 2, 3] as const;
|
|
198
198
|
|
|
199
199
|
const result = fillWithZero(arr);
|
|
200
200
|
|
|
@@ -204,7 +204,7 @@ describe('Arr modifications', () => {
|
|
|
204
204
|
|
|
205
205
|
describe(toRangeFilled, () => {
|
|
206
206
|
test('should fill array with range', () => {
|
|
207
|
-
const arr = [1, 2, 3, 4, 5];
|
|
207
|
+
const arr = [1, 2, 3, 4, 5] as const;
|
|
208
208
|
|
|
209
209
|
const result = toRangeFilled(arr, 0, [1, 4]);
|
|
210
210
|
|
|
@@ -212,7 +212,7 @@ describe('Arr modifications', () => {
|
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
test('should fill with range starting from 0', () => {
|
|
215
|
-
const arr = [1, 2, 3, 4, 5];
|
|
215
|
+
const arr = [1, 2, 3, 4, 5] as const;
|
|
216
216
|
|
|
217
217
|
const result = toRangeFilled(arr, 9, [0, 3]);
|
|
218
218
|
|
|
@@ -220,7 +220,7 @@ describe('Arr modifications', () => {
|
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
test('should handle empty range', () => {
|
|
223
|
-
const arr = [1, 2, 3];
|
|
223
|
+
const arr = [1, 2, 3] as const;
|
|
224
224
|
|
|
225
225
|
const result = toRangeFilled(arr, 0, [2, 2]);
|
|
226
226
|
|
|
@@ -228,7 +228,7 @@ describe('Arr modifications', () => {
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
test('should clamp range to array bounds', () => {
|
|
231
|
-
const arr = [1, 2, 3];
|
|
231
|
+
const arr = [1, 2, 3] as readonly number[];
|
|
232
232
|
|
|
233
233
|
const result = toRangeFilled(arr, 0, [1, 10]);
|
|
234
234
|
|
|
@@ -236,7 +236,7 @@ describe('Arr modifications', () => {
|
|
|
236
236
|
});
|
|
237
237
|
|
|
238
238
|
test('should handle negative start (clamped to 0)', () => {
|
|
239
|
-
const arr = [1, 2, 3];
|
|
239
|
+
const arr = [1, 2, 3] as readonly number[];
|
|
240
240
|
|
|
241
241
|
const result = toRangeFilled(arr, 9, [-5, 2]);
|
|
242
242
|
|
|
@@ -252,14 +252,14 @@ describe('Arr modifications', () => {
|
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
test('A non-integer starting value should result in a type error', () => {
|
|
255
|
-
const arr = [1, 2, 3];
|
|
255
|
+
const arr = [1, 2, 3] as const;
|
|
256
256
|
|
|
257
257
|
// @ts-expect-error start must be an integer
|
|
258
258
|
assert.deepStrictEqual(toRangeFilled(arr, 0, [1.5, 3]), [1, 0, 0]);
|
|
259
259
|
});
|
|
260
260
|
|
|
261
261
|
test('A non-integer ending value should result in a type error', () => {
|
|
262
|
-
const arr = [1, 2, 3];
|
|
262
|
+
const arr = [1, 2, 3] as const;
|
|
263
263
|
|
|
264
264
|
// @ts-expect-error end must be an integer
|
|
265
265
|
assert.deepStrictEqual(toRangeFilled(arr, 0, [1, 2.5]), [1, 0, 3]);
|
|
@@ -148,7 +148,7 @@ describe('Array overloaded functions - type error validation', () => {
|
|
|
148
148
|
const invalidArgs: readonly [readonly string[], (x: string) => number] = [
|
|
149
149
|
['a'],
|
|
150
150
|
(x) => x.length,
|
|
151
|
-
];
|
|
151
|
+
] as const;
|
|
152
152
|
|
|
153
153
|
// @ts-expect-error - Wrong types in tuple for spread
|
|
154
154
|
findIndex(...invalidArgs);
|
|
@@ -14,7 +14,7 @@ import { isNonEmpty } from './array-utils-validation.mjs';
|
|
|
14
14
|
* ```ts
|
|
15
15
|
* const values = [5, 3, 9] as const;
|
|
16
16
|
*
|
|
17
|
-
* const empty: readonly number[] = [];
|
|
17
|
+
* const empty: readonly number[] = [] as const;
|
|
18
18
|
*
|
|
19
19
|
* const smallest = Arr.min(values);
|
|
20
20
|
*
|
|
@@ -64,7 +64,7 @@ export function min<E extends number>(
|
|
|
64
64
|
* @example
|
|
65
65
|
*
|
|
66
66
|
* ```ts
|
|
67
|
-
* const values = [5, 3, 9];
|
|
67
|
+
* const values = [5, 3, 9] as const;
|
|
68
68
|
*
|
|
69
69
|
* const largest = Arr.max(values);
|
|
70
70
|
*
|
|
@@ -155,7 +155,7 @@ export function minBy<E, V>(
|
|
|
155
155
|
* { id: 'a', stars: 10 },
|
|
156
156
|
* { id: 'b', stars: 30 },
|
|
157
157
|
* { id: 'c', stars: 20 },
|
|
158
|
-
* ];
|
|
158
|
+
* ] as const;
|
|
159
159
|
*
|
|
160
160
|
* const mostStars = Arr.maxBy(projects, (project) => project.stars);
|
|
161
161
|
*
|
|
@@ -318,7 +318,7 @@ export function countBy<E, G extends MapSetKeyType>(
|
|
|
318
318
|
* @example
|
|
319
319
|
*
|
|
320
320
|
* ```ts
|
|
321
|
-
* const words = ['Ada', 'Lovelace'];
|
|
321
|
+
* const words = ['Ada', 'Lovelace'] as const;
|
|
322
322
|
*
|
|
323
323
|
* const totalLength = Arr.foldl(words, (acc, word) => acc + word.length, 0);
|
|
324
324
|
*
|
|
@@ -395,7 +395,7 @@ export function foldl<E, P>(
|
|
|
395
395
|
* @example
|
|
396
396
|
*
|
|
397
397
|
* ```ts
|
|
398
|
-
* const numbers = [1, 2, 3];
|
|
398
|
+
* const numbers = [1, 2, 3] as const;
|
|
399
399
|
*
|
|
400
400
|
* const subtractRight = Arr.foldr(numbers, (acc, value) => acc - value, 0);
|
|
401
401
|
*
|
|
@@ -496,6 +496,7 @@ export function sum(array: readonly Int[]): Int;
|
|
|
496
496
|
export function sum(array: readonly number[]): number;
|
|
497
497
|
|
|
498
498
|
export function sum(array: readonly number[]): number {
|
|
499
|
+
// eslint-disable-next-line ts-data-forge/prefer-arr-sum
|
|
499
500
|
return array.reduce((prev, curr) => prev + curr, 0);
|
|
500
501
|
}
|
|
501
502
|
|
|
@@ -93,7 +93,7 @@ describe('Arr reducing value', () => {
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
test('case 3: readonly array', () => {
|
|
96
|
-
const arr: readonly number[] = [1, 5, 2];
|
|
96
|
+
const arr: readonly number[] = [1, 5, 2] as const;
|
|
97
97
|
|
|
98
98
|
const res = max(arr);
|
|
99
99
|
|
|
@@ -107,7 +107,7 @@ describe('Arr reducing value', () => {
|
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
test('case 4: empty array', () => {
|
|
110
|
-
const arr: readonly number[] = [];
|
|
110
|
+
const arr: readonly number[] = [] as const;
|
|
111
111
|
|
|
112
112
|
const res = max(arr);
|
|
113
113
|
|
|
@@ -152,7 +152,7 @@ describe('Arr reducing value', () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
test('case 2: empty array', () => {
|
|
155
|
-
const arr: readonly Readonly<{ x: number }>[] = [];
|
|
155
|
+
const arr: readonly Readonly<{ x: number }>[] = [] as const;
|
|
156
156
|
|
|
157
157
|
const res = minBy(arr, (a) => a.x);
|
|
158
158
|
|
|
@@ -228,7 +228,7 @@ describe('Arr reducing value', () => {
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
test('case 2: empty array', () => {
|
|
231
|
-
const arr: readonly Readonly<{ x: number }>[] = [];
|
|
231
|
+
const arr: readonly Readonly<{ x: number }>[] = [] as const;
|
|
232
232
|
|
|
233
233
|
const res = maxBy(arr, (a) => a.x);
|
|
234
234
|
|
|
@@ -288,7 +288,7 @@ describe('Arr reducing value', () => {
|
|
|
288
288
|
});
|
|
289
289
|
|
|
290
290
|
test('case 2: empty array', () => {
|
|
291
|
-
const arr: readonly number[] = [];
|
|
291
|
+
const arr: readonly number[] = [] as const;
|
|
292
292
|
|
|
293
293
|
const res = count(arr, (x) => x > 0);
|
|
294
294
|
|
|
@@ -332,7 +332,7 @@ describe('Arr reducing value', () => {
|
|
|
332
332
|
});
|
|
333
333
|
|
|
334
334
|
test('case 2: empty array', () => {
|
|
335
|
-
const arr: readonly Readonly<{ x: number }>[] = [];
|
|
335
|
+
const arr: readonly Readonly<{ x: number }>[] = [] as const;
|
|
336
336
|
|
|
337
337
|
const res = countBy(arr, (a) => a.x);
|
|
338
338
|
|
|
@@ -485,7 +485,7 @@ describe('Arr reducing value', () => {
|
|
|
485
485
|
|
|
486
486
|
describe(join, () => {
|
|
487
487
|
test('should join array elements', () => {
|
|
488
|
-
const arr = ['Hello', 'World'];
|
|
488
|
+
const arr = ['Hello', 'World'] as const;
|
|
489
489
|
|
|
490
490
|
const result = join(arr, ' ');
|
|
491
491
|
|
|
@@ -495,7 +495,7 @@ describe('Arr reducing value', () => {
|
|
|
495
495
|
});
|
|
496
496
|
|
|
497
497
|
test('should handle empty separator', () => {
|
|
498
|
-
const arr = ['a', 'b', 'c'];
|
|
498
|
+
const arr = ['a', 'b', 'c'] as const;
|
|
499
499
|
|
|
500
500
|
const result = join(arr, '');
|
|
501
501
|
|
|
@@ -505,7 +505,7 @@ describe('Arr reducing value', () => {
|
|
|
505
505
|
});
|
|
506
506
|
|
|
507
507
|
test('should handle undefined separator', () => {
|
|
508
|
-
const arr = ['a', 'b', 'c'];
|
|
508
|
+
const arr = ['a', 'b', 'c'] as const;
|
|
509
509
|
|
|
510
510
|
const result = join(arr);
|
|
511
511
|
|
|
@@ -11,7 +11,7 @@ import { asUint32 } from '../../number/index.mjs';
|
|
|
11
11
|
* const users = [
|
|
12
12
|
* { id: 1, name: 'Ada' },
|
|
13
13
|
* { id: 2, name: 'Grace' },
|
|
14
|
-
* ];
|
|
14
|
+
* ] as const;
|
|
15
15
|
*
|
|
16
16
|
* const found = Arr.find(users, (user) => user.id === 2);
|
|
17
17
|
*
|
|
@@ -100,7 +100,7 @@ export function find<E>(
|
|
|
100
100
|
* @example
|
|
101
101
|
*
|
|
102
102
|
* ```ts
|
|
103
|
-
* const numbers = [1, 3, 2, 4, 5];
|
|
103
|
+
* const numbers = [1, 3, 2, 4, 5] as const;
|
|
104
104
|
*
|
|
105
105
|
* const lastEven = Arr.findLast(numbers, (n) => n % 2 === 0);
|
|
106
106
|
*
|
|
@@ -187,7 +187,7 @@ export function findLast<E>(
|
|
|
187
187
|
* @example
|
|
188
188
|
*
|
|
189
189
|
* ```ts
|
|
190
|
-
* const letters = ['a', 'b', 'c'];
|
|
190
|
+
* const letters = ['a', 'b', 'c'] as const;
|
|
191
191
|
*
|
|
192
192
|
* const indexOfB = Arr.findIndex(letters, (letter) => letter === 'b');
|
|
193
193
|
*
|
|
@@ -254,7 +254,7 @@ export function findIndex<E>(
|
|
|
254
254
|
* @example
|
|
255
255
|
*
|
|
256
256
|
* ```ts
|
|
257
|
-
* const letters = ['a', 'b', 'c', 'b'];
|
|
257
|
+
* const letters = ['a', 'b', 'c', 'b'] as const;
|
|
258
258
|
*
|
|
259
259
|
* const lastIndexOfB = Arr.findLastIndex(letters, (letter) => letter === 'b');
|
|
260
260
|
*
|
|
@@ -321,7 +321,7 @@ export function findLastIndex<E>(
|
|
|
321
321
|
* @example
|
|
322
322
|
*
|
|
323
323
|
* ```ts
|
|
324
|
-
* const fruits = ['apple', 'banana', 'orange', 'banana'];
|
|
324
|
+
* const fruits = ['apple', 'banana', 'orange', 'banana'] as readonly string[];
|
|
325
325
|
*
|
|
326
326
|
* const indexOfBanana = Arr.indexOf(fruits, 'banana');
|
|
327
327
|
*
|
|
@@ -376,7 +376,7 @@ export function indexOf<E>(
|
|
|
376
376
|
* @example
|
|
377
377
|
*
|
|
378
378
|
* ```ts
|
|
379
|
-
* const fruits = ['apple', 'banana', 'orange', 'banana'];
|
|
379
|
+
* const fruits = ['apple', 'banana', 'orange', 'banana'] as readonly string[];
|
|
380
380
|
*
|
|
381
381
|
* // Search for 'banana' starting from index 1
|
|
382
382
|
* const firstBanana = Arr.indexOfFrom(fruits, 'banana', 1);
|
|
@@ -444,7 +444,7 @@ export function indexOfFrom<E>(
|
|
|
444
444
|
* @example
|
|
445
445
|
*
|
|
446
446
|
* ```ts
|
|
447
|
-
* const fruits = ['apple', 'banana', 'orange', 'banana'];
|
|
447
|
+
* const fruits = ['apple', 'banana', 'orange', 'banana'] as readonly string[];
|
|
448
448
|
*
|
|
449
449
|
* const lastBanana = Arr.lastIndexOf(fruits, 'banana');
|
|
450
450
|
*
|
|
@@ -503,7 +503,7 @@ export function lastIndexOf<E>(
|
|
|
503
503
|
* @example
|
|
504
504
|
*
|
|
505
505
|
* ```ts
|
|
506
|
-
* const fruits = ['apple', 'banana', 'orange', 'banana', 'grape'];
|
|
506
|
+
* const fruits = ['apple', 'banana', 'orange', 'banana', 'grape'] as const;
|
|
507
507
|
*
|
|
508
508
|
* // Search backwards for 'banana' from index 3
|
|
509
509
|
* const lastBananaFrom3 = Arr.lastIndexOfFrom(fruits, 'banana', 3);
|