ts-data-forge 1.5.1 → 2.0.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 +13 -1
- package/dist/array/array-utils.d.mts +693 -351
- package/dist/array/array-utils.d.mts.map +1 -1
- package/dist/array/array-utils.mjs +474 -1541
- package/dist/array/array-utils.mjs.map +1 -1
- package/dist/array/index.d.mts +0 -1
- package/dist/array/index.d.mts.map +1 -1
- package/dist/array/index.mjs +0 -1
- package/dist/array/index.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs +0 -1
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs +4 -5
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/functional/match.d.mts +2 -33
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs +2 -119
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional.d.mts +29 -51
- package/dist/functional/optional.d.mts.map +1 -1
- package/dist/functional/optional.mjs +40 -171
- package/dist/functional/optional.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -15
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs +2 -110
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result.d.mts +18 -45
- package/dist/functional/result.d.mts.map +1 -1
- package/dist/functional/result.mjs +40 -196
- package/dist/functional/result.mjs.map +1 -1
- package/dist/globals.d.mts +10 -9
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.d.mts +2 -6
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +2 -93
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.mjs +0 -1
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/num.d.mts +3 -6
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +4 -22
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +4 -10
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +8 -140
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.d.mts +2 -6
- package/dist/others/map-nullable.d.mts.map +1 -1
- package/dist/others/map-nullable.mjs +2 -146
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/package.json +12 -12
- package/src/array/array-utils-modification.test.mts +93 -67
- package/src/array/array-utils-overload-type-error.test.mts +2 -2
- package/src/array/array-utils-reducing-value.test.mts +31 -37
- package/src/array/array-utils-slice-clamped.test.mts +94 -70
- package/src/array/array-utils-transformation.test.mts +557 -10
- package/src/array/array-utils.mts +1835 -1000
- package/src/array/index.mts +0 -1
- package/src/collections/queue.mts +2 -2
- package/src/collections/stack.mts +8 -8
- package/src/functional/match.mts +18 -44
- package/src/functional/optional.mts +88 -102
- package/src/functional/pipe.mts +25 -20
- package/src/functional/result.mts +114 -124
- package/src/globals.d.mts +10 -9
- package/src/iterator/range.mts +14 -17
- package/src/number/num.mts +16 -12
- package/src/object/object.mts +30 -45
- package/src/others/map-nullable.mts +13 -15
- package/dist/array/tuple-utils.d.mts +0 -421
- package/dist/array/tuple-utils.d.mts.map +0 -1
- package/dist/array/tuple-utils.mjs +0 -391
- package/dist/array/tuple-utils.mjs.map +0 -1
- package/src/array/tuple-utils.mts +0 -519
- package/src/array/tuple-utils.test.mts +0 -518
|
@@ -3,81 +3,105 @@ import { Arr } from './array-utils.mjs';
|
|
|
3
3
|
|
|
4
4
|
describe('Arr', () => {
|
|
5
5
|
describe('sliceClamped', () => {
|
|
6
|
-
|
|
6
|
+
{
|
|
7
|
+
const list: readonly number[] = [0, 1, 2, 3, 4] as const;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
9
|
+
test.each([
|
|
10
|
+
{
|
|
11
|
+
start: 0,
|
|
12
|
+
end: 5,
|
|
13
|
+
expected: [0, 1, 2, 3, 4],
|
|
14
|
+
}, // normal
|
|
15
|
+
{
|
|
16
|
+
start: 0,
|
|
17
|
+
end: 5,
|
|
18
|
+
expected: [0, 1, 2, 3, 4],
|
|
19
|
+
}, // one side overflow
|
|
20
|
+
{
|
|
21
|
+
start: -1,
|
|
22
|
+
end: 5,
|
|
23
|
+
expected: [0, 1, 2, 3, 4],
|
|
24
|
+
}, // one side overflow
|
|
25
|
+
{
|
|
26
|
+
start: -1,
|
|
27
|
+
end: 6,
|
|
28
|
+
expected: [0, 1, 2, 3, 4],
|
|
29
|
+
}, // both sides overflow
|
|
30
|
+
{
|
|
31
|
+
start: 0,
|
|
32
|
+
end: 3,
|
|
33
|
+
expected: [0, 1, 2],
|
|
34
|
+
}, // normal
|
|
35
|
+
{
|
|
36
|
+
start: 1,
|
|
37
|
+
end: 3,
|
|
38
|
+
expected: [1, 2],
|
|
39
|
+
}, // normal
|
|
40
|
+
{
|
|
41
|
+
start: -1,
|
|
42
|
+
end: 3,
|
|
43
|
+
expected: [0, 1, 2],
|
|
44
|
+
}, // one side overflow
|
|
45
|
+
{
|
|
46
|
+
start: 3,
|
|
47
|
+
end: 5,
|
|
48
|
+
expected: [3, 4],
|
|
49
|
+
}, // normal
|
|
50
|
+
{
|
|
51
|
+
start: 4,
|
|
52
|
+
end: 3,
|
|
53
|
+
expected: [],
|
|
54
|
+
}, // start > end
|
|
55
|
+
{
|
|
56
|
+
start: 0,
|
|
57
|
+
end: -1,
|
|
58
|
+
expected: [],
|
|
59
|
+
}, // start > end
|
|
60
|
+
{
|
|
61
|
+
start: -1,
|
|
62
|
+
end: -2,
|
|
63
|
+
expected: [],
|
|
64
|
+
}, // start > end
|
|
65
|
+
{
|
|
66
|
+
start: 6,
|
|
67
|
+
end: 9,
|
|
68
|
+
expected: [],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
start: 6,
|
|
72
|
+
end: 3,
|
|
73
|
+
expected: [],
|
|
74
|
+
},
|
|
75
|
+
] as const)('sliceClamped($start, $end)', ({ start, end, expected }) => {
|
|
76
|
+
expect(Arr.sliceClamped(list, start, end)).toStrictEqual(expected);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
test('should be type error for index overflow for fixed length array', () => {
|
|
59
81
|
{
|
|
60
|
-
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
const array = [1, 2, 3, 4, 5] as const;
|
|
83
|
+
// @ts-expect-error end index is out of bounds
|
|
84
|
+
const result = Arr.sliceClamped(array, 0, 6);
|
|
85
|
+
expect(result).toStrictEqual(array);
|
|
86
|
+
}
|
|
64
87
|
{
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
const array = [1, 2, 3, 4, 5] as const;
|
|
89
|
+
// @ts-expect-error end index is out of bounds
|
|
90
|
+
const result = Arr.sliceClamped(array, 0, -6);
|
|
91
|
+
expect(result).toStrictEqual([]);
|
|
92
|
+
}
|
|
69
93
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
94
|
+
const array = [1, 2, 3, 4, 5] as const;
|
|
95
|
+
// @ts-expect-error start index is out of bounds
|
|
96
|
+
const result = Arr.sliceClamped(array, -6, 5);
|
|
97
|
+
expect(result).toStrictEqual(array);
|
|
98
|
+
}
|
|
74
99
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
expect(Arr.sliceClamped(list, start, end)).toStrictEqual(expected);
|
|
100
|
+
const array = [1, 2, 3, 4, 5] as const;
|
|
101
|
+
// @ts-expect-error start index is out of bounds
|
|
102
|
+
const result = Arr.sliceClamped(array, 6, 5);
|
|
103
|
+
expect(result).toStrictEqual([]);
|
|
104
|
+
}
|
|
81
105
|
});
|
|
82
106
|
|
|
83
107
|
test('should slice with clamped indices', () => {
|