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
|
@@ -11,9 +11,9 @@ import { NoneTypeTagName, SomeTypeTagName } from './tag.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* const notOptional = { $$tag: 'ts-data-forge::Optional.some' };
|
|
13
13
|
*
|
|
14
|
-
* assert.
|
|
14
|
+
* assert.isTrue(Optional.isOptional(maybeOptional));
|
|
15
15
|
*
|
|
16
|
-
* assert.
|
|
16
|
+
* assert.isFalse(Optional.isOptional(notOptional));
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* @param maybeOptional The value to check.
|
|
@@ -11,9 +11,9 @@ import { NoneTypeTagName } from './tag.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* const noneValue = Optional.none;
|
|
13
13
|
*
|
|
14
|
-
* assert.
|
|
14
|
+
* assert.isTrue(Optional.isSome(someValue));
|
|
15
15
|
*
|
|
16
|
-
* assert.
|
|
16
|
+
* assert.isTrue(Optional.isNone(noneValue));
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export const none: None = { $$tag: NoneTypeTagName } as const;
|
|
@@ -10,9 +10,9 @@ import { SomeTypeTagName } from './tag.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* const noneValue = Optional.none;
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(Optional.isSome(someValue));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isTrue(Optional.isNone(noneValue));
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
18
|
* @template S The type of the value.
|
|
@@ -19,9 +19,9 @@ import { type Unwrap } from './types.mjs';
|
|
|
19
19
|
*
|
|
20
20
|
* const noneNumber = Optional.none as Optional<number>;
|
|
21
21
|
*
|
|
22
|
-
* assert(Optional.toNullable(someNumber) === 42);
|
|
22
|
+
* assert.isTrue(Optional.toNullable(someNumber) === 42);
|
|
23
23
|
*
|
|
24
|
-
* assert(Optional.toNullable(noneNumber) === undefined);
|
|
24
|
+
* assert.isTrue(Optional.toNullable(noneNumber) === undefined);
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
27
|
* @template O The `UnknownOptional` type to convert.
|
|
@@ -16,15 +16,15 @@ import { type Unwrap } from './types.mjs';
|
|
|
16
16
|
*
|
|
17
17
|
* const withoutValue = Optional.none as Optional<number>;
|
|
18
18
|
*
|
|
19
|
-
* assert(Optional.unwrapOr(withValue, 0) === 5);
|
|
19
|
+
* assert.isTrue(Optional.unwrapOr(withValue, 0) === 5);
|
|
20
20
|
*
|
|
21
|
-
* assert(Optional.unwrapOr(withoutValue, 0) === 0);
|
|
21
|
+
* assert.isTrue(Optional.unwrapOr(withoutValue, 0) === 0);
|
|
22
22
|
*
|
|
23
23
|
* const unwrapWithDefault = Optional.unwrapOr(10);
|
|
24
24
|
*
|
|
25
|
-
* assert(unwrapWithDefault(Optional.some(3)) === 3);
|
|
25
|
+
* assert.isTrue(unwrapWithDefault(Optional.some(3)) === 3);
|
|
26
26
|
*
|
|
27
|
-
* assert(unwrapWithDefault(Optional.none) === 10);
|
|
27
|
+
* assert.isTrue(unwrapWithDefault(Optional.none) === 10);
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* @template O The `UnknownOptional` type to unwrap.
|
|
@@ -14,7 +14,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
14
14
|
* ```ts
|
|
15
15
|
* const present = Optional.some('available');
|
|
16
16
|
*
|
|
17
|
-
* assert(Optional.unwrapThrow(present) === 'available');
|
|
17
|
+
* assert.isTrue(Optional.unwrapThrow(present) === 'available');
|
|
18
18
|
*
|
|
19
19
|
* assert.throws(
|
|
20
20
|
* () => Optional.unwrapThrow(Optional.none),
|
|
@@ -18,9 +18,9 @@ import { type Unwrap } from './types.mjs';
|
|
|
18
18
|
*
|
|
19
19
|
* const noneString = Optional.none as Optional<string>;
|
|
20
20
|
*
|
|
21
|
-
* assert(Optional.unwrap(someString) === 'text');
|
|
21
|
+
* assert.isTrue(Optional.unwrap(someString) === 'text');
|
|
22
22
|
*
|
|
23
|
-
* assert(Optional.unwrap(noneString) === undefined);
|
|
23
|
+
* assert.isTrue(Optional.unwrap(noneString) === undefined);
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
26
26
|
* @template O The `UnknownOptional` type to unwrap.
|
|
@@ -11,7 +11,7 @@ import { some } from './optional-some.mjs';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const zipped = Optional.zip(Optional.some('left'), Optional.some(1));
|
|
13
13
|
*
|
|
14
|
-
* assert.
|
|
14
|
+
* assert.isTrue(Optional.isSome(zipped));
|
|
15
15
|
*
|
|
16
16
|
* if (Optional.isSome(zipped)) {
|
|
17
17
|
* const expected: readonly [string, number] = ['left', 1];
|
|
@@ -5,31 +5,31 @@ import { pipe } from './pipe.mjs';
|
|
|
5
5
|
describe('Optional test', () => {
|
|
6
6
|
describe('isOptional', () => {
|
|
7
7
|
test('should return true for Some values', () => {
|
|
8
|
-
|
|
8
|
+
assert.isTrue(Optional.isOptional(Optional.some(42)));
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
assert.isTrue(Optional.isOptional(Optional.some('hello')));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
assert.isTrue(Optional.isOptional(Optional.some(null)));
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
assert.isTrue(Optional.isOptional(Optional.some(undefined)));
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
test('should return true for None value', () => {
|
|
18
|
-
|
|
18
|
+
assert.isTrue(Optional.isOptional(Optional.none));
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('should return false for non-Optional values', () => {
|
|
22
|
-
|
|
22
|
+
assert.isFalse(Optional.isOptional(42));
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
assert.isFalse(Optional.isOptional('hello'));
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
assert.isFalse(Optional.isOptional(null));
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
assert.isFalse(Optional.isOptional(undefined));
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
assert.isFalse(Optional.isOptional({}));
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
assert.isFalse(Optional.isOptional({ type: 'fake', value: 42 }));
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -37,19 +37,19 @@ describe('Optional test', () => {
|
|
|
37
37
|
test('should create a Some variant with the provided value', () => {
|
|
38
38
|
const someNumber = Optional.some(42);
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
assert.isTrue(Optional.isSome(someNumber));
|
|
41
41
|
|
|
42
42
|
expect(Optional.unwrap(someNumber)).toBe(42);
|
|
43
43
|
|
|
44
44
|
const someString = Optional.some('hello');
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
assert.isTrue(Optional.isSome(someString));
|
|
47
47
|
|
|
48
48
|
expect(Optional.unwrap(someString)).toBe('hello');
|
|
49
49
|
|
|
50
50
|
const someObject = Optional.some({ name: 'Alice', age: 30 });
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
assert.isTrue(Optional.isSome(someObject));
|
|
53
53
|
|
|
54
54
|
assert.deepStrictEqual(Optional.unwrap(someObject), {
|
|
55
55
|
name: 'Alice',
|
|
@@ -66,9 +66,9 @@ describe('Optional test', () => {
|
|
|
66
66
|
|
|
67
67
|
describe('none', () => {
|
|
68
68
|
test('should be a singleton None value', () => {
|
|
69
|
-
|
|
69
|
+
assert.isTrue(Optional.isNone(Optional.none));
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
assert.isFalse(Optional.isSome(Optional.none));
|
|
72
72
|
|
|
73
73
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
74
74
|
expect(Optional.unwrapOr(Optional.none, undefined)).toBeUndefined();
|
|
@@ -83,17 +83,17 @@ describe('Optional test', () => {
|
|
|
83
83
|
test('should correctly identify Some values', () => {
|
|
84
84
|
const some = Optional.some(42);
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
assert.isTrue(Optional.isSome(some));
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
assert.isFalse(Optional.isNone(some));
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
test('should correctly identify None values', () => {
|
|
92
92
|
const none = Optional.none;
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
assert.isFalse(Optional.isSome(none));
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
assert.isTrue(Optional.isNone(none));
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
test('should act as type guards', () => {
|
|
@@ -115,7 +115,7 @@ describe('Optional test', () => {
|
|
|
115
115
|
|
|
116
116
|
const mapped = Optional.map(some, (x) => x * 2);
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
assert.isTrue(Optional.isSome(mapped));
|
|
119
119
|
|
|
120
120
|
if (Optional.isSome(mapped)) {
|
|
121
121
|
expect(Optional.unwrap(mapped)).toBe(10);
|
|
@@ -127,7 +127,7 @@ describe('Optional test', () => {
|
|
|
127
127
|
|
|
128
128
|
const mapped = Optional.map(none, (x: never) => x * 2);
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
assert.isTrue(Optional.isNone(mapped));
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
test('should support chaining', () => {
|
|
@@ -156,7 +156,7 @@ describe('Optional test', () => {
|
|
|
156
156
|
|
|
157
157
|
const mapped = doubler(some);
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
assert.isTrue(Optional.isSome(mapped));
|
|
160
160
|
|
|
161
161
|
if (Optional.isSome(mapped)) {
|
|
162
162
|
expect(Optional.unwrap(mapped)).toBe(10);
|
|
@@ -166,7 +166,7 @@ describe('Optional test', () => {
|
|
|
166
166
|
|
|
167
167
|
const mappedNone = doubler(none);
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
assert.isTrue(Optional.isNone(mappedNone));
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
test('should work with pipe when curried', () => {
|
|
@@ -176,7 +176,7 @@ describe('Optional test', () => {
|
|
|
176
176
|
|
|
177
177
|
const result = pipe(Optional.some(5)).map(doubler).map(toStringFn).value;
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
assert.isTrue(Optional.isSome(result));
|
|
180
180
|
|
|
181
181
|
if (Optional.isSome(result)) {
|
|
182
182
|
expect(Optional.unwrap(result)).toBe('10');
|
|
@@ -386,7 +386,7 @@ describe('Optional test', () => {
|
|
|
386
386
|
|
|
387
387
|
const invalid = Optional.flatMap(Optional.some('abc'), parseNumber);
|
|
388
388
|
|
|
389
|
-
|
|
389
|
+
assert.isTrue(Optional.isNone(invalid));
|
|
390
390
|
});
|
|
391
391
|
|
|
392
392
|
test('should return None if input is None', () => {
|
|
@@ -394,7 +394,7 @@ describe('Optional test', () => {
|
|
|
394
394
|
Optional.some(42),
|
|
395
395
|
);
|
|
396
396
|
|
|
397
|
-
|
|
397
|
+
assert.isTrue(Optional.isNone(result));
|
|
398
398
|
});
|
|
399
399
|
|
|
400
400
|
test('should support chaining multiple flatMaps', () => {
|
|
@@ -432,7 +432,7 @@ describe('Optional test', () => {
|
|
|
432
432
|
|
|
433
433
|
const result = parser(Optional.some('42'));
|
|
434
434
|
|
|
435
|
-
|
|
435
|
+
assert.isTrue(Optional.isSome(result));
|
|
436
436
|
|
|
437
437
|
if (Optional.isSome(result)) {
|
|
438
438
|
expect(Optional.unwrap(result)).toBe(42);
|
|
@@ -440,11 +440,11 @@ describe('Optional test', () => {
|
|
|
440
440
|
|
|
441
441
|
const invalid = parser(Optional.some('abc'));
|
|
442
442
|
|
|
443
|
-
|
|
443
|
+
assert.isTrue(Optional.isNone(invalid));
|
|
444
444
|
|
|
445
445
|
const noneResult = parser(Optional.none);
|
|
446
446
|
|
|
447
|
-
|
|
447
|
+
assert.isTrue(Optional.isNone(noneResult));
|
|
448
448
|
});
|
|
449
449
|
|
|
450
450
|
test('should work with pipe when curried', () => {
|
|
@@ -463,7 +463,7 @@ describe('Optional test', () => {
|
|
|
463
463
|
|
|
464
464
|
const result = pipe(Optional.some('42')).map(parser).map(doubler).value;
|
|
465
465
|
|
|
466
|
-
|
|
466
|
+
assert.isTrue(Optional.isSome(result));
|
|
467
467
|
|
|
468
468
|
if (Optional.isSome(result)) {
|
|
469
469
|
expect(Optional.unwrap(result)).toBe(84);
|
|
@@ -487,13 +487,13 @@ describe('Optional test', () => {
|
|
|
487
487
|
|
|
488
488
|
const filtered = Optional.filter(someOdd, (x) => x % 2 === 0);
|
|
489
489
|
|
|
490
|
-
|
|
490
|
+
assert.isTrue(Optional.isNone(filtered));
|
|
491
491
|
});
|
|
492
492
|
|
|
493
493
|
test('should return None if input is None', () => {
|
|
494
494
|
const filtered = Optional.filter(Optional.none, (_: never) => true);
|
|
495
495
|
|
|
496
|
-
|
|
496
|
+
assert.isTrue(Optional.isNone(filtered));
|
|
497
497
|
});
|
|
498
498
|
|
|
499
499
|
test('should support curried form', () => {
|
|
@@ -503,7 +503,7 @@ describe('Optional test', () => {
|
|
|
503
503
|
|
|
504
504
|
const filtered = evenFilter(someEven);
|
|
505
505
|
|
|
506
|
-
|
|
506
|
+
assert.isTrue(Optional.isSome(filtered));
|
|
507
507
|
|
|
508
508
|
if (Optional.isSome(filtered)) {
|
|
509
509
|
expect(Optional.unwrap(filtered)).toBe(4);
|
|
@@ -513,11 +513,11 @@ describe('Optional test', () => {
|
|
|
513
513
|
|
|
514
514
|
const filteredOdd = evenFilter(someOdd);
|
|
515
515
|
|
|
516
|
-
|
|
516
|
+
assert.isTrue(Optional.isNone(filteredOdd));
|
|
517
517
|
|
|
518
518
|
const noneResult = evenFilter(Optional.none);
|
|
519
519
|
|
|
520
|
-
|
|
520
|
+
assert.isTrue(Optional.isNone(noneResult));
|
|
521
521
|
});
|
|
522
522
|
|
|
523
523
|
test('should work with pipe when curried', () => {
|
|
@@ -529,7 +529,7 @@ describe('Optional test', () => {
|
|
|
529
529
|
.map(evenFilter)
|
|
530
530
|
.map(positiveFilter).value;
|
|
531
531
|
|
|
532
|
-
|
|
532
|
+
assert.isTrue(Optional.isSome(result));
|
|
533
533
|
|
|
534
534
|
if (Optional.isSome(result)) {
|
|
535
535
|
expect(Optional.unwrap(result)).toBe(4);
|
|
@@ -537,7 +537,7 @@ describe('Optional test', () => {
|
|
|
537
537
|
|
|
538
538
|
const filtered = pipe(Optional.some(3)).map(evenFilter).value;
|
|
539
539
|
|
|
540
|
-
|
|
540
|
+
assert.isTrue(Optional.isNone(filtered));
|
|
541
541
|
});
|
|
542
542
|
});
|
|
543
543
|
|
|
@@ -569,7 +569,7 @@ describe('Optional test', () => {
|
|
|
569
569
|
test('should return None if both are None', () => {
|
|
570
570
|
const result = Optional.orElse(Optional.none, Optional.none);
|
|
571
571
|
|
|
572
|
-
|
|
572
|
+
assert.isTrue(Optional.isNone(result));
|
|
573
573
|
});
|
|
574
574
|
|
|
575
575
|
test('should support curried form', () => {
|
|
@@ -579,7 +579,7 @@ describe('Optional test', () => {
|
|
|
579
579
|
|
|
580
580
|
const result = fallbackTo(someValue);
|
|
581
581
|
|
|
582
|
-
|
|
582
|
+
assert.isTrue(Optional.isSome(result));
|
|
583
583
|
|
|
584
584
|
if (Optional.isSome(result)) {
|
|
585
585
|
expect(Optional.unwrap(result)).toBe('primary');
|
|
@@ -589,7 +589,7 @@ describe('Optional test', () => {
|
|
|
589
589
|
|
|
590
590
|
const fallbackResult = fallbackTo(noneValue);
|
|
591
591
|
|
|
592
|
-
|
|
592
|
+
assert.isTrue(Optional.isSome(fallbackResult));
|
|
593
593
|
|
|
594
594
|
if (Optional.isSome(fallbackResult)) {
|
|
595
595
|
expect(Optional.unwrap(fallbackResult)).toBe('fallback');
|
|
@@ -601,7 +601,7 @@ describe('Optional test', () => {
|
|
|
601
601
|
|
|
602
602
|
const someResult = pipe(Optional.some('original')).map(fallbackTo).value;
|
|
603
603
|
|
|
604
|
-
|
|
604
|
+
assert.isTrue(Optional.isSome(someResult));
|
|
605
605
|
|
|
606
606
|
if (Optional.isSome(someResult)) {
|
|
607
607
|
expect(Optional.unwrap(someResult)).toBe('original');
|
|
@@ -609,7 +609,7 @@ describe('Optional test', () => {
|
|
|
609
609
|
|
|
610
610
|
const noneResult = pipe(Optional.none).map(fallbackTo).value;
|
|
611
611
|
|
|
612
|
-
|
|
612
|
+
assert.isTrue(Optional.isSome(noneResult));
|
|
613
613
|
|
|
614
614
|
if (Optional.isSome(noneResult)) {
|
|
615
615
|
expect(Optional.unwrap(noneResult)).toBe('backup');
|
|
@@ -637,7 +637,7 @@ describe('Optional test', () => {
|
|
|
637
637
|
|
|
638
638
|
const zipped = Optional.zip(a, b);
|
|
639
639
|
|
|
640
|
-
|
|
640
|
+
assert.isTrue(Optional.isNone(zipped));
|
|
641
641
|
});
|
|
642
642
|
|
|
643
643
|
test('should return None if second is None', () => {
|
|
@@ -647,13 +647,13 @@ describe('Optional test', () => {
|
|
|
647
647
|
|
|
648
648
|
const zipped = Optional.zip(a, b);
|
|
649
649
|
|
|
650
|
-
|
|
650
|
+
assert.isTrue(Optional.isNone(zipped));
|
|
651
651
|
});
|
|
652
652
|
|
|
653
653
|
test('should return None if both are None', () => {
|
|
654
654
|
const zipped = Optional.zip(Optional.none, Optional.none);
|
|
655
655
|
|
|
656
|
-
|
|
656
|
+
assert.isTrue(Optional.isNone(zipped));
|
|
657
657
|
});
|
|
658
658
|
});
|
|
659
659
|
|
|
@@ -678,16 +678,15 @@ describe('Optional test', () => {
|
|
|
678
678
|
|
|
679
679
|
const falseOpt = Optional.fromNullable(false);
|
|
680
680
|
|
|
681
|
-
if (Optional.isSome(falseOpt))
|
|
682
|
-
expect(Optional.unwrap(falseOpt)).toBe(false);
|
|
681
|
+
if (Optional.isSome(falseOpt)) assert.isFalse(Optional.unwrap(falseOpt));
|
|
683
682
|
});
|
|
684
683
|
|
|
685
684
|
test('should convert null to None', () => {
|
|
686
|
-
|
|
685
|
+
assert.isTrue(Optional.isNone(Optional.fromNullable(null)));
|
|
687
686
|
});
|
|
688
687
|
|
|
689
688
|
test('should convert undefined to None', () => {
|
|
690
|
-
|
|
689
|
+
assert.isTrue(Optional.isNone(Optional.fromNullable(undefined)));
|
|
691
690
|
});
|
|
692
691
|
|
|
693
692
|
test('should work with union types', () => {
|
|
@@ -722,7 +721,7 @@ describe('Optional test', () => {
|
|
|
722
721
|
test('should handle undefined as a Some value', () => {
|
|
723
722
|
const someUndefined = Optional.some(undefined);
|
|
724
723
|
|
|
725
|
-
|
|
724
|
+
assert.isTrue(Optional.isSome(someUndefined));
|
|
726
725
|
|
|
727
726
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
728
727
|
expect(Optional.unwrap(someUndefined)).toBeUndefined();
|
|
@@ -734,7 +733,7 @@ describe('Optional test', () => {
|
|
|
734
733
|
test('should handle null as a Some value', () => {
|
|
735
734
|
const someNull = Optional.some(null);
|
|
736
735
|
|
|
737
|
-
|
|
736
|
+
assert.isTrue(Optional.isSome(someNull));
|
|
738
737
|
|
|
739
738
|
expect(Optional.unwrap(someNull)).toBeNull();
|
|
740
739
|
});
|
|
@@ -742,11 +741,11 @@ describe('Optional test', () => {
|
|
|
742
741
|
test('should handle nested Optionals', () => {
|
|
743
742
|
const nested = Optional.some(Optional.some(42));
|
|
744
743
|
|
|
745
|
-
|
|
744
|
+
assert.isTrue(Optional.isSome(nested));
|
|
746
745
|
|
|
747
746
|
const inner = Optional.unwrap(nested);
|
|
748
747
|
|
|
749
|
-
|
|
748
|
+
assert.isTrue(Optional.isOptional(inner));
|
|
750
749
|
|
|
751
750
|
expect(Optional.unwrap(inner)).toBe(42);
|
|
752
751
|
});
|
package/src/functional/pipe.mts
CHANGED
|
@@ -89,7 +89,7 @@ type PipeBase<A> = Readonly<{
|
|
|
89
89
|
* value.toUpperCase(),
|
|
90
90
|
* );
|
|
91
91
|
*
|
|
92
|
-
* assert(empty.value === undefined);
|
|
92
|
+
* assert.isTrue(empty.value === undefined);
|
|
93
93
|
* ```
|
|
94
94
|
*
|
|
95
95
|
* @template B The type of the transformed value.
|
|
@@ -127,7 +127,7 @@ type PipeWithMapOptional<A extends UnknownOptional> = MergeIntersection<
|
|
|
127
127
|
* (value) => value * 2,
|
|
128
128
|
* );
|
|
129
129
|
*
|
|
130
|
-
* assert.
|
|
130
|
+
* assert.isTrue(Optional.isNone(empty.value));
|
|
131
131
|
* ```
|
|
132
132
|
*
|
|
133
133
|
* @template B The type of the transformed inner value.
|
|
@@ -64,13 +64,13 @@ describe(pipe, () => {
|
|
|
64
64
|
|
|
65
65
|
const result = pipe(optional).mapOptional((x) => x * 2).value;
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
assert.isTrue(Optional.isSome(result));
|
|
68
68
|
|
|
69
69
|
if (Optional.isSome(result)) {
|
|
70
70
|
expect(result.value).toBe(84);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
expectType<typeof result,
|
|
73
|
+
expectType<typeof result, Some<number>>('=');
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
test('mapOptional with None value', () => {
|
|
@@ -78,9 +78,9 @@ describe(pipe, () => {
|
|
|
78
78
|
|
|
79
79
|
const result = pipe(optional).mapOptional((x) => x * 2).value;
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
assert.isTrue(Optional.isNone(result));
|
|
82
82
|
|
|
83
|
-
expectType<typeof result,
|
|
83
|
+
expectType<typeof result, None>('=');
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
test('chaining multiple operations', () => {
|
|
@@ -11,13 +11,13 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const okValue = Result.ok('data');
|
|
13
13
|
*
|
|
14
|
-
* assert(Result.expectToBe(okValue, 'should have value') === 'data');
|
|
14
|
+
* assert.isTrue(Result.expectToBe(okValue, 'should have value') === 'data');
|
|
15
15
|
*
|
|
16
16
|
* const expectResult = Result.expectToBe<string>('missing result');
|
|
17
17
|
*
|
|
18
18
|
* assert.throws(() => expectResult(Result.err('boom')), /missing result/u);
|
|
19
19
|
*
|
|
20
|
-
* assert(expectResult(Result.ok('value')) === 'value');
|
|
20
|
+
* assert.isTrue(expectResult(Result.ok('value')) === 'value');
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
23
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -28,7 +28,7 @@ type UnwrapPromise<P extends Promise<unknown>> =
|
|
|
28
28
|
*
|
|
29
29
|
* assert.deepStrictEqual(resolved, Result.ok('ok'));
|
|
30
30
|
*
|
|
31
|
-
* assert.
|
|
31
|
+
* assert.isTrue(Result.isErr(rejected));
|
|
32
32
|
* ```
|
|
33
33
|
*
|
|
34
34
|
* @template P The type of the input Promise.
|
|
@@ -14,10 +14,10 @@ import { type NarrowToErr } from './types.mjs';
|
|
|
14
14
|
* if (Result.isOk(operation)) {
|
|
15
15
|
* const value: number = operation.value;
|
|
16
16
|
*
|
|
17
|
-
* assert(value === 3);
|
|
17
|
+
* assert.isTrue(value === 3);
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
|
-
* assert.
|
|
20
|
+
* assert.isTrue(Result.isErr(failure));
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export const isErr = <R extends UnknownResult>(
|
|
@@ -14,10 +14,10 @@ import { type NarrowToOk } from './types.mjs';
|
|
|
14
14
|
* if (Result.isOk(operation)) {
|
|
15
15
|
* const value: number = operation.value;
|
|
16
16
|
*
|
|
17
|
-
* assert(value === 3);
|
|
17
|
+
* assert.isTrue(value === 3);
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
|
-
* assert.
|
|
20
|
+
* assert.isTrue(Result.isErr(failure));
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export const isOk = <R extends UnknownResult>(
|
|
@@ -13,11 +13,11 @@ import { ErrTypeTagName, OkTypeTagName } from './tag.mjs';
|
|
|
13
13
|
*
|
|
14
14
|
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
15
15
|
*
|
|
16
|
-
* assert.
|
|
16
|
+
* assert.isTrue(Result.isResult(okValue));
|
|
17
17
|
*
|
|
18
|
-
* assert.
|
|
18
|
+
* assert.isTrue(Result.isResult(errValue));
|
|
19
19
|
*
|
|
20
|
-
* assert.
|
|
20
|
+
* assert.isFalse(Result.isResult(notResult));
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export const isResult = (maybeResult: unknown): maybeResult is UnknownResult =>
|
|
@@ -12,15 +12,15 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
12
12
|
*
|
|
13
13
|
* const errResult = Result.err('failure');
|
|
14
14
|
*
|
|
15
|
-
* assert(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
15
|
+
* assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
16
16
|
*
|
|
17
|
-
* assert(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
17
|
+
* assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
18
18
|
*
|
|
19
19
|
* const unwrapError = Result.unwrapErrOr('fallback error');
|
|
20
20
|
*
|
|
21
|
-
* assert(unwrapError(Result.err('boom')) === 'boom');
|
|
21
|
+
* assert.isTrue(unwrapError(Result.err('boom')) === 'boom');
|
|
22
22
|
*
|
|
23
|
-
* assert(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
23
|
+
* assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
26
26
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -18,7 +18,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
18
18
|
*
|
|
19
19
|
* const okResult = Result.ok('value');
|
|
20
20
|
*
|
|
21
|
-
* assert(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
21
|
+
* assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
22
22
|
*
|
|
23
23
|
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
24
24
|
* ```
|