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
package/src/others/index.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './cast-mutable.mjs';
|
|
2
2
|
export * from './cast-readonly.mjs';
|
|
3
3
|
export * from './debounce-function.mjs';
|
|
4
|
+
export * from './fast-deep-equal.mjs';
|
|
4
5
|
export * from './if-then.mjs';
|
|
5
6
|
export * from './map-nullable.mjs';
|
|
6
7
|
export * from './memoize-function.mjs';
|
|
@@ -37,7 +37,7 @@ describe(mapNullable, () => {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test('should work with complex transformations', () => {
|
|
40
|
-
const user = { name: 'Alice', age: 30 };
|
|
40
|
+
const user = { name: 'Alice', age: 30 } as const;
|
|
41
41
|
|
|
42
42
|
const result = mapNullable(
|
|
43
43
|
user,
|
|
@@ -48,13 +48,13 @@ describe(mapNullable, () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
test('should work with nullable object properties', () => {
|
|
51
|
-
const user: Readonly<{ name?: string }> = { name: 'Bob' };
|
|
51
|
+
const user: Readonly<{ name?: string }> = { name: 'Bob' } as const;
|
|
52
52
|
|
|
53
53
|
const result = mapNullable(user.name, (name) => name.toUpperCase());
|
|
54
54
|
|
|
55
55
|
expect(result).toBe('BOB');
|
|
56
56
|
|
|
57
|
-
const userWithoutName: Readonly<{ name?: string }> = {};
|
|
57
|
+
const userWithoutName: Readonly<{ name?: string }> = {} as const;
|
|
58
58
|
|
|
59
59
|
const resultEmpty = mapNullable(userWithoutName.name, (name) =>
|
|
60
60
|
name.toUpperCase(),
|
|
@@ -102,7 +102,7 @@ describe(mapNullable, () => {
|
|
|
102
102
|
(u: Readonly<{ name: string; age: number }>) => u.name,
|
|
103
103
|
);
|
|
104
104
|
|
|
105
|
-
const user = { name: 'Charlie', age: 25 };
|
|
105
|
+
const user = { name: 'Charlie', age: 25 } as const;
|
|
106
106
|
|
|
107
107
|
const result1 = getName(user);
|
|
108
108
|
|
|
@@ -201,7 +201,7 @@ describe(mapNullable, () => {
|
|
|
201
201
|
const data = {
|
|
202
202
|
user: { profile: { name: 'Alice' } },
|
|
203
203
|
settings: { theme: 'dark' },
|
|
204
|
-
};
|
|
204
|
+
} as const;
|
|
205
205
|
|
|
206
206
|
const result = mapNullable(data, (d) => d.user.profile.name);
|
|
207
207
|
|
|
@@ -277,7 +277,7 @@ describe(mapNullable, () => {
|
|
|
277
277
|
email: 'john@example.com',
|
|
278
278
|
},
|
|
279
279
|
},
|
|
280
|
-
};
|
|
280
|
+
} as const;
|
|
281
281
|
|
|
282
282
|
const extractUserName = mapNullable(
|
|
283
283
|
(r: ApiResponse) => r.data?.user?.name,
|
|
@@ -301,7 +301,7 @@ describe(mapNullable, () => {
|
|
|
301
301
|
const formData: FormDataType = {
|
|
302
302
|
email: 'test@example.com',
|
|
303
303
|
age: '25',
|
|
304
|
-
};
|
|
304
|
+
} as const;
|
|
305
305
|
|
|
306
306
|
const extractAge = mapNullable((data: FormDataType) => data.age);
|
|
307
307
|
|
|
@@ -331,7 +331,7 @@ describe(mapNullable, () => {
|
|
|
331
331
|
const incompleteFormData: FormDataType = {
|
|
332
332
|
email: 'test@example.com',
|
|
333
333
|
// age is missing
|
|
334
|
-
};
|
|
334
|
+
} as const;
|
|
335
335
|
|
|
336
336
|
const extractAge = mapNullable((data: FormDataType) => data.age);
|
|
337
337
|
|
|
@@ -65,11 +65,11 @@ describe(memoizeFunction, () => {
|
|
|
65
65
|
|
|
66
66
|
const memoized = memoizeFunction(mockFn, (user) => user.id);
|
|
67
67
|
|
|
68
|
-
const user1 = { id: 1, name: 'Alice' };
|
|
68
|
+
const user1 = { id: 1, name: 'Alice' } as const;
|
|
69
69
|
|
|
70
|
-
const user2 = { id: 1, name: 'Bob' }; // Same id, different name
|
|
70
|
+
const user2 = { id: 1, name: 'Bob' } as const; // Same id, different name
|
|
71
71
|
|
|
72
|
-
const user3 = { id: 2, name: 'Charlie' };
|
|
72
|
+
const user3 = { id: 2, name: 'Charlie' } as const;
|
|
73
73
|
|
|
74
74
|
expect(memoized(user1)).toBe('Hello Alice');
|
|
75
75
|
|
|
@@ -216,11 +216,23 @@ describe(memoizeFunction, () => {
|
|
|
216
216
|
(args) => `${args.category}:${args.subcategory}:${args.id}`,
|
|
217
217
|
);
|
|
218
218
|
|
|
219
|
-
const args1 = {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
const args1 = {
|
|
220
|
+
category: 'books',
|
|
221
|
+
subcategory: 'fiction',
|
|
222
|
+
id: 123,
|
|
223
|
+
} as const;
|
|
224
|
+
|
|
225
|
+
const args2 = {
|
|
226
|
+
category: 'books',
|
|
227
|
+
subcategory: 'fiction',
|
|
228
|
+
id: 123,
|
|
229
|
+
} as const;
|
|
230
|
+
|
|
231
|
+
const args3 = {
|
|
232
|
+
category: 'books',
|
|
233
|
+
subcategory: 'fiction',
|
|
234
|
+
id: 124,
|
|
235
|
+
} as const;
|
|
224
236
|
|
|
225
237
|
expect(memoized(args1)).toBe('books/fiction/123');
|
|
226
238
|
|
|
@@ -62,7 +62,7 @@ describe(unknownToString, () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
test('(args) => ({ ret: args })', () => {
|
|
65
|
-
const fn = (args: unknown): unknown => ({ ret: args });
|
|
65
|
+
const fn = (args: unknown): unknown => ({ ret: args }) as const;
|
|
66
66
|
|
|
67
67
|
expect(unknownToString(fn)).toBe('(args) => ({ ret: args })');
|
|
68
68
|
|
|
@@ -72,7 +72,7 @@ describe(unknownToString, () => {
|
|
|
72
72
|
|
|
73
73
|
describe('object', () => {
|
|
74
74
|
test('object', () => {
|
|
75
|
-
const obj = { a: { b: 1 } };
|
|
75
|
+
const obj = { a: { b: 1 } } as const;
|
|
76
76
|
|
|
77
77
|
expect(unknownToString(obj)).toBe('{"a":{"b":1}}');
|
|
78
78
|
|
|
@@ -80,7 +80,7 @@ describe(unknownToString, () => {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
test('object(prettyPrint=true)', () => {
|
|
83
|
-
const obj = { a: { b: 1 } };
|
|
83
|
+
const obj = { a: { b: 1 } } as const;
|
|
84
84
|
|
|
85
85
|
expect(unknownToString(obj, { prettyPrintObject: true })).toBe(
|
|
86
86
|
dedent`
|
|
@@ -95,7 +95,7 @@ describe(unknownToString, () => {
|
|
|
95
95
|
|
|
96
96
|
describe('array', () => {
|
|
97
97
|
test('array of primitives', () => {
|
|
98
|
-
const arr = [1, 2, 3, 'test', true];
|
|
98
|
+
const arr = [1, 2, 3, 'test', true] as const;
|
|
99
99
|
|
|
100
100
|
expect(unknownToString(arr)).toBe('[1,2,3,"test",true]');
|
|
101
101
|
|
|
@@ -103,7 +103,7 @@ describe(unknownToString, () => {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
test('array of objects', () => {
|
|
106
|
-
const arr = [{ a: 1 }, { b: 2 }];
|
|
106
|
+
const arr = [{ a: 1 }, { b: 2 }] as const;
|
|
107
107
|
|
|
108
108
|
expect(unknownToString(arr)).toBe('[{"a":1},{"b":2}]');
|
|
109
109
|
|
|
@@ -120,7 +120,7 @@ describe(unknownToString, () => {
|
|
|
120
120
|
const nestedArray = [
|
|
121
121
|
[1, 2],
|
|
122
122
|
[3, 4],
|
|
123
|
-
];
|
|
123
|
+
] as const;
|
|
124
124
|
|
|
125
125
|
expect(unknownToString(nestedArray)).toBe('[[1,2],[3,4]]');
|
|
126
126
|
|
|
@@ -128,7 +128,7 @@ describe(unknownToString, () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test('array with prettyPrint', () => {
|
|
131
|
-
const arr = [1, { a: 2 }, 3];
|
|
131
|
+
const arr = [1, { a: 2 }, 3] as const;
|
|
132
132
|
|
|
133
133
|
expect(
|
|
134
134
|
unknownToString(arr, {
|
|
@@ -288,7 +288,7 @@ describe(unknownToString, () => {
|
|
|
288
288
|
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
289
289
|
throw 'custom failure';
|
|
290
290
|
},
|
|
291
|
-
};
|
|
291
|
+
} as const;
|
|
292
292
|
|
|
293
293
|
expect(unknownToString(value)).toBe('[Circular or Non-serializable]');
|
|
294
294
|
});
|