ts-data-forge 7.0.0 → 7.1.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/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +1 -1
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +0 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +0 -2
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +0 -1
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +2 -4
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +41 -1
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +44 -10
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- package/dist/collections/imap-mapped.d.mts +622 -3
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +111 -18
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +3 -3
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +6 -5
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +4 -4
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +8 -4
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +2 -2
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +5 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs +20 -20
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs +17 -17
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +2 -2
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +2 -2
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +5 -3
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +1 -3
- 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 +1 -3
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -3
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/json/json.mjs +5 -7
- 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-arithmetic-types.d.mts.map +1 -1
- package/dist/number/num.mjs +3 -3
- package/dist/object/object.mjs +1 -1
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +0 -1
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs +2 -2
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/package.json +5 -5
- package/src/array/impl/array-utils-creation.mts +1 -1
- package/src/array/impl/array-utils-iterators.mts +1 -1
- package/src/array/impl/array-utils-reducing-value.mts +1 -2
- package/src/array/impl/array-utils-search.mts +0 -2
- package/src/array/impl/array-utils-set-op.mts +0 -1
- package/src/array/impl/array-utils-transformation.mts +8 -6
- package/src/array/impl/array-utils-validation.mts +57 -5
- package/src/array/impl/array-utils-validation.test.mts +160 -1
- package/src/collections/imap-mapped.mts +696 -34
- package/src/collections/imap-mapped.test.mts +61 -13
- package/src/collections/imap.mts +20 -9
- package/src/collections/imap.test.mts +9 -8
- package/src/collections/iset-mapped.mts +18 -10
- package/src/collections/iset-mapped.test.mts +6 -1
- package/src/collections/iset.mts +11 -4
- package/src/collections/iset.test.mts +6 -8
- package/src/collections/queue.mts +32 -32
- package/src/collections/stack.mts +26 -26
- package/src/functional/optional/impl/optional-flat-map.mts +2 -2
- package/src/functional/optional.test.mts +6 -4
- package/src/functional/pipe.mts +0 -1
- package/src/functional/pipe.test.mts +2 -1
- package/src/functional/result/impl/result-flat-map.mts +2 -2
- package/src/functional/result.test.mts +3 -2
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +5 -3
- package/src/functional/ternary-result.test.mts +8 -3
- package/src/guard/has-key.mts +1 -3
- package/src/guard/is-non-null-object.mts +0 -1
- package/src/guard/key-is-in.mts +1 -3
- package/src/json/json.mts +5 -8
- package/src/json/json.test.mts +2 -2
- 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-arithmetic-types.mts +0 -4
- package/src/number/num.mts +3 -3
- package/src/number/num.test.mts +2 -2
- package/src/object/object.mts +2 -2
- package/src/others/fast-deep-equal.mts +0 -2
- package/src/others/map-nullable.test.mts +4 -3
- package/src/others/unknown-to-string.mts +2 -2
|
@@ -12,9 +12,9 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
14
|
* const parseNumber = (input: string): Result<number, string> => {
|
|
15
|
-
* const num =
|
|
15
|
+
* const num = Num.safeParseInt(input);
|
|
16
16
|
*
|
|
17
|
-
* return
|
|
17
|
+
* return Result.mapErr(num, () => 'not a number');
|
|
18
18
|
* };
|
|
19
19
|
*
|
|
20
20
|
* const parsed = Result.flatMap(Result.ok('42'), parseNumber);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../expect-type.mjs';
|
|
2
|
+
import { Num } from '../number/index.mjs';
|
|
2
3
|
import { type Err, type Ok } from '../types.mjs';
|
|
3
4
|
import { Optional } from './optional/index.mjs';
|
|
4
5
|
import { pipe } from './pipe.mjs';
|
|
@@ -467,7 +468,7 @@ describe('Result test', () => {
|
|
|
467
468
|
|
|
468
469
|
test('should support chaining multiple flatMaps', () => {
|
|
469
470
|
const parseNumber = (s: string): Result<number, string> => {
|
|
470
|
-
const n =
|
|
471
|
+
const n = Result.unwrapOkOr(Num.safeParseFloat(s), Number.NaN);
|
|
471
472
|
|
|
472
473
|
return Number.isNaN(n) ? Result.err('Not a number') : Result.ok(n);
|
|
473
474
|
};
|
|
@@ -518,7 +519,7 @@ describe('Result test', () => {
|
|
|
518
519
|
|
|
519
520
|
test('should work with pipe when curried', () => {
|
|
520
521
|
const parseNumber = (s: string): Result<number, string> => {
|
|
521
|
-
const n =
|
|
522
|
+
const n = Result.unwrapOkOr(Num.safeParseFloat(s), Number.NaN);
|
|
522
523
|
|
|
523
524
|
return Number.isNaN(n) ? Result.err('Not a number') : Result.ok(n);
|
|
524
525
|
};
|
|
@@ -15,9 +15,11 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
15
15
|
*
|
|
16
16
|
* ```ts
|
|
17
17
|
* const parse = (value: string): TernaryResult<number, string, string> =>
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* pipe(Num.safeParseFloat(value)).map((result) =>
|
|
19
|
+
* Result.isErr(result)
|
|
20
|
+
* ? TernaryResult.err('NaN')
|
|
21
|
+
* : TernaryResult.ok(result.value),
|
|
22
|
+
* ).value;
|
|
21
23
|
*
|
|
22
24
|
* const doubled = TernaryResult.flatMap(TernaryResult.ok('3'), (text) =>
|
|
23
25
|
* TernaryResult.map(parse(text), (num) => num * 2),
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { expectType } from '../expect-type.mjs';
|
|
2
|
+
import { Num } from '../number/index.mjs';
|
|
2
3
|
import { Optional } from './optional/index.mjs';
|
|
4
|
+
import { pipe } from './pipe.mjs';
|
|
5
|
+
import { Result } from './result/index.mjs';
|
|
3
6
|
import { TernaryResult } from './ternary-result/index.mjs';
|
|
4
7
|
|
|
5
8
|
describe('TernaryResult test', () => {
|
|
@@ -69,9 +72,11 @@ describe('TernaryResult test', () => {
|
|
|
69
72
|
|
|
70
73
|
test('flatMap propagates Warn and Err while keeping warnings', () => {
|
|
71
74
|
const parse = (value: string): TernaryResult<number, string, never> =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
pipe(Num.safeParseFloat(value)).map((result) =>
|
|
76
|
+
Result.isErr(result)
|
|
77
|
+
? TernaryResult.err('NaN')
|
|
78
|
+
: TernaryResult.ok(result.value),
|
|
79
|
+
).value;
|
|
75
80
|
|
|
76
81
|
const warn = TernaryResult.warn('3', 'slow');
|
|
77
82
|
|
package/src/guard/has-key.mts
CHANGED
|
@@ -47,9 +47,7 @@ export const hasKey = <
|
|
|
47
47
|
>(
|
|
48
48
|
obj: R,
|
|
49
49
|
key: K,
|
|
50
|
-
): obj is HasKeyReturnType<R, K> =>
|
|
51
|
-
// eslint-disable-next-line ts-data-forge/prefer-is-record-and-has-key
|
|
52
|
-
Object.hasOwn(obj, key);
|
|
50
|
+
): obj is HasKeyReturnType<R, K> => Object.hasOwn(obj, key);
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* @internal
|
package/src/guard/key-is-in.mts
CHANGED
package/src/json/json.mts
CHANGED
|
@@ -350,18 +350,15 @@ const keysDeepImpl = (
|
|
|
350
350
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
351
351
|
mut_keys: string[],
|
|
352
352
|
): void => {
|
|
353
|
-
for (const k of Object.
|
|
353
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
354
354
|
mut_keys.push(k);
|
|
355
355
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (isRecord(o)) {
|
|
359
|
-
keysDeepImpl(o, mut_keys);
|
|
356
|
+
if (isRecord(v)) {
|
|
357
|
+
keysDeepImpl(v, mut_keys);
|
|
360
358
|
}
|
|
361
359
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
for (const li of o) {
|
|
360
|
+
if (Array.isArray(v)) {
|
|
361
|
+
for (const li of v) {
|
|
365
362
|
if (isRecord(li)) {
|
|
366
363
|
keysDeepImpl(li, mut_keys);
|
|
367
364
|
}
|
package/src/json/json.test.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Arr } from '../array/index.mjs';
|
|
2
2
|
import { Result } from '../functional/index.mjs';
|
|
3
3
|
import { hasKey, isRecord, isString } from '../guard/index.mjs';
|
|
4
|
+
import { Num } from '../number/index.mjs';
|
|
4
5
|
import { Json } from './json.mjs';
|
|
5
6
|
|
|
6
7
|
describe('parse', () => {
|
|
@@ -154,7 +155,7 @@ describe('parse', () => {
|
|
|
154
155
|
test('should handle reviver returning different types', () => {
|
|
155
156
|
const transformReviver = (key: string, value: unknown): unknown => {
|
|
156
157
|
if (key === 'number' && typeof value === 'string') {
|
|
157
|
-
return
|
|
158
|
+
return Result.unwrapOkOr(Num.safeParseInt(value), Number.NaN);
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
return value;
|
|
@@ -465,7 +466,6 @@ describe('stringifySelected', () => {
|
|
|
465
466
|
|
|
466
467
|
// Note: stringifySelected works with JSON.stringify's replacer parameter
|
|
467
468
|
// which may not work as expected with arrays
|
|
468
|
-
// eslint-disable-next-line ts-data-forge/prefer-arr-is-array
|
|
469
469
|
assert.isTrue(Array.isArray(parsed));
|
|
470
470
|
|
|
471
471
|
expect(parsed).toHaveLength(3);
|
|
@@ -31,9 +31,9 @@ const {
|
|
|
31
31
|
>({
|
|
32
32
|
integerOrSafeInteger: 'SafeInteger',
|
|
33
33
|
nonZero: true,
|
|
34
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer
|
|
34
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer
|
|
35
35
|
MIN_VALUE: Number.MIN_SAFE_INTEGER as SafeInt,
|
|
36
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
36
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
37
37
|
MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,
|
|
38
38
|
typeNameInMessage,
|
|
39
39
|
} as const);
|
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
>({
|
|
33
33
|
integerOrSafeInteger: 'SafeInteger',
|
|
34
34
|
MIN_VALUE: 1,
|
|
35
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
35
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
36
36
|
MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,
|
|
37
37
|
typeNameInMessage,
|
|
38
38
|
} as const);
|
|
@@ -32,9 +32,9 @@ const {
|
|
|
32
32
|
SafeUint
|
|
33
33
|
>({
|
|
34
34
|
integerOrSafeInteger: 'SafeInteger',
|
|
35
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer
|
|
35
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer
|
|
36
36
|
MIN_VALUE: Number.MIN_SAFE_INTEGER as SafeInt,
|
|
37
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
37
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
38
38
|
MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,
|
|
39
39
|
typeNameInMessage,
|
|
40
40
|
} as const);
|
|
@@ -29,7 +29,7 @@ const {
|
|
|
29
29
|
>({
|
|
30
30
|
integerOrSafeInteger: 'SafeInteger',
|
|
31
31
|
MIN_VALUE: 0,
|
|
32
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
32
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
33
33
|
MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,
|
|
34
34
|
typeNameInMessage,
|
|
35
35
|
} as const);
|
|
@@ -52,7 +52,6 @@ type Sign = 'any' | 'neg' | 'nonneg' | 'nonpos' | 'nonzero' | 'pos';
|
|
|
52
52
|
type Level = 'finite' | 'int' | 'number' | 'safeint';
|
|
53
53
|
|
|
54
54
|
/** Classifies a numeric type's sign. */
|
|
55
|
-
// transformer-ignore-next-line convert-to-readonly
|
|
56
55
|
export type SignOf<N> = [N] extends [PositiveNumber]
|
|
57
56
|
? 'pos'
|
|
58
57
|
: [N] extends [NegativeNumber]
|
|
@@ -66,7 +65,6 @@ export type SignOf<N> = [N] extends [PositiveNumber]
|
|
|
66
65
|
: 'any';
|
|
67
66
|
|
|
68
67
|
/** Classifies a numeric type's level. */
|
|
69
|
-
// transformer-ignore-next-line convert-to-readonly
|
|
70
68
|
export type LevelOf<N> = [N] extends [SafeInt]
|
|
71
69
|
? 'safeint'
|
|
72
70
|
: [N] extends [Int]
|
|
@@ -77,7 +75,6 @@ export type LevelOf<N> = [N] extends [SafeInt]
|
|
|
77
75
|
|
|
78
76
|
// --- boolean fact algebra over a sign ----------------------------------------
|
|
79
77
|
|
|
80
|
-
// transformer-ignore-next-line convert-to-readonly
|
|
81
78
|
type And<A extends boolean, B extends boolean> = [A, B] extends [true, true]
|
|
82
79
|
? true
|
|
83
80
|
: false;
|
|
@@ -171,7 +168,6 @@ type DivLevel<LA extends Level, LB extends Level> = 'number' extends LA | LB
|
|
|
171
168
|
: 'finite';
|
|
172
169
|
|
|
173
170
|
/** Floor division yields an integer; the safe range is preserved. */
|
|
174
|
-
// transformer-ignore-next-line convert-to-readonly
|
|
175
171
|
type DivIntLevel<LA extends Level, LB extends Level> = 'number' extends LA | LB
|
|
176
172
|
? 'number'
|
|
177
173
|
: [LA, LB] extends ['safeint', 'safeint']
|
package/src/number/num.mts
CHANGED
|
@@ -134,7 +134,7 @@ export namespace Num {
|
|
|
134
134
|
? Result.err(
|
|
135
135
|
new Error(`safeParseInt: "${s}" is not a valid base-10 integer`),
|
|
136
136
|
)
|
|
137
|
-
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
137
|
+
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
138
138
|
Result.ok(Math.trunc(viaNumber) as Int);
|
|
139
139
|
};
|
|
140
140
|
|
|
@@ -214,7 +214,7 @@ export namespace Num {
|
|
|
214
214
|
? Result.err(
|
|
215
215
|
new Error(`safeParseFloat: "${s}" is not a valid finite number`),
|
|
216
216
|
)
|
|
217
|
-
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
217
|
+
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
218
218
|
Result.ok(viaNumber as FiniteNumber);
|
|
219
219
|
};
|
|
220
220
|
|
|
@@ -649,7 +649,7 @@ export namespace Num {
|
|
|
649
649
|
* @param num - The number to round
|
|
650
650
|
* @returns The rounded integer as an Int branded type
|
|
651
651
|
*/
|
|
652
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
652
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
653
653
|
export const roundToInt = (num: number): Int => Math.trunc(num + 0.5) as Int;
|
|
654
654
|
|
|
655
655
|
/**
|
package/src/number/num.test.mts
CHANGED
|
@@ -164,7 +164,7 @@ describe('Num test', () => {
|
|
|
164
164
|
test('rejects empty / whitespace-only input (unlike Number)', () => {
|
|
165
165
|
assert.isTrue(Result.isErr(Num.safeParseInt('')));
|
|
166
166
|
|
|
167
|
-
assert.isTrue(Result.isErr(Num.safeParseInt('
|
|
167
|
+
assert.isTrue(Result.isErr(Num.safeParseInt(' '.repeat(3))));
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
test('rejects non-finite words', () => {
|
|
@@ -222,7 +222,7 @@ describe('Num test', () => {
|
|
|
222
222
|
test('rejects empty / whitespace-only input (unlike Number)', () => {
|
|
223
223
|
assert.isTrue(Result.isErr(Num.safeParseFloat('')));
|
|
224
224
|
|
|
225
|
-
assert.isTrue(Result.isErr(Num.safeParseFloat('
|
|
225
|
+
assert.isTrue(Result.isErr(Num.safeParseFloat(' '.repeat(3))));
|
|
226
226
|
});
|
|
227
227
|
|
|
228
228
|
test('rejects non-finite values', () => {
|
package/src/object/object.mts
CHANGED
|
@@ -505,10 +505,10 @@ const deepOmitImpl = (
|
|
|
505
505
|
|
|
506
506
|
const head = path[0];
|
|
507
507
|
|
|
508
|
-
const tail = path.slice(1);
|
|
509
|
-
|
|
510
508
|
if (!hasKey(record, head)) return record;
|
|
511
509
|
|
|
510
|
+
const tail = path.slice(1);
|
|
511
|
+
|
|
512
512
|
if (!Arr.isNonEmpty(tail)) {
|
|
513
513
|
return Object.fromEntries(
|
|
514
514
|
Object.entries(record).filter(([k]) => k !== head),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DeepReadonly } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../expect-type.mjs';
|
|
3
|
-
import { pipe } from '../functional/index.mjs';
|
|
3
|
+
import { pipe, Result } from '../functional/index.mjs';
|
|
4
|
+
import { Num } from '../number/index.mjs';
|
|
4
5
|
import { mapNullable } from './map-nullable.mjs';
|
|
5
6
|
|
|
6
7
|
describe(mapNullable, () => {
|
|
@@ -306,7 +307,7 @@ describe(mapNullable, () => {
|
|
|
306
307
|
const extractAge = mapNullable((data: FormDataType) => data.age);
|
|
307
308
|
|
|
308
309
|
const parseAge = mapNullable((ageStr: string) =>
|
|
309
|
-
|
|
310
|
+
Result.unwrapOkOr(Num.safeParseInt(ageStr), Number.NaN),
|
|
310
311
|
);
|
|
311
312
|
|
|
312
313
|
const validateAge = mapNullable((age: number) =>
|
|
@@ -336,7 +337,7 @@ describe(mapNullable, () => {
|
|
|
336
337
|
const extractAge = mapNullable((data: FormDataType) => data.age);
|
|
337
338
|
|
|
338
339
|
const parseAge = mapNullable((ageStr: string) =>
|
|
339
|
-
|
|
340
|
+
Result.unwrapOkOr(Num.safeParseInt(ageStr), Number.NaN),
|
|
340
341
|
);
|
|
341
342
|
|
|
342
343
|
const extractedAge = extractAge(incompleteFormData);
|
|
@@ -78,7 +78,7 @@ export const unknownToString = (
|
|
|
78
78
|
|
|
79
79
|
// Special handling for Map
|
|
80
80
|
if (isMap(value)) {
|
|
81
|
-
const entries = Array.from(value
|
|
81
|
+
const entries = Array.from(value);
|
|
82
82
|
|
|
83
83
|
const entriesStr = prettyPrintObject
|
|
84
84
|
? JSON.stringify(entries, undefined, 2)
|
|
@@ -89,7 +89,7 @@ export const unknownToString = (
|
|
|
89
89
|
|
|
90
90
|
// Special handling for Set
|
|
91
91
|
if (isSet(value)) {
|
|
92
|
-
const values = Array.from(value
|
|
92
|
+
const values = Array.from(value);
|
|
93
93
|
|
|
94
94
|
const valuesStr = prettyPrintObject
|
|
95
95
|
? JSON.stringify(values, undefined, 2)
|