@duplojs/utils 1.4.44 → 1.4.46
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/extended/nullable.d.ts +1 -1
- package/dist/dataParser/extended/optional.d.ts +1 -1
- package/dist/dataParser/extended/recover.d.ts +1 -1
- package/dist/dataParser/parsers/array/index.d.ts +1 -1
- package/dist/dataParser/parsers/empty.d.ts +1 -1
- package/dist/dataParser/parsers/lazy.d.ts +1 -1
- package/dist/dataParser/parsers/literal.d.ts +1 -1
- package/dist/dataParser/parsers/nullable.d.ts +2 -2
- package/dist/dataParser/parsers/object/index.d.ts +3 -3
- package/dist/dataParser/parsers/optional.d.ts +3 -3
- package/dist/dataParser/parsers/pipe.d.ts +1 -1
- package/dist/dataParser/parsers/record/index.d.ts +1 -1
- package/dist/dataParser/parsers/recover.d.ts +3 -3
- package/dist/dataParser/parsers/templateLiteral/index.d.ts +1 -1
- package/dist/dataParser/parsers/transform.d.ts +1 -1
- package/dist/dataParser/parsers/tuple.d.ts +1 -1
- package/dist/dataParser/parsers/union.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/dist/string/isIn.d.ts +2 -2
- package/dist/string/slice.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type Kind } from "../../common/kind";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Right } from "./create";
|
|
3
|
+
export declare const successKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/success", unknown>>;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use successKind
|
|
6
|
+
*/
|
|
3
7
|
export declare const eitherSuccessKind: import("../../common/kind").KindHandler<import("../../common/kind").KindDefinition<"@DuplojsUtilsEither/success", unknown>>;
|
|
4
|
-
type
|
|
5
|
-
export interface
|
|
8
|
+
type _Success<GenericValue extends unknown = unknown> = (Right<"success", GenericValue> & Kind<typeof successKind.definition>);
|
|
9
|
+
export interface Success<GenericValue extends unknown = unknown> extends _Success<GenericValue> {
|
|
6
10
|
}
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* @deprecated use Success
|
|
13
|
+
*/
|
|
14
|
+
export type EitherSuccess<GenericValue extends unknown = unknown> = Success<GenericValue>;
|
|
15
|
+
/**
|
|
16
|
+
* Readable shortcut to create an Right with the literal info "success". Ideal for functions that return only one type of success.
|
|
9
17
|
*
|
|
10
18
|
* Signature: `success(value)` → returns a value
|
|
11
19
|
*
|
|
@@ -24,7 +32,7 @@ export interface EitherSuccess<GenericValue extends unknown = unknown> extends _
|
|
|
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/success
|
|
@@ -32,5 +40,5 @@ export interface EitherSuccess<GenericValue extends unknown = unknown> extends _
|
|
|
32
40
|
* @namespace E
|
|
33
41
|
*
|
|
34
42
|
*/
|
|
35
|
-
export declare function success<const GenericValue extends unknown>(value: GenericValue):
|
|
43
|
+
export declare function success<const GenericValue extends unknown>(value: GenericValue): Success<GenericValue>;
|
|
36
44
|
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { createEitherKind } from '../kind.mjs';
|
|
2
2
|
import { right } from './create.mjs';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const successKind = createEitherKind("success");
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use successKind
|
|
7
|
+
*/
|
|
8
|
+
const eitherSuccessKind = successKind;
|
|
5
9
|
/**
|
|
6
10
|
* {@include either/success/index.md}
|
|
7
11
|
*/
|
|
8
12
|
function success(value) {
|
|
9
|
-
return
|
|
13
|
+
return successKind.setTo(right("success", value));
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
export { eitherSuccessKind, success };
|
|
16
|
+
export { eitherSuccessKind, success, successKind };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type EscapeVoid, type AnyValue, type Unwrap, type BreakGenericLink } from "../../common";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Right } from "./create";
|
|
3
3
|
/**
|
|
4
|
-
* Applies a function only when the input is an
|
|
4
|
+
* Applies a function only when the input is an Right. Otherwise, the original value is returned as-is.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
7
|
* - Classic: `whenIsRight(input, theFunction)` → returns a value
|
|
@@ -26,5 +26,5 @@ import { type EitherRight } from "./create";
|
|
|
26
26
|
* @namespace E
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
|
-
export declare function whenIsRight<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>,
|
|
30
|
-
export declare function whenIsRight<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(input: GenericInput, theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>,
|
|
29
|
+
export declare function whenIsRight<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>, Right>>) => GenericOutput): (input: GenericInput) => Exclude<BreakGenericLink<GenericInput>, Right> | GenericOutput;
|
|
30
|
+
export declare function whenIsRight<const GenericInput extends unknown, const GenericOutput extends AnyValue | EscapeVoid>(input: GenericInput, theFunction: (eitherValue: Unwrap<Extract<BreakGenericLink<GenericInput>, Right>>) => GenericOutput): Exclude<GenericInput, Right> | GenericOutput;
|
|
@@ -6,13 +6,21 @@ var create$1 = require('./right/create.cjs');
|
|
|
6
6
|
var is = require('./right/is.cjs');
|
|
7
7
|
var is$1 = require('./left/is.cjs');
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const callbackErrorKind = kind.createEitherKind("callback-error");
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use callbackErrorKind
|
|
12
|
+
*/
|
|
13
|
+
const eitherCallbackErrorKind = callbackErrorKind;
|
|
14
|
+
const callbackSuccessKind = kind.createEitherKind("callback-success");
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use callbackSuccessKind
|
|
17
|
+
*/
|
|
18
|
+
const eitherCallbackSuccessKind = callbackSuccessKind;
|
|
11
19
|
function callbackError(value) {
|
|
12
|
-
return
|
|
20
|
+
return callbackErrorKind.setTo(create.left("callback", value));
|
|
13
21
|
}
|
|
14
22
|
function callbackSuccess(value) {
|
|
15
|
-
return
|
|
23
|
+
return callbackSuccessKind.setTo(create$1.right("callback", value));
|
|
16
24
|
}
|
|
17
25
|
/**
|
|
18
26
|
* {@include either/safeCallback/index.md}
|
|
@@ -31,7 +39,9 @@ function safeCallback(theFunction) {
|
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
exports.callbackError = callbackError;
|
|
42
|
+
exports.callbackErrorKind = callbackErrorKind;
|
|
34
43
|
exports.callbackSuccess = callbackSuccess;
|
|
44
|
+
exports.callbackSuccessKind = callbackSuccessKind;
|
|
35
45
|
exports.eitherCallbackErrorKind = eitherCallbackErrorKind;
|
|
36
46
|
exports.eitherCallbackSuccessKind = eitherCallbackSuccessKind;
|
|
37
47
|
exports.safeCallback = safeCallback;
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import type { Kind, EscapeVoid } from "../common";
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
2
|
+
import { type Left } from "./left";
|
|
3
|
+
import { type Right } from "./right";
|
|
4
|
+
export declare const callbackErrorKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-error", unknown>>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use callbackErrorKind
|
|
7
|
+
*/
|
|
4
8
|
export declare const eitherCallbackErrorKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-error", unknown>>;
|
|
9
|
+
export declare const callbackSuccessKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-success", unknown>>;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use callbackSuccessKind
|
|
12
|
+
*/
|
|
5
13
|
export declare const eitherCallbackSuccessKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-success", unknown>>;
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
export interface
|
|
14
|
+
type _CallbackError = (Left<"callback", unknown> & Kind<typeof callbackErrorKind.definition>);
|
|
15
|
+
type _CallbackSuccess<GenericValue extends unknown> = (Right<"callback", GenericValue> & Kind<typeof callbackSuccessKind.definition>);
|
|
16
|
+
export interface CallbackError extends _CallbackError {
|
|
9
17
|
}
|
|
10
|
-
export interface
|
|
18
|
+
export interface CallbackSuccess<GenericValue extends unknown> extends _CallbackSuccess<GenericValue> {
|
|
11
19
|
}
|
|
12
|
-
export declare function callbackError(value: unknown): EitherCallbackError;
|
|
13
|
-
export declare function callbackSuccess<GenericValue extends unknown>(value: GenericValue): EitherCallbackSuccess<GenericValue>;
|
|
14
|
-
type Either = EitherRight | EitherLeft;
|
|
15
|
-
type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput extends Either ? GenericOutput : GenericOutput extends EscapeVoid ? EitherCallbackSuccess<undefined> : EitherCallbackSuccess<GenericOutput>;
|
|
16
20
|
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
21
|
+
* @deprecated use CallbackError
|
|
22
|
+
*/
|
|
23
|
+
export type EitherCallbackError = CallbackError;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated use CallbackSuccess
|
|
26
|
+
*/
|
|
27
|
+
export type EitherCallbackSuccess<GenericValue extends unknown> = CallbackSuccess<GenericValue>;
|
|
28
|
+
export declare function callbackError(value: unknown): CallbackError;
|
|
29
|
+
export declare function callbackSuccess<GenericValue extends unknown>(value: GenericValue): CallbackSuccess<GenericValue>;
|
|
30
|
+
type Either = Right | Left;
|
|
31
|
+
type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput extends Either ? GenericOutput : GenericOutput extends EscapeVoid ? CallbackSuccess<undefined> : CallbackSuccess<GenericOutput>;
|
|
32
|
+
/**
|
|
33
|
+
* Runs a callback in a safe block. If the callback throws, the function returns a "callback" typed Left instead of propagating the exception.
|
|
34
|
+
* If the callback returns an Either, it is returned as-is; otherwise the value is wrapped in an Right.
|
|
19
35
|
*
|
|
20
36
|
* Signature: `safeCallback(theFunction)` → returns a value
|
|
21
37
|
*
|
|
@@ -23,7 +39,7 @@ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput ex
|
|
|
23
39
|
*
|
|
24
40
|
* ```ts
|
|
25
41
|
* const success = E.safeCallback(() => 42);
|
|
26
|
-
* // E.
|
|
42
|
+
* // E.CallbackError | E.CallbackSuccess<number>
|
|
27
43
|
*
|
|
28
44
|
* const failure = E.safeCallback(() => {
|
|
29
45
|
* throw new Error("boom");
|
|
@@ -35,12 +51,12 @@ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput ex
|
|
|
35
51
|
* () => E.left("example", "already"),
|
|
36
52
|
* );
|
|
37
53
|
*
|
|
38
|
-
* const
|
|
54
|
+
* const isLeft = E.isLeft(eitherResult);
|
|
39
55
|
* ```
|
|
40
56
|
*
|
|
41
57
|
* @remarks
|
|
42
|
-
* - Catches exceptions thrown by the callback and wraps them in an `
|
|
43
|
-
* - Keeps an `
|
|
58
|
+
* - Catches exceptions thrown by the callback and wraps them in an `Left<"callback">`
|
|
59
|
+
* - Keeps an `Left` or `Right` returned by the callback untouched
|
|
44
60
|
* - Useful for working in an unsafe environment (3rd party libraries, user code, etc.)
|
|
45
61
|
*
|
|
46
62
|
* @see https://utils.duplojs.dev/en/v1/api/either/safeCallback
|
|
@@ -48,5 +64,5 @@ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput ex
|
|
|
48
64
|
* @namespace E
|
|
49
65
|
*
|
|
50
66
|
*/
|
|
51
|
-
export declare function safeCallback<GenericOutput extends unknown>(theFunction: () => GenericOutput): ComputeSafeCallbackResult<GenericOutput> |
|
|
67
|
+
export declare function safeCallback<GenericOutput extends unknown>(theFunction: () => GenericOutput): ComputeSafeCallbackResult<GenericOutput> | CallbackError;
|
|
52
68
|
export {};
|
|
@@ -4,13 +4,21 @@ import { right } from './right/create.mjs';
|
|
|
4
4
|
import { isRight } from './right/is.mjs';
|
|
5
5
|
import { isLeft } from './left/is.mjs';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const callbackErrorKind = createEitherKind("callback-error");
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated use callbackErrorKind
|
|
10
|
+
*/
|
|
11
|
+
const eitherCallbackErrorKind = callbackErrorKind;
|
|
12
|
+
const callbackSuccessKind = createEitherKind("callback-success");
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use callbackSuccessKind
|
|
15
|
+
*/
|
|
16
|
+
const eitherCallbackSuccessKind = callbackSuccessKind;
|
|
9
17
|
function callbackError(value) {
|
|
10
|
-
return
|
|
18
|
+
return callbackErrorKind.setTo(left("callback", value));
|
|
11
19
|
}
|
|
12
20
|
function callbackSuccess(value) {
|
|
13
|
-
return
|
|
21
|
+
return callbackSuccessKind.setTo(right("callback", value));
|
|
14
22
|
}
|
|
15
23
|
/**
|
|
16
24
|
* {@include either/safeCallback/index.md}
|
|
@@ -28,4 +36,4 @@ function safeCallback(theFunction) {
|
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
export { callbackError, callbackSuccess, eitherCallbackErrorKind, eitherCallbackSuccessKind, safeCallback };
|
|
39
|
+
export { callbackError, callbackErrorKind, callbackSuccess, callbackSuccessKind, eitherCallbackErrorKind, eitherCallbackSuccessKind, safeCallback };
|
|
@@ -15,7 +15,7 @@ function whenHasInformation(...args) {
|
|
|
15
15
|
? information
|
|
16
16
|
: [information];
|
|
17
17
|
if ((is.isLeft(input)
|
|
18
|
-
|| is$1.isRight(input)) && formattedInformation.includes(kind.
|
|
18
|
+
|| is$1.isRight(input)) && formattedInformation.includes(kind.informationKind.getValue(input))) {
|
|
19
19
|
return theFunction(unwrap.unwrap(input));
|
|
20
20
|
}
|
|
21
21
|
return input;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Kind, type WrappedValue, type AnyValue, type Unwrap, type BreakGenericLink } from "../common";
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
type Either =
|
|
2
|
+
import { type Right } from "./right";
|
|
3
|
+
import { type Left } from "./left";
|
|
4
|
+
import { informationKind } from "./kind";
|
|
5
|
+
type Either = Right | Left;
|
|
6
6
|
/**
|
|
7
7
|
* Functional pattern matching based on the literal information of an Either. The function is executed only when the information (or one of the informations) matches.
|
|
8
8
|
*
|
|
@@ -31,7 +31,7 @@ type Either = EitherRight | EitherLeft;
|
|
|
31
31
|
* }),
|
|
32
32
|
* );
|
|
33
33
|
*
|
|
34
|
-
* // type: 1 | 2 | E.
|
|
34
|
+
* // type: 1 | 2 | E.Left<"left-3", 3>
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
37
|
* @see https://utils.duplojs.dev/en/v1/api/either/whenHasInformation
|
|
@@ -39,6 +39,6 @@ type Either = EitherRight | EitherLeft;
|
|
|
39
39
|
* @namespace E
|
|
40
40
|
*
|
|
41
41
|
*/
|
|
42
|
-
export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof
|
|
43
|
-
export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof
|
|
42
|
+
export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof informationKind.getValue<GenericInput>> : never), const GenericOutput extends AnyValue>(information: GenericInformation | GenericInformation[], theFunction: (value: Unwrap<Extract<BreakGenericLink<GenericInput>, Kind<typeof informationKind.definition, GenericInformation> & WrappedValue>>) => GenericOutput): (input: GenericInput) => GenericOutput | Exclude<BreakGenericLink<GenericInput>, Kind<typeof informationKind.definition, GenericInformation>>;
|
|
43
|
+
export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof informationKind.getValue<GenericInput>> : never), const GenericOutput extends AnyValue>(input: GenericInput, information: GenericInformation | GenericInformation[], theFunction: (value: Unwrap<Extract<BreakGenericLink<GenericInput>, Kind<typeof informationKind.definition, GenericInformation> & WrappedValue>>) => GenericOutput): GenericOutput | Exclude<GenericInput, Kind<typeof informationKind.definition, GenericInformation>>;
|
|
44
44
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { informationKind } from './kind.mjs';
|
|
2
2
|
import { isLeft } from './left/is.mjs';
|
|
3
3
|
import { isRight } from './right/is.mjs';
|
|
4
4
|
import { unwrap } from '../common/unwrap.mjs';
|
|
@@ -13,7 +13,7 @@ function whenHasInformation(...args) {
|
|
|
13
13
|
? information
|
|
14
14
|
: [information];
|
|
15
15
|
if ((isLeft(input)
|
|
16
|
-
|| isRight(input)) && formattedInformation.includes(
|
|
16
|
+
|| isRight(input)) && formattedInformation.includes(informationKind.getValue(input))) {
|
|
17
17
|
return theFunction(unwrap(input));
|
|
18
18
|
}
|
|
19
19
|
return input;
|
package/dist/string/isIn.d.ts
CHANGED
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
* @namespace S
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
|
-
export declare function isIn<
|
|
47
|
-
export declare function isIn<
|
|
46
|
+
export declare function isIn<GenericValue extends string>(array: readonly (GenericValue | string)[]): (input: string) => input is GenericValue;
|
|
47
|
+
export declare function isIn<GenericValue extends string>(input: string, array: readonly (GenericValue | string)[]): input is GenericValue;
|
package/dist/string/slice.d.ts
CHANGED