ts-data-forge 5.1.0 → 5.1.1
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 +46 -44
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +8 -8
- package/dist/array/impl/array-utils-search.d.mts +4 -4
- package/dist/array/impl/array-utils-set-op.d.mts +7 -7
- package/dist/array/impl/array-utils-set-op.mjs +7 -7
- package/dist/array/impl/array-utils-size.d.mts +2 -2
- package/dist/array/impl/array-utils-size.mjs +2 -2
- package/dist/array/impl/array-utils-slicing.d.mts +2 -2
- package/dist/array/impl/array-utils-slicing.mjs +2 -2
- package/dist/array/impl/array-utils-validation.d.mts +18 -18
- package/dist/array/impl/array-utils-validation.mjs +14 -14
- package/dist/collections/imap.d.mts +15 -15
- package/dist/collections/imap.mjs +3 -3
- package/dist/collections/iset-mapped.d.mts +19 -19
- package/dist/collections/iset-mapped.mjs +2 -2
- package/dist/collections/iset.d.mts +19 -19
- package/dist/collections/iset.mjs +2 -2
- package/dist/collections/queue.d.mts +25 -25
- package/dist/collections/queue.mjs +5 -5
- package/dist/collections/stack.d.mts +25 -25
- package/dist/collections/stack.mjs +5 -5
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +2 -2
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +2 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs +2 -2
- package/dist/functional/optional/impl/optional-is-some.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +2 -2
- package/dist/functional/optional/impl/optional-none.mjs +2 -2
- package/dist/functional/optional/impl/optional-some.d.mts +2 -2
- package/dist/functional/optional/impl/optional-some.mjs +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs +2 -2
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +4 -4
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +2 -2
- package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +1 -1
- package/dist/functional/result/impl/result-err.mjs +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +2 -2
- package/dist/functional/result/impl/result-from-promise.d.mts +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +2 -2
- package/dist/functional/result/impl/result-is-err.mjs +2 -2
- package/dist/functional/result/impl/result-is-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-is-ok.mjs +2 -2
- package/dist/functional/result/impl/result-is-result.d.mts +3 -3
- package/dist/functional/result/impl/result-is-result.mjs +3 -3
- package/dist/functional/result/impl/result-ok.d.mts +1 -1
- package/dist/functional/result/impl/result-ok.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs +2 -2
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +3 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +3 -3
- package/dist/globals.d.mts +2 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/key-is-in.d.mts +2 -2
- package/dist/guard/key-is-in.mjs +2 -2
- package/dist/json/json.d.mts +21 -21
- package/dist/json/json.mjs +21 -21
- package/dist/number/branded-types/int.d.mts +19 -19
- package/dist/number/branded-types/int.mjs +19 -19
- package/dist/number/branded-types/positive-int.d.mts +20 -20
- package/dist/number/branded-types/positive-int.mjs +20 -20
- package/dist/number/branded-types/positive-safe-int.d.mts +26 -26
- package/dist/number/branded-types/positive-safe-int.mjs +26 -26
- package/dist/number/branded-types/safe-int.d.mts +27 -27
- package/dist/number/branded-types/safe-int.mjs +27 -27
- package/dist/number/branded-types/uint.d.mts +19 -19
- package/dist/number/branded-types/uint.mjs +19 -19
- package/dist/number/num.d.mts +20 -20
- package/dist/number/num.mjs +16 -16
- package/dist/number/refined-number-utils.d.mts +11 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +11 -11
- package/dist/object/object.d.mts +3 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +3 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/tuple.d.mts +3 -3
- package/dist/others/tuple.mjs +3 -3
- package/dist/promise/promise.d.mts +4 -4
- package/dist/promise/promise.mjs +4 -4
- package/package.json +15 -13
- package/src/array/impl/array-utils-creation.test.mts +1 -1
- package/src/array/impl/array-utils-element-access.test.mts +16 -16
- package/src/array/impl/array-utils-modification.mts +38 -19
- package/src/array/impl/array-utils-reducing-value.mts +8 -8
- package/src/array/impl/array-utils-reducing-value.test.mts +23 -31
- package/src/array/impl/array-utils-search.mts +4 -4
- package/src/array/impl/array-utils-search.test.mts +10 -10
- package/src/array/impl/array-utils-set-op.mts +7 -7
- package/src/array/impl/array-utils-set-op.test.mts +13 -13
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +2 -2
- package/src/array/impl/array-utils-transformation.test.mts +2 -2
- package/src/array/impl/array-utils-validation.mts +18 -18
- package/src/array/impl/array-utils-validation.test.mts +80 -78
- package/src/array/impl/array.test.mts +6 -6
- package/src/collections/imap-mapped.test.mts +16 -18
- package/src/collections/imap.mts +15 -15
- package/src/collections/imap.test.mts +31 -31
- package/src/collections/iset-mapped.mts +19 -19
- package/src/collections/iset-mapped.test.mts +52 -52
- package/src/collections/iset.mts +19 -19
- package/src/collections/iset.test.mts +130 -130
- package/src/collections/queue.mts +25 -25
- package/src/collections/queue.test.mts +33 -35
- package/src/collections/stack.mts +25 -25
- package/src/collections/stack.test.mts +15 -15
- package/src/functional/match.mts +1 -1
- package/src/functional/optional/impl/optional-expect-to-be.mts +2 -2
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +2 -2
- package/src/functional/optional/impl/optional-is-some.mts +1 -1
- package/src/functional/optional/impl/optional-none.mts +2 -2
- package/src/functional/optional/impl/optional-some.mts +2 -2
- package/src/functional/optional/impl/optional-to-nullable.mts +2 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +4 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +1 -1
- package/src/functional/optional/impl/optional-unwrap.mts +2 -2
- package/src/functional/optional/impl/optional-zip.mts +1 -1
- package/src/functional/optional.test.mts +53 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +4 -4
- package/src/functional/result/impl/result-err.mts +1 -1
- package/src/functional/result/impl/result-expect-to-be.mts +2 -2
- package/src/functional/result/impl/result-from-promise.mts +1 -1
- package/src/functional/result/impl/result-from-throwable.mts +1 -1
- package/src/functional/result/impl/result-is-err.mts +2 -2
- package/src/functional/result/impl/result-is-ok.mts +2 -2
- package/src/functional/result/impl/result-is-result.mts +3 -3
- package/src/functional/result/impl/result-ok.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err.mts +2 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +2 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +1 -1
- package/src/functional/result.test.mts +94 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +3 -3
- package/src/functional/ternary-result.test.mts +8 -8
- package/src/globals.d.mts +2 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +0 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +24 -24
- package/src/guard/is-non-null-object.test.mts +26 -26
- package/src/guard/is-primitive.test.mts +28 -28
- package/src/guard/is-record.test.mts +7 -7
- package/src/guard/is-type.test.mts +151 -155
- package/src/guard/key-is-in.mts +2 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/json/json.mts +21 -21
- package/src/json/json.test.mts +135 -174
- package/src/number/branded-types/finite-number.test.mts +13 -11
- package/src/number/branded-types/int.mts +19 -19
- package/src/number/branded-types/int.test.mts +14 -14
- package/src/number/branded-types/int16.test.mts +16 -16
- package/src/number/branded-types/int32.test.mts +16 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +12 -12
- package/src/number/branded-types/non-negative-int16.test.mts +16 -16
- package/src/number/branded-types/non-negative-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +14 -14
- package/src/number/branded-types/non-zero-int.test.mts +19 -19
- package/src/number/branded-types/non-zero-int16.test.mts +16 -16
- package/src/number/branded-types/non-zero-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-safe-int.test.mts +23 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +16 -16
- package/src/number/branded-types/positive-finite-number.test.mts +14 -14
- package/src/number/branded-types/positive-int.mts +20 -20
- package/src/number/branded-types/positive-int.test.mts +17 -17
- package/src/number/branded-types/positive-int16.test.mts +15 -15
- package/src/number/branded-types/positive-int32.test.mts +15 -15
- package/src/number/branded-types/positive-safe-int.mts +26 -26
- package/src/number/branded-types/positive-safe-int.test.mts +19 -19
- package/src/number/branded-types/positive-uint16.test.mts +16 -16
- package/src/number/branded-types/positive-uint32.test.mts +16 -16
- package/src/number/branded-types/safe-int.mts +27 -27
- package/src/number/branded-types/safe-int.test.mts +18 -18
- package/src/number/branded-types/safe-uint.test.mts +17 -17
- package/src/number/branded-types/uint.mts +19 -19
- package/src/number/branded-types/uint.test.mts +15 -15
- package/src/number/branded-types/uint16.test.mts +15 -15
- package/src/number/branded-types/uint32.test.mts +15 -15
- package/src/number/enum/int8.test.mts +1 -1
- package/src/number/enum/uint8.test.mts +1 -1
- package/src/number/num.mts +20 -20
- package/src/number/num.test.mts +26 -26
- package/src/number/refined-number-utils.mts +13 -13
- package/src/object/object.mts +4 -3
- package/src/object/object.test.mts +6 -6
- package/src/others/cast-mutable.test.mts +1 -1
- package/src/others/cast-readonly.test.mts +4 -4
- package/src/others/if-then.test.mts +24 -24
- package/src/others/tuple.mts +3 -3
- package/src/promise/promise.mts +4 -4
- package/src/promise/promise.test.mts +7 -13
|
@@ -10,15 +10,15 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* const errResult = Result.err('failure');
|
|
12
12
|
*
|
|
13
|
-
* assert(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
13
|
+
* assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
14
14
|
*
|
|
15
|
-
* assert(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
15
|
+
* assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
16
16
|
*
|
|
17
17
|
* const unwrapError = Result.unwrapErrOr('fallback error');
|
|
18
18
|
*
|
|
19
|
-
* assert(unwrapError(Result.err('boom')) === 'boom');
|
|
19
|
+
* assert.isTrue(unwrapError(Result.err('boom')) === 'boom');
|
|
20
20
|
*
|
|
21
|
-
* assert(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
21
|
+
* assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
24
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -14,7 +14,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
14
14
|
*
|
|
15
15
|
* const okResult = Result.ok('value');
|
|
16
16
|
*
|
|
17
|
-
* assert(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
17
|
+
* assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
18
18
|
*
|
|
19
19
|
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
20
20
|
* ```
|
|
@@ -17,7 +17,7 @@ import { isErr } from './result-is-err.mjs';
|
|
|
17
17
|
*
|
|
18
18
|
* const okResult = Result.ok('value');
|
|
19
19
|
*
|
|
20
|
-
* assert(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
20
|
+
* assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
21
21
|
*
|
|
22
22
|
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
23
23
|
* ```
|
|
@@ -17,11 +17,11 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
17
17
|
* // Result.unwrapErr returns undefined for Ok results
|
|
18
18
|
*
|
|
19
19
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
20
|
-
* assert(Result.unwrapErr(okResult) === undefined);
|
|
20
|
+
* assert.isTrue(Result.unwrapErr(okResult) === undefined);
|
|
21
21
|
*
|
|
22
22
|
* // Result.unwrapErr returns the error value for Err results
|
|
23
23
|
*
|
|
24
|
-
* assert(Result.unwrapErr(errResult) === 'problem');
|
|
24
|
+
* assert.isTrue(Result.unwrapErr(errResult) === 'problem');
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
27
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -18,11 +18,11 @@ import { isErr } from './result-is-err.mjs';
|
|
|
18
18
|
* // Result.unwrapErr returns undefined for Ok results
|
|
19
19
|
*
|
|
20
20
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
21
|
-
* assert(Result.unwrapErr(okResult) === undefined);
|
|
21
|
+
* assert.isTrue(Result.unwrapErr(okResult) === undefined);
|
|
22
22
|
*
|
|
23
23
|
* // Result.unwrapErr returns the error value for Err results
|
|
24
24
|
*
|
|
25
|
-
* assert(Result.unwrapErr(errResult) === 'problem');
|
|
25
|
+
* assert.isTrue(Result.unwrapErr(errResult) === 'problem');
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
28
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -10,15 +10,15 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* const errValue = Result.err('fail');
|
|
12
12
|
*
|
|
13
|
-
* assert(Result.unwrapOkOr(okValue, 0) === 10);
|
|
13
|
+
* assert.isTrue(Result.unwrapOkOr(okValue, 0) === 10);
|
|
14
14
|
*
|
|
15
|
-
* assert(Result.unwrapOkOr(errValue, 0) === 0);
|
|
15
|
+
* assert.isTrue(Result.unwrapOkOr(errValue, 0) === 0);
|
|
16
16
|
*
|
|
17
17
|
* const unwrapWithDefault = Result.unwrapOkOr(5);
|
|
18
18
|
*
|
|
19
|
-
* assert(unwrapWithDefault(Result.ok(3)) === 3);
|
|
19
|
+
* assert.isTrue(unwrapWithDefault(Result.ok(3)) === 3);
|
|
20
20
|
*
|
|
21
|
-
* assert(unwrapWithDefault(Result.err('no data')) === 5);
|
|
21
|
+
* assert.isTrue(unwrapWithDefault(Result.err('no data')) === 5);
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
24
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -11,12 +11,12 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* // Result.unwrapOk returns the value for Ok results
|
|
13
13
|
*
|
|
14
|
-
* assert(Result.unwrapOk(okResult) === 42);
|
|
14
|
+
* assert.isTrue(Result.unwrapOk(okResult) === 42);
|
|
15
15
|
*
|
|
16
16
|
* // Result.unwrapOk returns undefined for Err results
|
|
17
17
|
*
|
|
18
18
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
19
|
-
* assert(Result.unwrapOk(errResult) === undefined);
|
|
19
|
+
* assert.isTrue(Result.unwrapOk(errResult) === undefined);
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
export declare function unwrapOk<R extends Ok<unknown>>(result: R): UnwrapOk<R>;
|
|
@@ -15,7 +15,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
15
15
|
*
|
|
16
16
|
* const errResult = Result.err(new Error('fail'));
|
|
17
17
|
*
|
|
18
|
-
* assert(Result.unwrapThrow(okResult) === 'data');
|
|
18
|
+
* assert.isTrue(Result.unwrapThrow(okResult) === 'data');
|
|
19
19
|
*
|
|
20
20
|
* assert.throws(() => Result.unwrapThrow(errResult), /fail/u);
|
|
21
21
|
* ```
|
|
@@ -17,7 +17,7 @@ import { isErr } from './result-is-err.mjs';
|
|
|
17
17
|
*
|
|
18
18
|
* const errResult = Result.err(new Error('fail'));
|
|
19
19
|
*
|
|
20
|
-
* assert(Result.unwrapThrow(okResult) === 'data');
|
|
20
|
+
* assert.isTrue(Result.unwrapThrow(okResult) === 'data');
|
|
21
21
|
*
|
|
22
22
|
* assert.throws(() => Result.unwrapThrow(errResult), /fail/u);
|
|
23
23
|
* ```
|
|
@@ -10,7 +10,7 @@ import { ErrTypeTagName } from './tag.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(TernaryResult.isErr(failure));
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
const err = (value) => ({
|
|
@@ -14,7 +14,7 @@ type UnwrapPromise<P extends Promise<unknown>> = P extends Promise<infer V> ? V
|
|
|
14
14
|
*
|
|
15
15
|
* assert.deepStrictEqual(resolved, TernaryResult.ok('ok'));
|
|
16
16
|
*
|
|
17
|
-
* assert.
|
|
17
|
+
* assert.isTrue(TernaryResult.isErr(rejected));
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export declare const fromPromise: <P extends Promise<unknown>>(promise: P) => Promise<TernaryResult<UnwrapPromise<P>, unknown, never>>;
|
|
@@ -15,7 +15,7 @@ import { ok } from './ternary-result-ok.mjs';
|
|
|
15
15
|
*
|
|
16
16
|
* assert.deepStrictEqual(resolved, TernaryResult.ok('ok'));
|
|
17
17
|
*
|
|
18
|
-
* assert.
|
|
18
|
+
* assert.isTrue(TernaryResult.isErr(rejected));
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
const fromPromise = (promise) =>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* assert.deepStrictEqual(success, TernaryResult.ok(2));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isTrue(TernaryResult.isErr(failure));
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare const fromThrowable: <T>(fn: () => T) => TernaryResult<T, Error, never>;
|
|
@@ -17,7 +17,7 @@ import { ok } from './ternary-result-ok.mjs';
|
|
|
17
17
|
*
|
|
18
18
|
* assert.deepStrictEqual(success, TernaryResult.ok(2));
|
|
19
19
|
*
|
|
20
|
-
* assert.
|
|
20
|
+
* assert.isTrue(TernaryResult.isErr(failure));
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
const fromThrowable = (fn) => {
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
*
|
|
11
11
|
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(TernaryResult.isTernaryResult(okValue));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isTrue(TernaryResult.isTernaryResult(warnValue));
|
|
16
16
|
*
|
|
17
|
-
* assert.
|
|
17
|
+
* assert.isFalse(TernaryResult.isTernaryResult(notResult));
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export declare const isTernaryResult: (maybeResult: unknown) => maybeResult is UnknownTernaryResult;
|
|
@@ -14,11 +14,11 @@ import { WarnTypeTagName, OkTypeTagName, ErrTypeTagName } from './tag.mjs';
|
|
|
14
14
|
*
|
|
15
15
|
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
16
16
|
*
|
|
17
|
-
* assert.
|
|
17
|
+
* assert.isTrue(TernaryResult.isTernaryResult(okValue));
|
|
18
18
|
*
|
|
19
|
-
* assert.
|
|
19
|
+
* assert.isTrue(TernaryResult.isTernaryResult(warnValue));
|
|
20
20
|
*
|
|
21
|
-
* assert.
|
|
21
|
+
* assert.isFalse(TernaryResult.isTernaryResult(notResult));
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
const isTernaryResult = (maybeResult) => isRecord(maybeResult) &&
|
package/dist/globals.d.mts
CHANGED
|
@@ -13,7 +13,8 @@ type ArgArrayIndex<Ar extends readonly unknown[]> =
|
|
|
13
13
|
|
|
14
14
|
type ArgArrayIndexWithNegative<Ar extends readonly unknown[]> =
|
|
15
15
|
IsFixedLengthList<Ar> extends true
|
|
16
|
-
?
|
|
16
|
+
? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
17
|
+
IndexOfTuple<[...Ar, 0]> | NegativeIndexOfTuple<Ar>
|
|
17
18
|
: SizeType.ArgArrWithNegative;
|
|
18
19
|
|
|
19
20
|
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/length
|
package/dist/guard/has-key.d.mts
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
*
|
|
22
22
|
* if (hasKey(maybeUser, 'id')) {
|
|
23
23
|
* // `maybeUser` is now known to have an `id` property.
|
|
24
|
-
* assert(maybeUser.id === 42);
|
|
24
|
+
* assert.isTrue(maybeUser.id === 42);
|
|
25
25
|
* } else {
|
|
26
|
-
* assert.fail(
|
|
26
|
+
* assert.fail();
|
|
27
27
|
* }
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
@@ -45,5 +45,8 @@ export declare const hasKey: <const R extends UnknownRecord, const K extends Pro
|
|
|
45
45
|
* If none of the elements in the union contain K as a key, returns `ReadonlyRecord<K, unknown>`.
|
|
46
46
|
* The result is made readonly.
|
|
47
47
|
*/
|
|
48
|
-
export type HasKeyReturnType<R extends UnknownRecord, K extends PropertyKey> = R extends R ? K extends keyof R ? string extends keyof R ?
|
|
48
|
+
export type HasKeyReturnType<R extends UnknownRecord, K extends PropertyKey> = R extends R ? K extends keyof R ? string extends keyof R ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
49
|
+
ReadonlyRecord<K, R[keyof R]> & R : number extends keyof R ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
50
|
+
ReadonlyRecord<K, R[keyof R]> & R : symbol extends keyof R ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
51
|
+
ReadonlyRecord<K, R[keyof R]> & R : R : never : never;
|
|
49
52
|
//# sourceMappingURL=has-key.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-key.d.mts","sourceRoot":"","sources":["../../src/guard/has-key.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC7B,KAAK,CAAC,CAAC,SAAS,WAAW,EAE3B,KAAK,CAAC,EACN,KAAK,CAAC,KACL,GAAG,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAA4B,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,WAAW,IACnB,CAAC,SAAS,CAAC,GACX,CAAC,SAAS,MAAM,CAAC,GACf,MAAM,SAAS,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"has-key.d.mts","sourceRoot":"","sources":["../../src/guard/has-key.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC7B,KAAK,CAAC,CAAC,SAAS,WAAW,EAE3B,KAAK,CAAC,EACN,KAAK,CAAC,KACL,GAAG,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAA4B,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,WAAW,IACnB,CAAC,SAAS,CAAC,GACX,CAAC,SAAS,MAAM,CAAC,GACf,MAAM,SAAS,MAAM,CAAC,GAEpB,AADA,6EAA6E;AAC7E,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GACjC,MAAM,SAAS,MAAM,CAAC,GAEpB,AADA,6EAA6E;AAC7E,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GACjC,MAAM,SAAS,MAAM,CAAC,GAEpB,AADA,6EAA6E;AAC7E,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GACjC,CAAC,GACP,KAAK,GACP,KAAK,CAAC"}
|
package/dist/guard/has-key.mjs
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
*
|
|
22
22
|
* if (hasKey(maybeUser, 'id')) {
|
|
23
23
|
* // `maybeUser` is now known to have an `id` property.
|
|
24
|
-
* assert(maybeUser.id === 42);
|
|
24
|
+
* assert.isTrue(maybeUser.id === 42);
|
|
25
25
|
* } else {
|
|
26
|
-
* assert.fail(
|
|
26
|
+
* assert.fail();
|
|
27
27
|
* }
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
* const maybeKey: string = 'name';
|
|
24
24
|
*
|
|
25
25
|
* if (keyIsIn(maybeKey, user)) {
|
|
26
|
-
* assert(user[maybeKey] === 'Ada');
|
|
26
|
+
* assert.isTrue(user[maybeKey] === 'Ada');
|
|
27
27
|
* } else {
|
|
28
|
-
* assert.fail(
|
|
28
|
+
* assert.fail();
|
|
29
29
|
* }
|
|
30
30
|
* ```
|
|
31
31
|
*
|
package/dist/guard/key-is-in.mjs
CHANGED
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
* const maybeKey: string = 'name';
|
|
24
24
|
*
|
|
25
25
|
* if (keyIsIn(maybeKey, user)) {
|
|
26
|
-
* assert(user[maybeKey] === 'Ada');
|
|
26
|
+
* assert.isTrue(user[maybeKey] === 'Ada');
|
|
27
27
|
* } else {
|
|
28
|
-
* assert.fail(
|
|
28
|
+
* assert.fail();
|
|
29
29
|
* }
|
|
30
30
|
* ```
|
|
31
31
|
*
|
package/dist/json/json.d.mts
CHANGED
|
@@ -23,13 +23,13 @@ export declare namespace Json {
|
|
|
23
23
|
*
|
|
24
24
|
* const failed = Json.parse(invalidJson);
|
|
25
25
|
*
|
|
26
|
-
* assert.
|
|
26
|
+
* assert.isTrue(Result.isOk(parsed));
|
|
27
27
|
*
|
|
28
28
|
* if (Result.isOk(parsed)) {
|
|
29
29
|
* assert.deepStrictEqual(parsed.value, { name: 'Alice', age: 30 });
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
32
|
-
* assert.
|
|
32
|
+
* assert.isTrue(Result.isErr(failed));
|
|
33
33
|
*
|
|
34
34
|
* // With reviver
|
|
35
35
|
* const jsonWithDate = '{"created": "2024-01-01T00:00:00.000Z"}';
|
|
@@ -42,7 +42,7 @@ export declare namespace Json {
|
|
|
42
42
|
* return value;
|
|
43
43
|
* });
|
|
44
44
|
*
|
|
45
|
-
* assert.
|
|
45
|
+
* assert.isTrue(Result.isOk(withReviver));
|
|
46
46
|
* ```
|
|
47
47
|
*
|
|
48
48
|
* @param text - A valid JSON string to parse. Can contain any valid JSON data
|
|
@@ -75,16 +75,16 @@ export declare namespace Json {
|
|
|
75
75
|
* // Basic stringify
|
|
76
76
|
* const basic = Json.stringify(data);
|
|
77
77
|
*
|
|
78
|
-
* assert.
|
|
78
|
+
* assert.isTrue(Result.isOk(basic));
|
|
79
79
|
*
|
|
80
80
|
* if (Result.isOk(basic)) {
|
|
81
|
-
* assert(basic.value === '{"name":"Bob","age":25,"active":true}');
|
|
81
|
+
* assert.isTrue(basic.value === '{"name":"Bob","age":25,"active":true}');
|
|
82
82
|
* }
|
|
83
83
|
*
|
|
84
84
|
* // With formatting
|
|
85
85
|
* const formatted = Json.stringify(data, undefined, 2);
|
|
86
86
|
*
|
|
87
|
-
* assert.
|
|
87
|
+
* assert.isTrue(Result.isOk(formatted));
|
|
88
88
|
*
|
|
89
89
|
* // With replacer
|
|
90
90
|
* const filtered = Json.stringify(data, (key, value) => {
|
|
@@ -93,12 +93,12 @@ export declare namespace Json {
|
|
|
93
93
|
* return value;
|
|
94
94
|
* });
|
|
95
95
|
*
|
|
96
|
-
* assert.
|
|
96
|
+
* assert.isTrue(Result.isOk(filtered));
|
|
97
97
|
*
|
|
98
98
|
* if (Result.isOk(filtered)) {
|
|
99
|
-
* assert(isString(filtered.value));
|
|
99
|
+
* assert.isTrue(isString(filtered.value));
|
|
100
100
|
*
|
|
101
|
-
* assert.
|
|
101
|
+
* assert.isFalse(filtered.value.includes('age'));
|
|
102
102
|
* }
|
|
103
103
|
* ```
|
|
104
104
|
*
|
|
@@ -146,10 +146,10 @@ export declare namespace Json {
|
|
|
146
146
|
* // Select only safe properties to serialize
|
|
147
147
|
* const safeJson = Json.stringifySelected(user, ['id', 'name', 'role']);
|
|
148
148
|
*
|
|
149
|
-
* assert.
|
|
149
|
+
* assert.isTrue(Result.isOk(safeJson));
|
|
150
150
|
*
|
|
151
151
|
* if (Result.isOk(safeJson)) {
|
|
152
|
-
* assert(isString(safeJson.value));
|
|
152
|
+
* assert.isTrue(isString(safeJson.value));
|
|
153
153
|
*
|
|
154
154
|
* const parsed: unknown = JSON.parse(safeJson.value);
|
|
155
155
|
*
|
|
@@ -159,15 +159,15 @@ export declare namespace Json {
|
|
|
159
159
|
* role: 'admin',
|
|
160
160
|
* });
|
|
161
161
|
*
|
|
162
|
-
* assert.
|
|
162
|
+
* assert.isFalse(safeJson.value.includes('password'));
|
|
163
163
|
*
|
|
164
|
-
* assert.
|
|
164
|
+
* assert.isFalse(safeJson.value.includes('email'));
|
|
165
165
|
* }
|
|
166
166
|
*
|
|
167
167
|
* // With formatting
|
|
168
168
|
* const formatted = Json.stringifySelected(user, ['id', 'name'], 2);
|
|
169
169
|
*
|
|
170
|
-
* assert.
|
|
170
|
+
* assert.isTrue(Result.isOk(formatted));
|
|
171
171
|
* ```
|
|
172
172
|
*
|
|
173
173
|
* @param value - The JavaScript value to serialize. While any value is
|
|
@@ -216,34 +216,34 @@ export declare namespace Json {
|
|
|
216
216
|
* // Keys will be sorted alphabetically at all levels
|
|
217
217
|
* const sorted = Json.stringifySortedKey(unorderedData);
|
|
218
218
|
*
|
|
219
|
-
* assert.
|
|
219
|
+
* assert.isTrue(Result.isOk(sorted));
|
|
220
220
|
*
|
|
221
221
|
* if (Result.isOk(sorted)) {
|
|
222
222
|
* // Keys should appear in alphabetical order
|
|
223
223
|
* const expected =
|
|
224
224
|
* '{"apple":2,"mango":3,"nested":{"alpha":"a","beta":"b","zulu":"z"},"zebra":1}';
|
|
225
225
|
*
|
|
226
|
-
* assert(sorted.value === expected);
|
|
226
|
+
* assert.isTrue(sorted.value === expected);
|
|
227
227
|
* }
|
|
228
228
|
*
|
|
229
229
|
* // With formatting
|
|
230
230
|
* const formatted = Json.stringifySortedKey(unorderedData, 2);
|
|
231
231
|
*
|
|
232
|
-
* assert.
|
|
232
|
+
* assert.isTrue(Result.isOk(formatted));
|
|
233
233
|
*
|
|
234
234
|
* if (Result.isOk(formatted)) {
|
|
235
|
-
* assert(isString(formatted.value));
|
|
235
|
+
* assert.isTrue(isString(formatted.value));
|
|
236
236
|
*
|
|
237
237
|
* // Check that keys are in order (first key should be "apple")
|
|
238
|
-
* assert.
|
|
238
|
+
* assert.isTrue(
|
|
239
239
|
* formatted.value.indexOf('"apple"') < formatted.value.indexOf('"mango"'),
|
|
240
240
|
* );
|
|
241
241
|
*
|
|
242
|
-
* assert.
|
|
242
|
+
* assert.isTrue(
|
|
243
243
|
* formatted.value.indexOf('"mango"') < formatted.value.indexOf('"nested"'),
|
|
244
244
|
* );
|
|
245
245
|
*
|
|
246
|
-
* assert.
|
|
246
|
+
* assert.isTrue(
|
|
247
247
|
* formatted.value.indexOf('"nested"') < formatted.value.indexOf('"zebra"'),
|
|
248
248
|
* );
|
|
249
249
|
* }
|
package/dist/json/json.mjs
CHANGED
|
@@ -67,13 +67,13 @@ var Json;
|
|
|
67
67
|
*
|
|
68
68
|
* const failed = Json.parse(invalidJson);
|
|
69
69
|
*
|
|
70
|
-
* assert.
|
|
70
|
+
* assert.isTrue(Result.isOk(parsed));
|
|
71
71
|
*
|
|
72
72
|
* if (Result.isOk(parsed)) {
|
|
73
73
|
* assert.deepStrictEqual(parsed.value, { name: 'Alice', age: 30 });
|
|
74
74
|
* }
|
|
75
75
|
*
|
|
76
|
-
* assert.
|
|
76
|
+
* assert.isTrue(Result.isErr(failed));
|
|
77
77
|
*
|
|
78
78
|
* // With reviver
|
|
79
79
|
* const jsonWithDate = '{"created": "2024-01-01T00:00:00.000Z"}';
|
|
@@ -86,7 +86,7 @@ var Json;
|
|
|
86
86
|
* return value;
|
|
87
87
|
* });
|
|
88
88
|
*
|
|
89
|
-
* assert.
|
|
89
|
+
* assert.isTrue(Result.isOk(withReviver));
|
|
90
90
|
* ```
|
|
91
91
|
*
|
|
92
92
|
* @param text - A valid JSON string to parse. Can contain any valid JSON data
|
|
@@ -129,16 +129,16 @@ var Json;
|
|
|
129
129
|
* // Basic stringify
|
|
130
130
|
* const basic = Json.stringify(data);
|
|
131
131
|
*
|
|
132
|
-
* assert.
|
|
132
|
+
* assert.isTrue(Result.isOk(basic));
|
|
133
133
|
*
|
|
134
134
|
* if (Result.isOk(basic)) {
|
|
135
|
-
* assert(basic.value === '{"name":"Bob","age":25,"active":true}');
|
|
135
|
+
* assert.isTrue(basic.value === '{"name":"Bob","age":25,"active":true}');
|
|
136
136
|
* }
|
|
137
137
|
*
|
|
138
138
|
* // With formatting
|
|
139
139
|
* const formatted = Json.stringify(data, undefined, 2);
|
|
140
140
|
*
|
|
141
|
-
* assert.
|
|
141
|
+
* assert.isTrue(Result.isOk(formatted));
|
|
142
142
|
*
|
|
143
143
|
* // With replacer
|
|
144
144
|
* const filtered = Json.stringify(data, (key, value) => {
|
|
@@ -147,12 +147,12 @@ var Json;
|
|
|
147
147
|
* return value;
|
|
148
148
|
* });
|
|
149
149
|
*
|
|
150
|
-
* assert.
|
|
150
|
+
* assert.isTrue(Result.isOk(filtered));
|
|
151
151
|
*
|
|
152
152
|
* if (Result.isOk(filtered)) {
|
|
153
|
-
* assert(isString(filtered.value));
|
|
153
|
+
* assert.isTrue(isString(filtered.value));
|
|
154
154
|
*
|
|
155
|
-
* assert.
|
|
155
|
+
* assert.isFalse(filtered.value.includes('age'));
|
|
156
156
|
* }
|
|
157
157
|
* ```
|
|
158
158
|
*
|
|
@@ -208,10 +208,10 @@ var Json;
|
|
|
208
208
|
* // Select only safe properties to serialize
|
|
209
209
|
* const safeJson = Json.stringifySelected(user, ['id', 'name', 'role']);
|
|
210
210
|
*
|
|
211
|
-
* assert.
|
|
211
|
+
* assert.isTrue(Result.isOk(safeJson));
|
|
212
212
|
*
|
|
213
213
|
* if (Result.isOk(safeJson)) {
|
|
214
|
-
* assert(isString(safeJson.value));
|
|
214
|
+
* assert.isTrue(isString(safeJson.value));
|
|
215
215
|
*
|
|
216
216
|
* const parsed: unknown = JSON.parse(safeJson.value);
|
|
217
217
|
*
|
|
@@ -221,15 +221,15 @@ var Json;
|
|
|
221
221
|
* role: 'admin',
|
|
222
222
|
* });
|
|
223
223
|
*
|
|
224
|
-
* assert.
|
|
224
|
+
* assert.isFalse(safeJson.value.includes('password'));
|
|
225
225
|
*
|
|
226
|
-
* assert.
|
|
226
|
+
* assert.isFalse(safeJson.value.includes('email'));
|
|
227
227
|
* }
|
|
228
228
|
*
|
|
229
229
|
* // With formatting
|
|
230
230
|
* const formatted = Json.stringifySelected(user, ['id', 'name'], 2);
|
|
231
231
|
*
|
|
232
|
-
* assert.
|
|
232
|
+
* assert.isTrue(Result.isOk(formatted));
|
|
233
233
|
* ```
|
|
234
234
|
*
|
|
235
235
|
* @param value - The JavaScript value to serialize. While any value is
|
|
@@ -286,34 +286,34 @@ var Json;
|
|
|
286
286
|
* // Keys will be sorted alphabetically at all levels
|
|
287
287
|
* const sorted = Json.stringifySortedKey(unorderedData);
|
|
288
288
|
*
|
|
289
|
-
* assert.
|
|
289
|
+
* assert.isTrue(Result.isOk(sorted));
|
|
290
290
|
*
|
|
291
291
|
* if (Result.isOk(sorted)) {
|
|
292
292
|
* // Keys should appear in alphabetical order
|
|
293
293
|
* const expected =
|
|
294
294
|
* '{"apple":2,"mango":3,"nested":{"alpha":"a","beta":"b","zulu":"z"},"zebra":1}';
|
|
295
295
|
*
|
|
296
|
-
* assert(sorted.value === expected);
|
|
296
|
+
* assert.isTrue(sorted.value === expected);
|
|
297
297
|
* }
|
|
298
298
|
*
|
|
299
299
|
* // With formatting
|
|
300
300
|
* const formatted = Json.stringifySortedKey(unorderedData, 2);
|
|
301
301
|
*
|
|
302
|
-
* assert.
|
|
302
|
+
* assert.isTrue(Result.isOk(formatted));
|
|
303
303
|
*
|
|
304
304
|
* if (Result.isOk(formatted)) {
|
|
305
|
-
* assert(isString(formatted.value));
|
|
305
|
+
* assert.isTrue(isString(formatted.value));
|
|
306
306
|
*
|
|
307
307
|
* // Check that keys are in order (first key should be "apple")
|
|
308
|
-
* assert.
|
|
308
|
+
* assert.isTrue(
|
|
309
309
|
* formatted.value.indexOf('"apple"') < formatted.value.indexOf('"mango"'),
|
|
310
310
|
* );
|
|
311
311
|
*
|
|
312
|
-
* assert.
|
|
312
|
+
* assert.isTrue(
|
|
313
313
|
* formatted.value.indexOf('"mango"') < formatted.value.indexOf('"nested"'),
|
|
314
314
|
* );
|
|
315
315
|
*
|
|
316
|
-
* assert.
|
|
316
|
+
* assert.isTrue(
|
|
317
317
|
* formatted.value.indexOf('"nested"') < formatted.value.indexOf('"zebra"'),
|
|
318
318
|
* );
|
|
319
319
|
* }
|