@duplojs/utils 1.4.44 → 1.4.45
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/clean/constraint/base.d.ts +5 -5
- package/dist/clean/constraint/defaultConstraint/number.d.ts +3 -3
- package/dist/clean/constraint/defaultConstraint/string.d.ts +2 -2
- package/dist/clean/entity.d.ts +2 -2
- package/dist/clean/flag.d.ts +1 -1
- package/dist/clean/newType.d.ts +5 -5
- package/dist/clean/primitive/base.d.ts +10 -10
- package/dist/clean/repository.d.ts +1 -1
- package/dist/clean/useCase.d.ts +1 -1
- package/dist/common/hasKinds.d.ts +3 -3
- package/dist/common/hasSomeKinds.d.ts +3 -3
- package/dist/common/path/resolveFrom.d.ts +1 -1
- package/dist/dataParser/base.d.ts +2 -2
- package/dist/dataParser/baseExtended.d.ts +2 -2
- package/dist/dataParser/extended/empty.d.ts +1 -1
- package/dist/dataParser/parsers/empty.d.ts +1 -1
- package/dist/date/create.d.ts +1 -1
- package/dist/date/createTime.d.ts +1 -1
- package/dist/either/bool/base.cjs +6 -1
- package/dist/either/bool/base.d.ts +4 -0
- package/dist/either/bool/base.mjs +6 -2
- package/dist/either/bool/create.d.ts +6 -6
- package/dist/either/bool/falsy.cjs +9 -4
- package/dist/either/bool/falsy.d.ts +23 -15
- package/dist/either/bool/falsy.mjs +10 -6
- package/dist/either/bool/truthy.cjs +9 -4
- package/dist/either/bool/truthy.d.ts +23 -15
- package/dist/either/bool/truthy.mjs +10 -6
- package/dist/either/future/base.cjs +6 -1
- package/dist/either/future/base.d.ts +4 -0
- package/dist/either/future/base.mjs +6 -2
- package/dist/either/future/create.d.ts +8 -8
- package/dist/either/future/error.cjs +7 -2
- package/dist/either/future/error.d.ts +15 -7
- package/dist/either/future/error.mjs +8 -4
- package/dist/either/future/success.cjs +7 -2
- package/dist/either/future/success.d.ts +15 -7
- package/dist/either/future/success.mjs +8 -4
- package/dist/either/hasInformation.cjs +2 -2
- package/dist/either/hasInformation.d.ts +8 -8
- package/dist/either/hasInformation.mjs +3 -3
- package/dist/either/index.cjs +24 -0
- package/dist/either/index.mjs +23 -23
- package/dist/either/kind.cjs +6 -1
- package/dist/either/kind.d.ts +4 -0
- package/dist/either/kind.mjs +6 -2
- package/dist/either/left/create.cjs +7 -2
- package/dist/either/left/create.d.ts +14 -6
- package/dist/either/left/create.mjs +8 -4
- package/dist/either/left/error.cjs +7 -2
- package/dist/either/left/error.d.ts +14 -6
- package/dist/either/left/error.mjs +7 -3
- package/dist/either/left/fail.cjs +7 -2
- package/dist/either/left/fail.d.ts +14 -6
- package/dist/either/left/fail.mjs +7 -3
- package/dist/either/left/is.cjs +2 -2
- package/dist/either/left/is.d.ts +4 -4
- package/dist/either/left/is.mjs +4 -4
- package/dist/either/left/when.d.ts +4 -4
- package/dist/either/nullable/base.cjs +6 -1
- package/dist/either/nullable/base.d.ts +4 -0
- package/dist/either/nullable/base.mjs +6 -2
- package/dist/either/nullable/create.d.ts +5 -5
- package/dist/either/nullable/empty.cjs +9 -4
- package/dist/either/nullable/empty.d.ts +23 -15
- package/dist/either/nullable/empty.mjs +10 -6
- package/dist/either/nullable/filled.cjs +9 -4
- package/dist/either/nullable/filled.d.ts +22 -14
- package/dist/either/nullable/filled.mjs +10 -6
- package/dist/either/nullish/base.cjs +6 -1
- package/dist/either/nullish/base.d.ts +4 -0
- package/dist/either/nullish/base.mjs +6 -2
- package/dist/either/nullish/create.d.ts +5 -5
- package/dist/either/nullish/empty.cjs +9 -4
- package/dist/either/nullish/empty.d.ts +23 -15
- package/dist/either/nullish/empty.mjs +10 -6
- package/dist/either/nullish/filled.cjs +9 -4
- package/dist/either/nullish/filled.d.ts +23 -15
- package/dist/either/nullish/filled.mjs +10 -6
- package/dist/either/optional/base.cjs +6 -1
- package/dist/either/optional/base.d.ts +4 -0
- package/dist/either/optional/base.mjs +6 -2
- package/dist/either/optional/create.d.ts +5 -5
- package/dist/either/optional/empty.cjs +9 -4
- package/dist/either/optional/empty.d.ts +23 -15
- package/dist/either/optional/empty.mjs +10 -6
- package/dist/either/optional/filled.cjs +9 -4
- package/dist/either/optional/filled.d.ts +22 -14
- package/dist/either/optional/filled.mjs +10 -6
- package/dist/either/right/asyncGroup.d.ts +7 -7
- package/dist/either/right/asyncPipe.d.ts +33 -25
- package/dist/either/right/create.cjs +7 -2
- package/dist/either/right/create.d.ts +15 -7
- package/dist/either/right/create.mjs +8 -4
- package/dist/either/right/group.d.ts +8 -8
- package/dist/either/right/is.cjs +2 -2
- package/dist/either/right/is.d.ts +4 -4
- package/dist/either/right/is.mjs +4 -4
- package/dist/either/right/ok.cjs +7 -2
- package/dist/either/right/ok.d.ts +14 -6
- package/dist/either/right/ok.mjs +7 -3
- package/dist/either/right/pipe.d.ts +32 -24
- package/dist/either/right/success.cjs +7 -2
- package/dist/either/right/success.d.ts +14 -6
- package/dist/either/right/success.mjs +7 -3
- package/dist/either/right/when.d.ts +4 -4
- package/dist/either/safeCallback.cjs +14 -4
- package/dist/either/safeCallback.d.ts +33 -17
- package/dist/either/safeCallback.mjs +13 -5
- package/dist/either/whenHasInformation.cjs +1 -1
- package/dist/either/whenHasInformation.d.ts +7 -7
- package/dist/either/whenHasInformation.mjs +2 -2
- package/package.json +1 -1
package/dist/either/kind.cjs
CHANGED
|
@@ -5,7 +5,12 @@ var kind = require('../common/kind.cjs');
|
|
|
5
5
|
const createEitherKind = kind.createKindNamespace(
|
|
6
6
|
// @ts-expect-error reserved kind namespace
|
|
7
7
|
"DuplojsUtilsEither");
|
|
8
|
-
const
|
|
8
|
+
const informationKind = createEitherKind("information");
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated use informationKind
|
|
11
|
+
*/
|
|
12
|
+
const eitherInformationKind = informationKind;
|
|
9
13
|
|
|
10
14
|
exports.createEitherKind = createEitherKind;
|
|
11
15
|
exports.eitherInformationKind = eitherInformationKind;
|
|
16
|
+
exports.informationKind = informationKind;
|
package/dist/either/kind.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export declare const createEitherKind: <GenericName extends string, GenericKindValue extends unknown = unknown>(name: GenericName & import("../string").ForbiddenString<GenericName, "@" | "/">) => import("../common").KindHandler<import("../common").KindDefinition<`@DuplojsUtilsEither/${GenericName}`, GenericKindValue>>;
|
|
2
|
+
export declare const informationKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/information", string>>;
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated use informationKind
|
|
5
|
+
*/
|
|
2
6
|
export declare const eitherInformationKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/information", string>>;
|
package/dist/either/kind.mjs
CHANGED
|
@@ -3,6 +3,10 @@ import { createKindNamespace } from '../common/kind.mjs';
|
|
|
3
3
|
const createEitherKind = createKindNamespace(
|
|
4
4
|
// @ts-expect-error reserved kind namespace
|
|
5
5
|
"DuplojsUtilsEither");
|
|
6
|
-
const
|
|
6
|
+
const informationKind = createEitherKind("information");
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use informationKind
|
|
9
|
+
*/
|
|
10
|
+
const eitherInformationKind = informationKind;
|
|
7
11
|
|
|
8
|
-
export { createEitherKind, eitherInformationKind };
|
|
12
|
+
export { createEitherKind, eitherInformationKind, informationKind };
|
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
var wrapValue = require('../../common/wrapValue.cjs');
|
|
4
4
|
var kind = require('../kind.cjs');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const leftKind = kind.createEitherKind("left");
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use leftKind
|
|
9
|
+
*/
|
|
10
|
+
const eitherLeftKind = leftKind;
|
|
7
11
|
/**
|
|
8
12
|
* {@include either/left/index.md}
|
|
9
13
|
*/
|
|
10
14
|
function left(information, value = undefined) {
|
|
11
|
-
return
|
|
15
|
+
return leftKind.setTo(kind.informationKind.setTo(wrapValue.wrapValue(value), information));
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
exports.eitherLeftKind = eitherLeftKind;
|
|
15
19
|
exports.left = left;
|
|
20
|
+
exports.leftKind = leftKind;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { type Kind } from "../../common/kind";
|
|
2
2
|
import { type WrappedValue } from "../../common/wrapValue";
|
|
3
|
-
import {
|
|
3
|
+
import { informationKind } from "../kind";
|
|
4
|
+
export declare const leftKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/left", unknown>>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use leftKind
|
|
7
|
+
*/
|
|
4
8
|
export declare const eitherLeftKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/left", unknown>>;
|
|
5
|
-
type
|
|
6
|
-
export interface
|
|
9
|
+
type _Left<GenericInformation extends string = string, GenericValue extends unknown = unknown> = (Kind<typeof leftKind.definition> & Kind<typeof informationKind.definition, GenericInformation> & WrappedValue<GenericValue>);
|
|
10
|
+
export interface Left<GenericInformation extends string = string, GenericValue extends unknown = unknown> extends _Left<GenericInformation, GenericValue> {
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
|
-
*
|
|
13
|
+
* @deprecated use Left
|
|
14
|
+
*/
|
|
15
|
+
export type EitherLeft<GenericInformation extends string = string, GenericValue extends unknown = unknown> = Left<GenericInformation, GenericValue>;
|
|
16
|
+
/**
|
|
17
|
+
* Builds an Left by associating mandatory business information (literal string) with a value representing the error. This is the fundamental brick to signal a contextualized failure.
|
|
10
18
|
*
|
|
11
19
|
* Signature: `left(information, value)` → returns a value
|
|
12
20
|
*
|
|
@@ -26,7 +34,7 @@ export interface EitherLeft<GenericInformation extends string = string, GenericV
|
|
|
26
34
|
* ),
|
|
27
35
|
* );
|
|
28
36
|
*
|
|
29
|
-
* // type: E.
|
|
37
|
+
* // type: E.Right<"number.positive", number> | E.Left<"number.notPositive", number>
|
|
30
38
|
* ```
|
|
31
39
|
*
|
|
32
40
|
* @see https://utils.duplojs.dev/en/v1/api/either/left
|
|
@@ -34,5 +42,5 @@ export interface EitherLeft<GenericInformation extends string = string, GenericV
|
|
|
34
42
|
* @namespace E
|
|
35
43
|
*
|
|
36
44
|
*/
|
|
37
|
-
export declare function left<GenericInformation extends string, const GenericValue extends unknown = undefined>(information: GenericInformation, value?: GenericValue):
|
|
45
|
+
export declare function left<GenericInformation extends string, const GenericValue extends unknown = undefined>(information: GenericInformation, value?: GenericValue): Left<GenericInformation, GenericValue>;
|
|
38
46
|
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { wrapValue } from '../../common/wrapValue.mjs';
|
|
2
|
-
import { createEitherKind,
|
|
2
|
+
import { createEitherKind, informationKind } from '../kind.mjs';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const leftKind = createEitherKind("left");
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use leftKind
|
|
7
|
+
*/
|
|
8
|
+
const eitherLeftKind = leftKind;
|
|
5
9
|
/**
|
|
6
10
|
* {@include either/left/index.md}
|
|
7
11
|
*/
|
|
8
12
|
function left(information, value = undefined) {
|
|
9
|
-
return
|
|
13
|
+
return leftKind.setTo(informationKind.setTo(wrapValue(value), information));
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
export { eitherLeftKind, left };
|
|
16
|
+
export { eitherLeftKind, left, leftKind };
|
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
var kind = require('../kind.cjs');
|
|
4
4
|
var create = require('./create.cjs');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const errorKind = kind.createEitherKind("error");
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use errorKind
|
|
9
|
+
*/
|
|
10
|
+
const eitherErrorKind = errorKind;
|
|
7
11
|
/**
|
|
8
12
|
* {@include either/error/index.md}
|
|
9
13
|
*/
|
|
10
14
|
function error(value) {
|
|
11
|
-
return
|
|
15
|
+
return errorKind.setTo(create.left("error", value));
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
exports.eitherErrorKind = eitherErrorKind;
|
|
15
19
|
exports.error = error;
|
|
20
|
+
exports.errorKind = errorKind;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type Kind } from "../../common/kind";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Left } from "./create";
|
|
3
|
+
export declare const errorKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/error", unknown>>;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use errorKind
|
|
6
|
+
*/
|
|
3
7
|
export declare const eitherErrorKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/error", unknown>>;
|
|
4
|
-
type
|
|
5
|
-
export interface
|
|
8
|
+
type _Error<GenericValue extends unknown = unknown> = (Left<"error", GenericValue> & Kind<typeof errorKind.definition>);
|
|
9
|
+
export interface Error<GenericValue extends unknown = unknown> extends _Error<GenericValue> {
|
|
6
10
|
}
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* @deprecated use Error
|
|
13
|
+
*/
|
|
14
|
+
export type EitherError<GenericValue extends unknown = unknown> = Error<GenericValue>;
|
|
15
|
+
/**
|
|
16
|
+
* Handy alias to create an Left with the info fixed to "error". Useful to signal a generic error without manually providing the info.
|
|
9
17
|
*
|
|
10
18
|
* Signature: `error(value)` → returns a value
|
|
11
19
|
*
|
|
@@ -24,7 +32,7 @@ export interface EitherError<GenericValue extends unknown = unknown> extends _Ei
|
|
|
24
32
|
* ),
|
|
25
33
|
* );
|
|
26
34
|
*
|
|
27
|
-
* // type: E.
|
|
35
|
+
* // type: E.Error<string> | E.Success<string>
|
|
28
36
|
* ```
|
|
29
37
|
*
|
|
30
38
|
* @see https://utils.duplojs.dev/en/v1/api/either/error
|
|
@@ -32,5 +40,5 @@ export interface EitherError<GenericValue extends unknown = unknown> extends _Ei
|
|
|
32
40
|
* @namespace E
|
|
33
41
|
*
|
|
34
42
|
*/
|
|
35
|
-
export declare function error<const GenericValue extends unknown>(value: GenericValue):
|
|
43
|
+
export declare function error<const GenericValue extends unknown>(value: GenericValue): Error<GenericValue>;
|
|
36
44
|
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { createEitherKind } from '../kind.mjs';
|
|
2
2
|
import { left } from './create.mjs';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const errorKind = createEitherKind("error");
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use errorKind
|
|
7
|
+
*/
|
|
8
|
+
const eitherErrorKind = errorKind;
|
|
5
9
|
/**
|
|
6
10
|
* {@include either/error/index.md}
|
|
7
11
|
*/
|
|
8
12
|
function error(value) {
|
|
9
|
-
return
|
|
13
|
+
return errorKind.setTo(left("error", value));
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
export { eitherErrorKind, error };
|
|
16
|
+
export { eitherErrorKind, error, errorKind };
|
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
var kind = require('../kind.cjs');
|
|
4
4
|
var create = require('./create.cjs');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const failKind = kind.createEitherKind("fail");
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use failKind
|
|
9
|
+
*/
|
|
10
|
+
const eitherFailKind = failKind;
|
|
7
11
|
/**
|
|
8
12
|
* {@include either/fail/index.md}
|
|
9
13
|
*/
|
|
10
14
|
function fail() {
|
|
11
|
-
return
|
|
15
|
+
return failKind.setTo(create.left("fail", undefined));
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
exports.eitherFailKind = eitherFailKind;
|
|
15
19
|
exports.fail = fail;
|
|
20
|
+
exports.failKind = failKind;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type Kind } from "../../common/kind";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Left } from "./create";
|
|
3
|
+
export declare const failKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/fail", unknown>>;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use failKind
|
|
6
|
+
*/
|
|
3
7
|
export declare const eitherFailKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/fail", unknown>>;
|
|
4
|
-
type
|
|
5
|
-
export interface
|
|
8
|
+
type _Fail = (Left<"fail", never> & Kind<typeof failKind.definition>);
|
|
9
|
+
export interface Fail extends _Fail {
|
|
6
10
|
}
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* @deprecated use Fail
|
|
13
|
+
*/
|
|
14
|
+
export type EitherFail = Fail;
|
|
15
|
+
/**
|
|
16
|
+
* Returns an Left<"fail", never>: perfect to signal a failure without carrying extra data.
|
|
9
17
|
*
|
|
10
18
|
* Signature: `fail()` → returns a value
|
|
11
19
|
*
|
|
@@ -25,7 +33,7 @@ export interface EitherFail extends _EitherFail {
|
|
|
25
33
|
* ),
|
|
26
34
|
* );
|
|
27
35
|
*
|
|
28
|
-
* // type: E.
|
|
36
|
+
* // type: E.Success<number> | E.Fail
|
|
29
37
|
* ```
|
|
30
38
|
*
|
|
31
39
|
* @see https://utils.duplojs.dev/en/v1/api/either/fail
|
|
@@ -33,5 +41,5 @@ export interface EitherFail extends _EitherFail {
|
|
|
33
41
|
* @namespace E
|
|
34
42
|
*
|
|
35
43
|
*/
|
|
36
|
-
export declare function fail():
|
|
44
|
+
export declare function fail(): Fail;
|
|
37
45
|
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { createEitherKind } from '../kind.mjs';
|
|
2
2
|
import { left } from './create.mjs';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const failKind = createEitherKind("fail");
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use failKind
|
|
7
|
+
*/
|
|
8
|
+
const eitherFailKind = failKind;
|
|
5
9
|
/**
|
|
6
10
|
* {@include either/fail/index.md}
|
|
7
11
|
*/
|
|
8
12
|
function fail() {
|
|
9
|
-
return
|
|
13
|
+
return failKind.setTo(left("fail", undefined));
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
export { eitherFailKind, fail };
|
|
16
|
+
export { eitherFailKind, fail, failKind };
|
package/dist/either/left/is.cjs
CHANGED
|
@@ -8,8 +8,8 @@ var kind = require('../kind.cjs');
|
|
|
8
8
|
* {@include either/isLeft/index.md}
|
|
9
9
|
*/
|
|
10
10
|
function isLeft(input) {
|
|
11
|
-
return create.
|
|
12
|
-
&& kind.
|
|
11
|
+
return create.leftKind.has(input)
|
|
12
|
+
&& kind.informationKind.has(input)
|
|
13
13
|
&& wrapValue.isWrappedValue(input);
|
|
14
14
|
}
|
|
15
15
|
|
package/dist/either/left/is.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Left } from "./create";
|
|
2
2
|
/**
|
|
3
|
-
* Type guard that checks whether a value is an
|
|
3
|
+
* Type guard that checks whether a value is an Left. Ideal to secure an unwrap or trigger an error branch.
|
|
4
4
|
*
|
|
5
5
|
* Signature: `isLeft(input)` → returns a value
|
|
6
6
|
*
|
|
@@ -12,7 +12,7 @@ import { type EitherLeft } from "./create";
|
|
|
12
12
|
* : E.fail();
|
|
13
13
|
*
|
|
14
14
|
* if (E.isLeft(result)) {
|
|
15
|
-
* // type: E.
|
|
15
|
+
* // type: E.Fail
|
|
16
16
|
* }
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
@@ -21,4 +21,4 @@ import { type EitherLeft } from "./create";
|
|
|
21
21
|
* @namespace E
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
|
-
export declare function isLeft<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput,
|
|
24
|
+
export declare function isLeft<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput, Left>;
|
package/dist/either/left/is.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { leftKind } from './create.mjs';
|
|
2
2
|
import { isWrappedValue } from '../../common/wrapValue.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { informationKind } from '../kind.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* {@include either/isLeft/index.md}
|
|
7
7
|
*/
|
|
8
8
|
function isLeft(input) {
|
|
9
|
-
return
|
|
10
|
-
&&
|
|
9
|
+
return leftKind.has(input)
|
|
10
|
+
&& informationKind.has(input)
|
|
11
11
|
&& isWrappedValue(input);
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type EscapeVoid, type AnyValue, type Unwrap, type BreakGenericLink } from "../../common";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Left } from "./create";
|
|
3
3
|
/**
|
|
4
|
-
* Executes a function only when the input is an
|
|
4
|
+
* Executes a function only when the input is an Left. Otherwise, the original value is returned as-is.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
7
|
* - Classic: `whenIsLeft(input, theFunction)` → returns a value
|
|
@@ -26,5 +26,5 @@ import { type EitherLeft } from "./create";
|
|
|
26
26
|
* @namespace E
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
|
-
export declare function whenIsLeft<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>,
|
|
30
|
-
export declare function whenIsLeft<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(input: GenericInput, theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>,
|
|
29
|
+
export declare function whenIsLeft<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>, Left>>) => GenericOutput): (input: GenericInput) => Exclude<BreakGenericLink<GenericInput>, Left> | GenericOutput;
|
|
30
|
+
export declare function whenIsLeft<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(input: GenericInput, theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>, Left>>) => GenericOutput): Exclude<GenericInput, Left> | GenericOutput;
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var kind = require('../kind.cjs');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const nullableKind = kind.createEitherKind("nullable");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use nullableKind
|
|
8
|
+
*/
|
|
9
|
+
const eitherNullableKind = nullableKind;
|
|
6
10
|
|
|
7
11
|
exports.eitherNullableKind = eitherNullableKind;
|
|
12
|
+
exports.nullableKind = nullableKind;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
export declare const nullableKind: import("../..").KindHandler<import("../..").KindDefinition<"@DuplojsUtilsEither/nullable", unknown>>;
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use nullableKind
|
|
4
|
+
*/
|
|
1
5
|
export declare const eitherNullableKind: import("../..").KindHandler<import("../..").KindDefinition<"@DuplojsUtilsEither/nullable", unknown>>;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { createEitherKind } from '../kind.mjs';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const nullableKind = createEitherKind("nullable");
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use nullableKind
|
|
6
|
+
*/
|
|
7
|
+
const eitherNullableKind = nullableKind;
|
|
4
8
|
|
|
5
|
-
export { eitherNullableKind };
|
|
9
|
+
export { eitherNullableKind, nullableKind };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
1
|
+
import { type NullableEmpty } from "./empty";
|
|
2
|
+
import { type NullableFilled } from "./filled";
|
|
3
3
|
/**
|
|
4
4
|
* Wraps a null or non-null value in an Either, while keeping the information on whether it is filled or empty.
|
|
5
5
|
*
|
|
@@ -10,7 +10,7 @@ import { type EitherNullableFilled } from "./filled";
|
|
|
10
10
|
* ```ts
|
|
11
11
|
* const result = E.nullable(true ? "value" : null);
|
|
12
12
|
*
|
|
13
|
-
* // type: E.
|
|
13
|
+
* // type: E.NullableEmpty | E.NullableFilled<"value">
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
16
|
* @see https://utils.duplojs.dev/en/v1/api/either/nullable
|
|
@@ -18,5 +18,5 @@ import { type EitherNullableFilled } from "./filled";
|
|
|
18
18
|
* @namespace E
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
export declare function nullable<const GenericValue extends unknown = null>(value: GenericValue): GenericValue extends null ?
|
|
22
|
-
export type Nullable<GenericValue extends unknown> =
|
|
21
|
+
export declare function nullable<const GenericValue extends unknown = null>(value: GenericValue): GenericValue extends null ? NullableEmpty : NullableFilled<GenericValue>;
|
|
22
|
+
export type Nullable<GenericValue extends unknown> = NullableFilled<GenericValue> | NullableEmpty;
|
|
@@ -8,7 +8,11 @@ var is = require('../left/is.cjs');
|
|
|
8
8
|
var is$1 = require('../right/is.cjs');
|
|
9
9
|
var unwrap = require('../../common/unwrap.cjs');
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const nullableEmptyKind = kind.createEitherKind("nullable-empty");
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use nullableEmptyKind
|
|
14
|
+
*/
|
|
15
|
+
const eitherNullableEmptyKind = nullableEmptyKind;
|
|
12
16
|
/**
|
|
13
17
|
* {@include either/isNullableEmpty/index.md}
|
|
14
18
|
*/
|
|
@@ -19,12 +23,12 @@ const eitherNullableEmptyKind = kind.createEitherKind("nullable-empty");
|
|
|
19
23
|
* {@include either/whenIsNullableEmpty/index.md}
|
|
20
24
|
*/
|
|
21
25
|
function nullableEmpty() {
|
|
22
|
-
return base.
|
|
26
|
+
return base.nullableKind.setTo(nullableEmptyKind.setTo(create.left("nullable", null)));
|
|
23
27
|
}
|
|
24
28
|
function isNullableEmpty(input) {
|
|
25
29
|
return is.isLeft(input)
|
|
26
|
-
&& base.
|
|
27
|
-
&&
|
|
30
|
+
&& base.nullableKind.has(input)
|
|
31
|
+
&& nullableEmptyKind.has(input);
|
|
28
32
|
}
|
|
29
33
|
function whenIsNullableEmpty(...args) {
|
|
30
34
|
if (args.length === 1) {
|
|
@@ -50,4 +54,5 @@ function whenIsNullableEmpty(...args) {
|
|
|
50
54
|
exports.eitherNullableEmptyKind = eitherNullableEmptyKind;
|
|
51
55
|
exports.isNullableEmpty = isNullableEmpty;
|
|
52
56
|
exports.nullableEmpty = nullableEmpty;
|
|
57
|
+
exports.nullableEmptyKind = nullableEmptyKind;
|
|
53
58
|
exports.whenIsNullableEmpty = whenIsNullableEmpty;
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { type EscapeVoid, type AnyValue, type Unwrap, type BreakGenericLink } from "../../common";
|
|
2
2
|
import { type Kind } from "../../common/kind";
|
|
3
|
-
import { type
|
|
4
|
-
import { type
|
|
3
|
+
import { type Left } from "../left";
|
|
4
|
+
import { type Right } from "../right";
|
|
5
5
|
import { nullable } from "./create";
|
|
6
|
-
import {
|
|
6
|
+
import { nullableKind } from "./base";
|
|
7
|
+
export declare const nullableEmptyKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DuplojsUtilsEither/nullable-empty", unknown>>;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated use nullableEmptyKind
|
|
10
|
+
*/
|
|
7
11
|
export declare const eitherNullableEmptyKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DuplojsUtilsEither/nullable-empty", unknown>>;
|
|
8
|
-
type
|
|
9
|
-
export interface
|
|
12
|
+
type _NullableEmpty = (Left<"nullable", null> & Kind<typeof nullableKind.definition> & Kind<typeof nullableEmptyKind.definition>);
|
|
13
|
+
export interface NullableEmpty extends _NullableEmpty {
|
|
10
14
|
}
|
|
11
|
-
type Either = EitherRight | EitherLeft;
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* @deprecated use NullableEmpty
|
|
17
|
+
*/
|
|
18
|
+
export type EitherNullableEmpty = NullableEmpty;
|
|
19
|
+
type Either = Right | Left;
|
|
20
|
+
/**
|
|
21
|
+
* Type guard that detects an NullableEmpty.
|
|
14
22
|
*
|
|
15
23
|
* Signature: `isNullableEmpty(input)` → returns a value
|
|
16
24
|
*
|
|
@@ -20,7 +28,7 @@ type Either = EitherRight | EitherLeft;
|
|
|
20
28
|
* const maybeValue = E.nullable(true ? "value" : null);
|
|
21
29
|
*
|
|
22
30
|
* if (E.isNullableEmpty(maybeValue)) {
|
|
23
|
-
* // type: E.
|
|
31
|
+
* // type: E.NullableEmpty
|
|
24
32
|
* }
|
|
25
33
|
* ```
|
|
26
34
|
*
|
|
@@ -30,14 +38,14 @@ type Either = EitherRight | EitherLeft;
|
|
|
30
38
|
*
|
|
31
39
|
*/
|
|
32
40
|
/**
|
|
33
|
-
* Explicitly builds an
|
|
41
|
+
* Explicitly builds an Left<"nullable"> containing null.
|
|
34
42
|
*
|
|
35
43
|
* Signature: `nullableEmpty()` → returns a value
|
|
36
44
|
*
|
|
37
45
|
* ```ts
|
|
38
46
|
* const result = E.nullableEmpty();
|
|
39
47
|
*
|
|
40
|
-
* // type: E.
|
|
48
|
+
* // type: E.NullableEmpty
|
|
41
49
|
* ```
|
|
42
50
|
*
|
|
43
51
|
* @see https://utils.duplojs.dev/en/v1/api/either/nullableEmpty
|
|
@@ -60,7 +68,7 @@ type Either = EitherRight | EitherLeft;
|
|
|
60
68
|
* E.whenIsNullableEmpty(() => "nullable"),
|
|
61
69
|
* );
|
|
62
70
|
*
|
|
63
|
-
* // type: "nullable" | E.
|
|
71
|
+
* // type: "nullable" | E.NullableFilled<"value">
|
|
64
72
|
* ```
|
|
65
73
|
*
|
|
66
74
|
* @see https://utils.duplojs.dev/en/v1/api/either/whenIsNullableEmpty
|
|
@@ -68,9 +76,9 @@ type Either = EitherRight | EitherLeft;
|
|
|
68
76
|
* @namespace E
|
|
69
77
|
*
|
|
70
78
|
*/
|
|
71
|
-
export declare function nullableEmpty():
|
|
72
|
-
export declare function isNullableEmpty<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput,
|
|
79
|
+
export declare function nullableEmpty(): NullableEmpty;
|
|
80
|
+
export declare function isNullableEmpty<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput, NullableEmpty>;
|
|
73
81
|
type ToEither<GenericValue extends unknown> = GenericValue extends Either ? GenericValue : ReturnType<typeof nullable<GenericValue>>;
|
|
74
|
-
export declare function whenIsNullableEmpty<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(theFunction: (eitherValue: Unwrap<Extract<ToEither<BreakGenericLink<GenericInput>>,
|
|
75
|
-
export declare function whenIsNullableEmpty<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(input: GenericInput, theFunction: (eitherValue: Unwrap<Extract<ToEither<BreakGenericLink<GenericInput>>,
|
|
82
|
+
export declare function whenIsNullableEmpty<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(theFunction: (eitherValue: Unwrap<Extract<ToEither<BreakGenericLink<GenericInput>>, NullableEmpty>>) => GenericOutput): (input: GenericInput) => GenericOutput | Exclude<ToEither<GenericInput>, NullableEmpty>;
|
|
83
|
+
export declare function whenIsNullableEmpty<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(input: GenericInput, theFunction: (eitherValue: Unwrap<Extract<ToEither<BreakGenericLink<GenericInput>>, NullableEmpty>>) => GenericOutput): GenericOutput | Exclude<ToEither<BreakGenericLink<GenericInput>>, NullableEmpty>;
|
|
76
84
|
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { nullable } from './create.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { nullableKind } from './base.mjs';
|
|
3
3
|
import { createEitherKind } from '../kind.mjs';
|
|
4
4
|
import { left } from '../left/create.mjs';
|
|
5
5
|
import { isLeft } from '../left/is.mjs';
|
|
6
6
|
import { isRight } from '../right/is.mjs';
|
|
7
7
|
import { unwrap } from '../../common/unwrap.mjs';
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const nullableEmptyKind = createEitherKind("nullable-empty");
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use nullableEmptyKind
|
|
12
|
+
*/
|
|
13
|
+
const eitherNullableEmptyKind = nullableEmptyKind;
|
|
10
14
|
/**
|
|
11
15
|
* {@include either/isNullableEmpty/index.md}
|
|
12
16
|
*/
|
|
@@ -17,12 +21,12 @@ const eitherNullableEmptyKind = createEitherKind("nullable-empty");
|
|
|
17
21
|
* {@include either/whenIsNullableEmpty/index.md}
|
|
18
22
|
*/
|
|
19
23
|
function nullableEmpty() {
|
|
20
|
-
return
|
|
24
|
+
return nullableKind.setTo(nullableEmptyKind.setTo(left("nullable", null)));
|
|
21
25
|
}
|
|
22
26
|
function isNullableEmpty(input) {
|
|
23
27
|
return isLeft(input)
|
|
24
|
-
&&
|
|
25
|
-
&&
|
|
28
|
+
&& nullableKind.has(input)
|
|
29
|
+
&& nullableEmptyKind.has(input);
|
|
26
30
|
}
|
|
27
31
|
function whenIsNullableEmpty(...args) {
|
|
28
32
|
if (args.length === 1) {
|
|
@@ -45,4 +49,4 @@ function whenIsNullableEmpty(...args) {
|
|
|
45
49
|
return either;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
export { eitherNullableEmptyKind, isNullableEmpty, nullableEmpty, whenIsNullableEmpty };
|
|
52
|
+
export { eitherNullableEmptyKind, isNullableEmpty, nullableEmpty, nullableEmptyKind, whenIsNullableEmpty };
|
|
@@ -8,7 +8,11 @@ var is = require('../right/is.cjs');
|
|
|
8
8
|
var is$1 = require('../left/is.cjs');
|
|
9
9
|
var unwrap = require('../../common/unwrap.cjs');
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const nullableFilledKind = kind.createEitherKind("nullable-filled");
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use nullableFilledKind
|
|
14
|
+
*/
|
|
15
|
+
const eitherNullableFilledKind = nullableFilledKind;
|
|
12
16
|
/**
|
|
13
17
|
* {@include either/isNullableFilled/index.md}
|
|
14
18
|
*/
|
|
@@ -19,12 +23,12 @@ const eitherNullableFilledKind = kind.createEitherKind("nullable-filled");
|
|
|
19
23
|
* {@include either/whenIsNullableFilled/index.md}
|
|
20
24
|
*/
|
|
21
25
|
function nullableFilled(value) {
|
|
22
|
-
return base.
|
|
26
|
+
return base.nullableKind.setTo(nullableFilledKind.setTo(create.right("nullable", value)));
|
|
23
27
|
}
|
|
24
28
|
function isNullableFilled(input) {
|
|
25
29
|
return is.isRight(input)
|
|
26
|
-
&& base.
|
|
27
|
-
&&
|
|
30
|
+
&& base.nullableKind.has(input)
|
|
31
|
+
&& nullableFilledKind.has(input);
|
|
28
32
|
}
|
|
29
33
|
function whenIsNullableFilled(...args) {
|
|
30
34
|
if (args.length === 1) {
|
|
@@ -50,4 +54,5 @@ function whenIsNullableFilled(...args) {
|
|
|
50
54
|
exports.eitherNullableFilledKind = eitherNullableFilledKind;
|
|
51
55
|
exports.isNullableFilled = isNullableFilled;
|
|
52
56
|
exports.nullableFilled = nullableFilled;
|
|
57
|
+
exports.nullableFilledKind = nullableFilledKind;
|
|
53
58
|
exports.whenIsNullableFilled = whenIsNullableFilled;
|