@duplojs/utils 1.0.3 → 1.0.5
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/common/and.d.ts +31 -0
- package/dist/common/equal.cjs +14 -0
- package/dist/common/equal.d.ts +3 -0
- package/dist/common/equal.mjs +12 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/isType.cjs +24 -0
- package/dist/common/isType.d.ts +20 -0
- package/dist/common/isType.mjs +22 -0
- package/dist/common/not.cjs +12 -0
- package/dist/common/not.d.ts +2 -0
- package/dist/common/not.mjs +10 -0
- package/dist/common/or.d.ts +26 -0
- package/dist/index.cjs +6 -0
- package/dist/index.mjs +3 -0
- package/dist/object/deepDiscriminate.cjs +15 -0
- package/dist/object/deepDiscriminate.d.ts +11 -0
- package/dist/object/deepDiscriminate.mjs +13 -0
- package/dist/object/discriminate.cjs +14 -0
- package/dist/object/discriminate.d.ts +8 -0
- package/dist/object/discriminate.mjs +12 -0
- package/dist/object/getDeepProperty.cjs +18 -0
- package/dist/object/getDeepProperty.d.ts +6 -0
- package/dist/object/getDeepProperty.mjs +16 -0
- package/dist/object/index.cjs +6 -0
- package/dist/object/index.d.ts +3 -0
- package/dist/object/index.mjs +3 -0
- package/dist/object/types/getPropsWithValueExtends.d.ts +3 -0
- package/dist/object/types/index.d.ts +2 -0
- package/dist/object/types/unFlatObject.d.ts +21 -0
- package/dist/pattern/index.cjs +2 -2
- package/dist/pattern/index.d.ts +1 -1
- package/dist/pattern/index.mjs +1 -1
- package/dist/pattern/isMatch.cjs +6 -1
- package/dist/pattern/isMatch.d.ts +5 -2
- package/dist/pattern/isMatch.mjs +6 -1
- package/dist/pattern/match.cjs +1 -1
- package/dist/pattern/match.mjs +2 -2
- package/dist/pattern/result.cjs +1 -1
- package/dist/pattern/result.mjs +1 -1
- package/dist/pattern/when.cjs +17 -0
- package/dist/pattern/when.d.ts +6 -0
- package/dist/pattern/when.mjs +15 -0
- package/dist/string/endsWith.d.ts +5 -2
- package/dist/string/includes.d.ts +5 -2
- package/dist/string/isIn.d.ts +2 -2
- package/dist/string/startsWith.d.ts +5 -2
- package/package.json +1 -1
- package/dist/pattern/matchPrimitive.cjs +0 -17
- package/dist/pattern/matchPrimitive.d.ts +0 -3
- package/dist/pattern/matchPrimitive.mjs +0 -15
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type IsEqual, type AnyFunction, type UnionToIntersection } from "./types";
|
|
2
|
+
type ExtractIntersection<GenericInput extends unknown, GenericPredicatedInput extends AnyFunction<any[], boolean>[], GenericResult extends unknown = GenericInput> = GenericPredicatedInput extends [
|
|
3
|
+
(input: any) => input is infer InferredPredicate,
|
|
4
|
+
...infer InferredRest extends AnyFunction<any[], boolean>[]
|
|
5
|
+
] ? Extract<GenericResult, InferredPredicate> extends infer InferredResult extends GenericInput ? InferredRest extends readonly [] ? InferredResult : ExtractIntersection<GenericInput, InferredRest, InferredResult> : never : never;
|
|
6
|
+
type ExtractPredicate<GenericInput extends unknown, GenericPredicatedInput extends AnyFunction<any[], boolean>[]> = GenericPredicatedInput extends [
|
|
7
|
+
(input: any) => input is infer InferredPredicate,
|
|
8
|
+
...infer InferredRest extends AnyFunction<any[], boolean>[]
|
|
9
|
+
] ? InferredRest extends readonly [] ? InferredPredicate : InferredPredicate | ExtractPredicate<GenericInput, InferredRest> : GenericInput;
|
|
10
|
+
type ComputeResult<GenericInput extends unknown, GenericPredicatedInput extends AnyFunction<any[], boolean>[]> = ExtractIntersection<GenericInput, GenericPredicatedInput> extends infer InferredResult extends GenericInput ? IsEqual<InferredResult, never> extends true ? GenericInput & UnionToIntersection<ExtractPredicate<GenericInput, GenericPredicatedInput>> : InferredResult : never;
|
|
11
|
+
export declare function and<GenericInput extends unknown, GenericArrayPredicatedInput extends [
|
|
12
|
+
(input: GenericInput) => input is any,
|
|
13
|
+
(input: GenericInput) => input is any,
|
|
14
|
+
...((input: GenericInput) => input is any)[]
|
|
15
|
+
]>(predicatedList: GenericArrayPredicatedInput): (input: GenericInput) => input is ComputeResult<GenericInput, GenericArrayPredicatedInput>;
|
|
16
|
+
export declare function and<GenericInput extends unknown>(predicatedList: [
|
|
17
|
+
(input: GenericInput) => boolean,
|
|
18
|
+
(input: GenericInput) => boolean,
|
|
19
|
+
...((input: GenericInput) => boolean)[]
|
|
20
|
+
]): (input: GenericInput) => boolean;
|
|
21
|
+
export declare function and<GenericInput extends unknown, GenericArrayPredicatedInput extends [
|
|
22
|
+
(input: GenericInput) => input is any,
|
|
23
|
+
(input: GenericInput) => input is any,
|
|
24
|
+
...((input: GenericInput) => input is any)[]
|
|
25
|
+
]>(input: GenericInput, predicatedList: GenericArrayPredicatedInput): input is ComputeResult<GenericInput, GenericArrayPredicatedInput>;
|
|
26
|
+
export declare function and<GenericInput extends unknown>(input: GenericInput, predicatedList: [
|
|
27
|
+
(input: GenericInput) => boolean,
|
|
28
|
+
(input: GenericInput) => boolean,
|
|
29
|
+
...((input: GenericInput) => boolean)[]
|
|
30
|
+
]): boolean;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function equal(...args) {
|
|
4
|
+
if (args.length === 1) {
|
|
5
|
+
const [value] = args;
|
|
6
|
+
return (input) => equal(input, value);
|
|
7
|
+
}
|
|
8
|
+
const [input, value] = args;
|
|
9
|
+
return value instanceof Array
|
|
10
|
+
? value.includes(input)
|
|
11
|
+
: input === value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.equal = equal;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type EligibleEqual = string | null | number | undefined | bigint | boolean | symbol;
|
|
2
|
+
export declare function equal<GenericInput extends EligibleEqual, GenericValue extends GenericInput>(value: GenericValue | GenericValue[]): (input: GenericInput) => input is NoInfer<GenericValue>;
|
|
3
|
+
export declare function equal<GenericInput extends EligibleEqual, GenericValue extends GenericInput>(input: GenericInput, value: GenericValue | GenericValue[]): input is GenericValue;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function equal(...args) {
|
|
2
|
+
if (args.length === 1) {
|
|
3
|
+
const [value] = args;
|
|
4
|
+
return (input) => equal(input, value);
|
|
5
|
+
}
|
|
6
|
+
const [input, value] = args;
|
|
7
|
+
return value instanceof Array
|
|
8
|
+
? value.includes(input)
|
|
9
|
+
: input === value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { equal };
|
package/dist/common/index.d.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const testTypeWrapper = {
|
|
4
|
+
string: (input) => typeof input === "string",
|
|
5
|
+
number: (input) => typeof input === "number",
|
|
6
|
+
bigint: (input) => typeof input === "bigint",
|
|
7
|
+
boolean: (input) => typeof input === "boolean",
|
|
8
|
+
function: (input) => typeof input === "function",
|
|
9
|
+
symbol: (input) => typeof input === "symbol",
|
|
10
|
+
undefined: (input) => typeof input === "undefined",
|
|
11
|
+
null: (input) => input === null,
|
|
12
|
+
array: (input) => input instanceof Array,
|
|
13
|
+
object: (input) => !!input && typeof input === "object" && !(input instanceof Array),
|
|
14
|
+
};
|
|
15
|
+
function isType(...args) {
|
|
16
|
+
if (args.length === 1) {
|
|
17
|
+
const [type] = args;
|
|
18
|
+
return (input) => isType(input, type);
|
|
19
|
+
}
|
|
20
|
+
const [input, type] = args;
|
|
21
|
+
return testTypeWrapper[type](input);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.isType = isType;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type IsEqual, type AnyFunction } from "./types";
|
|
2
|
+
interface Type {
|
|
3
|
+
string: [string, never];
|
|
4
|
+
number: [number, never];
|
|
5
|
+
boolean: [boolean, never];
|
|
6
|
+
function: [AnyFunction, never];
|
|
7
|
+
bigint: [bigint, never];
|
|
8
|
+
undefined: [undefined, never];
|
|
9
|
+
null: [null, never];
|
|
10
|
+
symbol: [symbol, never];
|
|
11
|
+
object: [object, any[] | AnyFunction];
|
|
12
|
+
array: [any[], never];
|
|
13
|
+
}
|
|
14
|
+
type ComputeResult<GenericInput extends unknown, GenericTypeEntry extends Type[keyof Type]> = Exclude<Extract<GenericInput, GenericTypeEntry[0]>, GenericTypeEntry[1]>;
|
|
15
|
+
type EligibleType<GenericInput extends unknown> = {
|
|
16
|
+
[Prop in keyof Type]: IsEqual<ComputeResult<GenericInput, Type[Prop]>, never> extends true ? never : Prop;
|
|
17
|
+
}[keyof Type];
|
|
18
|
+
export declare function isType<GenericInput extends unknown, GenericType extends EligibleType<GenericInput>>(type: GenericType): (input: GenericInput) => input is ComputeResult<GenericInput, Type[GenericType]>;
|
|
19
|
+
export declare function isType<GenericInput extends unknown, GenericType extends EligibleType<GenericInput>>(input: GenericInput, type: GenericType): input is ComputeResult<GenericInput, Type[GenericType]>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const testTypeWrapper = {
|
|
2
|
+
string: (input) => typeof input === "string",
|
|
3
|
+
number: (input) => typeof input === "number",
|
|
4
|
+
bigint: (input) => typeof input === "bigint",
|
|
5
|
+
boolean: (input) => typeof input === "boolean",
|
|
6
|
+
function: (input) => typeof input === "function",
|
|
7
|
+
symbol: (input) => typeof input === "symbol",
|
|
8
|
+
undefined: (input) => typeof input === "undefined",
|
|
9
|
+
null: (input) => input === null,
|
|
10
|
+
array: (input) => input instanceof Array,
|
|
11
|
+
object: (input) => !!input && typeof input === "object" && !(input instanceof Array),
|
|
12
|
+
};
|
|
13
|
+
function isType(...args) {
|
|
14
|
+
if (args.length === 1) {
|
|
15
|
+
const [type] = args;
|
|
16
|
+
return (input) => isType(input, type);
|
|
17
|
+
}
|
|
18
|
+
const [input, type] = args;
|
|
19
|
+
return testTypeWrapper[type](input);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { isType };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function not<GenericInput extends unknown, GenericPredicatedInput extends GenericInput>(predicate: (input: GenericInput) => input is GenericPredicatedInput): (input: GenericInput) => input is Exclude<GenericInput, GenericPredicatedInput>;
|
|
2
|
+
export declare function not<GenericInput extends unknown, GenericPredicatedInput extends GenericInput>(input: GenericInput, predicate: (input: GenericInput) => input is GenericPredicatedInput): input is Exclude<GenericInput, GenericPredicatedInput>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type AnyFunction } from "./types";
|
|
2
|
+
type ExtractPredicate<GenericInput extends unknown, GenericPredicatedInput extends AnyFunction<any[], boolean>[]> = GenericPredicatedInput extends [
|
|
3
|
+
(input: any) => input is infer InferredPredicate,
|
|
4
|
+
...infer InferredRest extends AnyFunction<any[], boolean>[]
|
|
5
|
+
] ? InferredRest extends readonly [] ? InferredPredicate : InferredPredicate | ExtractPredicate<GenericInput, InferredRest> : GenericInput;
|
|
6
|
+
export declare function or<GenericInput extends unknown, GenericArrayPredicatedInput extends [
|
|
7
|
+
(input: GenericInput) => input is any,
|
|
8
|
+
(input: GenericInput) => input is any,
|
|
9
|
+
...((input: GenericInput) => input is any)[]
|
|
10
|
+
]>(predicatedList: GenericArrayPredicatedInput): (input: GenericInput) => input is Extract<GenericInput, ExtractPredicate<GenericInput, GenericArrayPredicatedInput>>;
|
|
11
|
+
export declare function or<GenericInput extends unknown>(predicatedList: [
|
|
12
|
+
(input: GenericInput) => boolean,
|
|
13
|
+
(input: GenericInput) => boolean,
|
|
14
|
+
...((input: GenericInput) => boolean)[]
|
|
15
|
+
]): (input: GenericInput) => boolean;
|
|
16
|
+
export declare function or<GenericInput extends unknown, GenericArrayPredicatedInput extends [
|
|
17
|
+
(input: GenericInput) => input is any,
|
|
18
|
+
(input: GenericInput) => input is any,
|
|
19
|
+
...((input: GenericInput) => input is any)[]
|
|
20
|
+
]>(input: GenericInput, predicatedList: GenericArrayPredicatedInput): input is Extract<GenericInput, ExtractPredicate<GenericInput, GenericArrayPredicatedInput>>;
|
|
21
|
+
export declare function or<GenericInput extends unknown>(input: GenericInput, predicatedList: [
|
|
22
|
+
(input: GenericInput) => boolean,
|
|
23
|
+
(input: GenericInput) => boolean,
|
|
24
|
+
...((input: GenericInput) => boolean)[]
|
|
25
|
+
]): boolean;
|
|
26
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,9 @@ var loop = require('./common/loop.cjs');
|
|
|
28
28
|
var forward = require('./common/forward.cjs');
|
|
29
29
|
var when = require('./common/when.cjs');
|
|
30
30
|
var whenNot = require('./common/whenNot.cjs');
|
|
31
|
+
var equal = require('./common/equal.cjs');
|
|
32
|
+
var not = require('./common/not.cjs');
|
|
33
|
+
var isType = require('./common/isType.cjs');
|
|
31
34
|
var index = require('./array/index.cjs');
|
|
32
35
|
var index$1 = require('./number/index.cjs');
|
|
33
36
|
var index$2 = require('./either/index.cjs');
|
|
@@ -72,6 +75,9 @@ exports.loop = loop.loop;
|
|
|
72
75
|
exports.forward = forward.forward;
|
|
73
76
|
exports.when = when.when;
|
|
74
77
|
exports.whenNot = whenNot.whenNot;
|
|
78
|
+
exports.equal = equal.equal;
|
|
79
|
+
exports.not = not.not;
|
|
80
|
+
exports.isType = isType.isType;
|
|
75
81
|
exports.A = index;
|
|
76
82
|
exports.DArray = index;
|
|
77
83
|
exports.DNumber = index$1;
|
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,9 @@ export { loop } from './common/loop.mjs';
|
|
|
26
26
|
export { forward } from './common/forward.mjs';
|
|
27
27
|
export { when } from './common/when.mjs';
|
|
28
28
|
export { whenNot } from './common/whenNot.mjs';
|
|
29
|
+
export { equal } from './common/equal.mjs';
|
|
30
|
+
export { not } from './common/not.mjs';
|
|
31
|
+
export { isType } from './common/isType.mjs';
|
|
29
32
|
import * as index from './array/index.mjs';
|
|
30
33
|
export { index as A };
|
|
31
34
|
export { index as DArray };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var equal = require('../common/equal.cjs');
|
|
4
|
+
var getDeepProperty = require('./getDeepProperty.cjs');
|
|
5
|
+
|
|
6
|
+
function deepDiscriminate(...args) {
|
|
7
|
+
if (args.length === 2) {
|
|
8
|
+
const [path, value] = args;
|
|
9
|
+
return (input) => deepDiscriminate(input, path, value);
|
|
10
|
+
}
|
|
11
|
+
const [input, path, value] = args;
|
|
12
|
+
return equal.equal(getDeepProperty.getDeepProperty(input, path), value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.deepDiscriminate = deepDiscriminate;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type EligibleEqual, type MaybeArray } from "../common";
|
|
2
|
+
import { type UnFlatObject, type FlatObject } from "./types";
|
|
3
|
+
import { type GetPropsWithValueExtends } from "./types/getPropsWithValueExtends";
|
|
4
|
+
type ObjectProjection<GenericInput extends object> = FlatObject<GenericInput> extends infer InferredResult extends object ? Omit<Pick<InferredResult, GetPropsWithValueExtends<InferredResult, EligibleEqual>>, `${string}[${string}]${string}`> : never;
|
|
5
|
+
export declare function deepDiscriminate<GenericInput extends object, GenericObjectProjection extends ObjectProjection<GenericInput>, GenericPath extends keyof GenericObjectProjection, GenericValue extends EligibleEqual>(path: GenericPath, value: (MaybeArray<(GenericValue & GenericObjectProjection[GenericPath])> | MaybeArray<GenericObjectProjection[GenericPath]>)): (input: GenericInput) => input is Extract<GenericInput, UnFlatObject<{
|
|
6
|
+
[Prop in GenericPath]: GenericValue;
|
|
7
|
+
}>>;
|
|
8
|
+
export declare function deepDiscriminate<GenericInput extends object, GenericObjectProjection extends ObjectProjection<GenericInput>, GenericPath extends keyof GenericObjectProjection, GenericValue extends EligibleEqual>(input: GenericInput, path: GenericPath, value: (MaybeArray<(GenericValue & GenericObjectProjection[GenericPath])> | MaybeArray<GenericObjectProjection[GenericPath]>)): input is Extract<GenericInput, UnFlatObject<{
|
|
9
|
+
[Prop in GenericPath]: GenericValue;
|
|
10
|
+
}>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { equal } from '../common/equal.mjs';
|
|
2
|
+
import { getDeepProperty } from './getDeepProperty.mjs';
|
|
3
|
+
|
|
4
|
+
function deepDiscriminate(...args) {
|
|
5
|
+
if (args.length === 2) {
|
|
6
|
+
const [path, value] = args;
|
|
7
|
+
return (input) => deepDiscriminate(input, path, value);
|
|
8
|
+
}
|
|
9
|
+
const [input, path, value] = args;
|
|
10
|
+
return equal(getDeepProperty(input, path), value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { deepDiscriminate };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var equal = require('../common/equal.cjs');
|
|
4
|
+
|
|
5
|
+
function discriminate(...args) {
|
|
6
|
+
if (args.length === 2) {
|
|
7
|
+
const [key, value] = args;
|
|
8
|
+
return (input) => discriminate(input, key, value);
|
|
9
|
+
}
|
|
10
|
+
const [input, key, value] = args;
|
|
11
|
+
return equal.equal(input[key], value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.discriminate = discriminate;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EligibleEqual, type MaybeArray } from "../common";
|
|
2
|
+
import { type GetPropsWithValueExtends } from "./types/getPropsWithValueExtends";
|
|
3
|
+
export declare function discriminate<GenericInput extends object, GenericKey extends GetPropsWithValueExtends<GenericInput, EligibleEqual>, GenericValue extends EligibleEqual>(key: GenericKey, value: (MaybeArray<(GenericValue & GenericInput[GenericKey])> | MaybeArray<GenericInput[GenericKey]>)): (input: GenericInput) => input is Extract<GenericInput, {
|
|
4
|
+
[Prop in GenericKey]: GenericValue;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function discriminate<GenericInput extends object, GenericKey extends GetPropsWithValueExtends<GenericInput, EligibleEqual>, GenericValue extends EligibleEqual>(input: GenericInput, key: GenericKey, value: (MaybeArray<(GenericValue & GenericInput[GenericKey])> | MaybeArray<GenericInput[GenericKey]>)): input is Extract<GenericInput, {
|
|
7
|
+
[Prop in GenericKey]: GenericValue;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { equal } from '../common/equal.mjs';
|
|
2
|
+
|
|
3
|
+
function discriminate(...args) {
|
|
4
|
+
if (args.length === 2) {
|
|
5
|
+
const [key, value] = args;
|
|
6
|
+
return (input) => discriminate(input, key, value);
|
|
7
|
+
}
|
|
8
|
+
const [input, key, value] = args;
|
|
9
|
+
return equal(input[key], value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { discriminate };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const regexExtractProperty = /([^.]*)(?:\.([^]*))?/;
|
|
4
|
+
function getDeepProperty(...args) {
|
|
5
|
+
if (args.length === 1) {
|
|
6
|
+
const [path] = args;
|
|
7
|
+
return (input) => getDeepProperty(input, path);
|
|
8
|
+
}
|
|
9
|
+
const [input, path] = args;
|
|
10
|
+
const [_match, first, rest] = path.match(regexExtractProperty);
|
|
11
|
+
const currentValue = input[first];
|
|
12
|
+
if (rest) {
|
|
13
|
+
return getDeepProperty(currentValue, rest);
|
|
14
|
+
}
|
|
15
|
+
return currentValue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.getDeepProperty = getDeepProperty;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type EligibleEqual } from "../common";
|
|
2
|
+
import { type FlatObject, type GetPropsWithValueExtends } from "./types";
|
|
3
|
+
type ObjectProjection<GenericInput extends object> = FlatObject<GenericInput> extends infer InferredResult extends object ? Omit<Pick<InferredResult, GetPropsWithValueExtends<InferredResult, EligibleEqual>>, `${string}[${string}]${string}`> : never;
|
|
4
|
+
export declare function getDeepProperty<GenericInput extends object, GenericObjectProjection extends ObjectProjection<GenericInput>, GenericPath extends keyof GenericObjectProjection>(path: GenericPath): (input: GenericInput) => GenericObjectProjection[GenericPath];
|
|
5
|
+
export declare function getDeepProperty<GenericInput extends object, GenericObjectProjection extends ObjectProjection<GenericInput>, GenericPath extends keyof GenericObjectProjection>(input: GenericInput, path: GenericPath): GenericObjectProjection[GenericPath];
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const regexExtractProperty = /([^.]*)(?:\.([^]*))?/;
|
|
2
|
+
function getDeepProperty(...args) {
|
|
3
|
+
if (args.length === 1) {
|
|
4
|
+
const [path] = args;
|
|
5
|
+
return (input) => getDeepProperty(input, path);
|
|
6
|
+
}
|
|
7
|
+
const [input, path] = args;
|
|
8
|
+
const [_match, first, rest] = path.match(regexExtractProperty);
|
|
9
|
+
const currentValue = input[first];
|
|
10
|
+
if (rest) {
|
|
11
|
+
return getDeepProperty(currentValue, rest);
|
|
12
|
+
}
|
|
13
|
+
return currentValue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getDeepProperty };
|
package/dist/object/index.cjs
CHANGED
|
@@ -13,6 +13,9 @@ var assign = require('./assign.cjs');
|
|
|
13
13
|
var override = require('./override.cjs');
|
|
14
14
|
var omit = require('./omit.cjs');
|
|
15
15
|
var pick = require('./pick.cjs');
|
|
16
|
+
var deepDiscriminate = require('./deepDiscriminate.cjs');
|
|
17
|
+
var getDeepProperty = require('./getDeepProperty.cjs');
|
|
18
|
+
var discriminate = require('./discriminate.cjs');
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
|
|
@@ -29,3 +32,6 @@ exports.assign = assign.assign;
|
|
|
29
32
|
exports.override = override.override;
|
|
30
33
|
exports.omit = omit.omit;
|
|
31
34
|
exports.pick = pick.pick;
|
|
35
|
+
exports.deepDiscriminate = deepDiscriminate.deepDiscriminate;
|
|
36
|
+
exports.getDeepProperty = getDeepProperty.getDeepProperty;
|
|
37
|
+
exports.discriminate = discriminate.discriminate;
|
package/dist/object/index.d.ts
CHANGED
package/dist/object/index.mjs
CHANGED
|
@@ -11,3 +11,6 @@ export { assign } from './assign.mjs';
|
|
|
11
11
|
export { override } from './override.mjs';
|
|
12
12
|
export { omit } from './omit.mjs';
|
|
13
13
|
export { pick } from './pick.mjs';
|
|
14
|
+
export { deepDiscriminate } from './deepDiscriminate.mjs';
|
|
15
|
+
export { getDeepProperty } from './getDeepProperty.mjs';
|
|
16
|
+
export { discriminate } from './discriminate.mjs';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type IsEqual, type Adaptor, type LastUnionElement, type UnionToIntersection, type SimplifyTopLevel, type IsExtends } from "../../common";
|
|
2
|
+
type GroupPath<GenericPath extends string> = IsEqual<GenericPath, never> extends true ? never : LastUnionElement<GenericPath> extends infer InferredLast ? InferredLast extends `${infer InferredFirst}.${string}` ? InferredFirst extends `[${number}]` ? Extract<GenericPath, `[${number}].${string}`> extends infer InferredResult ? ["[tuple]", InferredResult] | GroupPath<Exclude<GenericPath, InferredResult>> : never : Extract<GenericPath, `${InferredFirst}.${string}`> extends infer InferredResult ? [InferredFirst, InferredResult] | GroupPath<Exclude<GenericPath, InferredResult>> : never : InferredLast extends `[${number}]` ? ["[tuple]", Extract<GenericPath, `[${number}]`>] | GroupPath<Exclude<GenericPath, `[${number}]`>> : [InferredLast, InferredLast] | GroupPath<Exclude<GenericPath, InferredLast>> : never;
|
|
3
|
+
type RemoveFirstFromKey<GenericObject extends object, GenericFirst extends string> = {
|
|
4
|
+
[Prop in keyof GenericObject as Prop extends `${GenericFirst}.${infer InferredRst}` ? InferredRst : never]: GenericObject[Prop];
|
|
5
|
+
};
|
|
6
|
+
type UnFlatTuple<GenericObject extends object, GenericGroupPath extends [string, string], GenericLastTuple extends unknown[] = []> = Extract<GenericGroupPath[1], `[${GenericLastTuple["length"]}]${string}`> extends infer InferredElementPath ? IsEqual<InferredElementPath, never> extends true ? GenericLastTuple : (IsEqual<InferredElementPath, `[${GenericLastTuple["length"]}]`> extends true ? [
|
|
7
|
+
...GenericLastTuple,
|
|
8
|
+
GenericObject[Adaptor<InferredElementPath, keyof GenericObject>]
|
|
9
|
+
] : [
|
|
10
|
+
...GenericLastTuple,
|
|
11
|
+
UnFlatObject<RemoveFirstFromKey<Pick<GenericObject, Adaptor<InferredElementPath, keyof GenericObject>>, `[${GenericLastTuple["length"]}]`>>
|
|
12
|
+
]) extends infer InferredResult extends any[] ? UnFlatTuple<GenericObject, GenericGroupPath, InferredResult> : never : never;
|
|
13
|
+
export type UnFlatObject<GenericObject extends object> = GroupPath<Adaptor<keyof GenericObject, string>> extends infer InferredGroupedPath ? (InferredGroupedPath extends [
|
|
14
|
+
infer InferredFirst extends string,
|
|
15
|
+
infer InferredPath extends string
|
|
16
|
+
] ? IsExtends<InferredFirst, "[tuple]"> extends true ? UnFlatTuple<GenericObject, InferredGroupedPath> : IsEqual<InferredFirst, "[number]"> extends true ? IsEqual<InferredFirst, InferredPath> extends true ? GenericObject[Adaptor<InferredFirst, keyof GenericObject>][] : UnFlatObject<RemoveFirstFromKey<Pick<GenericObject, Adaptor<InferredPath, keyof GenericObject>>, InferredFirst>>[] : IsEqual<InferredFirst, InferredPath> extends true ? {
|
|
17
|
+
[Prop in InferredFirst]: GenericObject[Adaptor<Prop, keyof GenericObject>];
|
|
18
|
+
} : {
|
|
19
|
+
[Prop in InferredFirst]: UnFlatObject<RemoveFirstFromKey<Pick<GenericObject, Adaptor<InferredPath, keyof GenericObject>>, InferredFirst>>;
|
|
20
|
+
} : never) extends infer InferredResult ? SimplifyTopLevel<UnionToIntersection<InferredResult>> : never : never;
|
|
21
|
+
export {};
|
package/dist/pattern/index.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
var result = require('./result.cjs');
|
|
4
4
|
var exhaustive = require('./exhaustive.cjs');
|
|
5
5
|
var otherwise = require('./otherwise.cjs');
|
|
6
|
-
var matchPrimitive = require('./matchPrimitive.cjs');
|
|
7
6
|
var match = require('./match.cjs');
|
|
8
7
|
var isMatch = require('./isMatch.cjs');
|
|
9
8
|
var pattern = require('./types/pattern.cjs');
|
|
10
9
|
var union = require('./union.cjs');
|
|
10
|
+
var when = require('./when.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
@@ -15,8 +15,8 @@ exports.isResult = result.isResult;
|
|
|
15
15
|
exports.result = result.result;
|
|
16
16
|
exports.exhaustive = exhaustive.exhaustive;
|
|
17
17
|
exports.otherwise = otherwise.otherwise;
|
|
18
|
-
exports.matchPrimitive = matchPrimitive.matchPrimitive;
|
|
19
18
|
exports.match = match.match;
|
|
20
19
|
exports.isMatch = isMatch.isMatch;
|
|
21
20
|
exports.SymbolToolPatternFunctionLabel = pattern.SymbolToolPatternFunctionLabel;
|
|
22
21
|
exports.union = union.union;
|
|
22
|
+
exports.when = when.when;
|
package/dist/pattern/index.d.ts
CHANGED
package/dist/pattern/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { isResult, result } from './result.mjs';
|
|
2
2
|
export { exhaustive } from './exhaustive.mjs';
|
|
3
3
|
export { otherwise } from './otherwise.mjs';
|
|
4
|
-
export { matchPrimitive } from './matchPrimitive.mjs';
|
|
5
4
|
export { match } from './match.mjs';
|
|
6
5
|
export { isMatch } from './isMatch.mjs';
|
|
7
6
|
export { SymbolToolPatternFunctionLabel } from './types/pattern.mjs';
|
|
8
7
|
export { union } from './union.mjs';
|
|
8
|
+
export { when } from './when.mjs';
|
package/dist/pattern/isMatch.cjs
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
var pattern = require('./types/pattern.cjs');
|
|
4
4
|
|
|
5
5
|
const SymbolToolPatternFunction = Symbol.for(pattern.SymbolToolPatternFunctionLabel);
|
|
6
|
-
function isMatch(
|
|
6
|
+
function isMatch(...args) {
|
|
7
|
+
if (args.length === 1) {
|
|
8
|
+
const [pattern] = args;
|
|
9
|
+
return (input) => isMatch(input, pattern);
|
|
10
|
+
}
|
|
11
|
+
const [input, pattern] = args;
|
|
7
12
|
if (typeof pattern === "string"
|
|
8
13
|
|| typeof pattern === "number"
|
|
9
14
|
|| typeof pattern === "boolean"
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { type ForcePredicate, type AnyValue, type FixDeepFunctionInfer } from "../common";
|
|
2
|
+
import { type Pattern, type PatternValue } from "./types/pattern";
|
|
3
|
+
import { type ComplexMatchedValue } from "./types";
|
|
4
|
+
export declare function isMatch<GenericInput extends AnyValue, const GenericPattern extends Pattern<GenericInput>>(pattern: FixDeepFunctionInfer<Pattern<GenericInput>, GenericPattern>): (input: GenericInput) => input is ForcePredicate<GenericInput, ComplexMatchedValue<GenericInput, PatternValue<GenericPattern>>>;
|
|
5
|
+
export declare function isMatch<GenericInput extends AnyValue, const GenericPattern extends Pattern<GenericInput>>(input: GenericInput, pattern: FixDeepFunctionInfer<Pattern<GenericInput>, GenericPattern>): input is ForcePredicate<GenericInput, ComplexMatchedValue<GenericInput, PatternValue<GenericPattern>>>;
|
package/dist/pattern/isMatch.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { SymbolToolPatternFunctionLabel } from './types/pattern.mjs';
|
|
2
2
|
|
|
3
3
|
const SymbolToolPatternFunction = Symbol.for(SymbolToolPatternFunctionLabel);
|
|
4
|
-
function isMatch(
|
|
4
|
+
function isMatch(...args) {
|
|
5
|
+
if (args.length === 1) {
|
|
6
|
+
const [pattern] = args;
|
|
7
|
+
return (input) => isMatch(input, pattern);
|
|
8
|
+
}
|
|
9
|
+
const [input, pattern] = args;
|
|
5
10
|
if (typeof pattern === "string"
|
|
6
11
|
|| typeof pattern === "number"
|
|
7
12
|
|| typeof pattern === "boolean"
|
package/dist/pattern/match.cjs
CHANGED
|
@@ -9,7 +9,7 @@ function match(...args) {
|
|
|
9
9
|
return (input) => match(input, pattern, theFunction);
|
|
10
10
|
}
|
|
11
11
|
const [input, pattern, theFunction] = args;
|
|
12
|
-
if (isMatch.isMatch(input, pattern)) {
|
|
12
|
+
if (!result.isResult(input) && isMatch.isMatch(input, pattern)) {
|
|
13
13
|
return result.result(theFunction(input));
|
|
14
14
|
}
|
|
15
15
|
return input;
|
package/dist/pattern/match.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { result } from './result.mjs';
|
|
1
|
+
import { isResult, result } from './result.mjs';
|
|
2
2
|
import { isMatch } from './isMatch.mjs';
|
|
3
3
|
|
|
4
4
|
function match(...args) {
|
|
@@ -7,7 +7,7 @@ function match(...args) {
|
|
|
7
7
|
return (input) => match(input, pattern, theFunction);
|
|
8
8
|
}
|
|
9
9
|
const [input, pattern, theFunction] = args;
|
|
10
|
-
if (isMatch(input, pattern)) {
|
|
10
|
+
if (!isResult(input) && isMatch(input, pattern)) {
|
|
11
11
|
return result(theFunction(input));
|
|
12
12
|
}
|
|
13
13
|
return input;
|
package/dist/pattern/result.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var wrapValue = require('../common/wrapValue.cjs');
|
|
|
5
5
|
|
|
6
6
|
const patternResultKind = kind.createKind("pattern-result");
|
|
7
7
|
function result(value) {
|
|
8
|
-
return patternResultKind.addTo(wrapValue.wrapValue(value)
|
|
8
|
+
return patternResultKind.addTo(wrapValue.wrapValue(value));
|
|
9
9
|
}
|
|
10
10
|
const isResult = patternResultKind.has;
|
|
11
11
|
|
package/dist/pattern/result.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { wrapValue } from '../common/wrapValue.mjs';
|
|
|
3
3
|
|
|
4
4
|
const patternResultKind = createKind("pattern-result");
|
|
5
5
|
function result(value) {
|
|
6
|
-
return patternResultKind.addTo(wrapValue(value)
|
|
6
|
+
return patternResultKind.addTo(wrapValue(value));
|
|
7
7
|
}
|
|
8
8
|
const isResult = patternResultKind.has;
|
|
9
9
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var result = require('./result.cjs');
|
|
4
|
+
|
|
5
|
+
function when(...args) {
|
|
6
|
+
if (args.length === 2) {
|
|
7
|
+
const [predicate, theFunction] = args;
|
|
8
|
+
return (input) => when(input, predicate, theFunction);
|
|
9
|
+
}
|
|
10
|
+
const [input, predicate, theFunction] = args;
|
|
11
|
+
if (!result.isResult(input) && predicate(input)) {
|
|
12
|
+
return result.result(theFunction(input));
|
|
13
|
+
}
|
|
14
|
+
return input;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.when = when;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AnyValue } from "../common";
|
|
2
|
+
import { type PatternResult } from "./result";
|
|
3
|
+
export declare function when<GenericInput extends AnyValue, GenericInputValue extends Exclude<GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericPredicatedInput extends GenericInputValue, GenericOutput extends AnyValue>(predicate: (input: GenericInputValue) => input is GenericPredicatedInput, theFunction: (predicatedInput: GenericPredicatedInput) => GenericOutput): (input: (GenericInput | GenericInputPatternResult | GenericInputValue)) => (GenericInputPatternResult | Exclude<GenericInputValue, GenericPredicatedInput> | PatternResult<GenericOutput>);
|
|
4
|
+
export declare function when<GenericInput extends AnyValue, GenericInputValue extends Exclude<GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericOutput extends AnyValue>(predicate: (input: GenericInputValue) => boolean, theFunction: (predicatedInput: GenericInputValue) => GenericOutput): (input: (GenericInput | GenericInputPatternResult | GenericInputValue)) => (GenericInputPatternResult | GenericInputValue | PatternResult<GenericOutput>);
|
|
5
|
+
export declare function when<GenericInput extends AnyValue, GenericInputValue extends Exclude<GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericPredicatedInput extends GenericInputValue, GenericOutput extends AnyValue>(input: (GenericInput | GenericInputPatternResult | GenericInputValue), predicate: (input: GenericInputValue) => input is GenericPredicatedInput, theFunction: (predicatedInput: GenericPredicatedInput) => GenericOutput): (GenericInputPatternResult | Exclude<GenericInputValue, GenericPredicatedInput> | PatternResult<GenericOutput>);
|
|
6
|
+
export declare function when<GenericInput extends AnyValue, GenericInputValue extends Exclude<GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericOutput extends AnyValue>(input: (GenericInput | GenericInputPatternResult | GenericInputValue), predicate: (input: GenericInputValue) => boolean, theFunction: (predicatedInput: GenericInputValue) => GenericOutput): (GenericInputPatternResult | GenericInputValue | PatternResult<GenericOutput>);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isResult, result } from './result.mjs';
|
|
2
|
+
|
|
3
|
+
function when(...args) {
|
|
4
|
+
if (args.length === 2) {
|
|
5
|
+
const [predicate, theFunction] = args;
|
|
6
|
+
return (input) => when(input, predicate, theFunction);
|
|
7
|
+
}
|
|
8
|
+
const [input, predicate, theFunction] = args;
|
|
9
|
+
if (!isResult(input) && predicate(input)) {
|
|
10
|
+
return result(theFunction(input));
|
|
11
|
+
}
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { when };
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type IsEqual } from "../common";
|
|
2
|
+
type ComputeResult<GenericString extends string, GenericSearchString extends string> = Extract<GenericString, `${string}${GenericSearchString}`> extends infer InferredResult extends GenericString ? IsEqual<InferredResult, never> extends true ? GenericString & `${string}${GenericSearchString}` : InferredResult : never;
|
|
3
|
+
export declare function endsWith<GenericString extends string, GenericSearchString extends string>(searchString: GenericSearchString): (input: GenericString) => input is ComputeResult<GenericString, GenericSearchString>;
|
|
4
|
+
export declare function endsWith<GenericString extends string, GenericSearchString extends string>(input: GenericString, searchString: GenericSearchString): input is ComputeResult<GenericString, GenericSearchString>;
|
|
5
|
+
export {};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type IsEqual } from "../common";
|
|
2
|
+
type ComputeResult<GenericString extends string, GenericSearchString extends string> = Extract<GenericString, `${string}${GenericSearchString}${string}`> extends infer InferredResult extends GenericString ? IsEqual<InferredResult, never> extends true ? GenericString & `${string}${GenericSearchString}${string}` : InferredResult : never;
|
|
3
|
+
export declare function includes<GenericString extends string, GenericSearchString extends string>(searchString: GenericSearchString): (input: GenericString) => input is ComputeResult<GenericString, GenericSearchString>;
|
|
4
|
+
export declare function includes<GenericString extends string, GenericSearchString extends string>(input: GenericString, searchString: GenericSearchString): input is ComputeResult<GenericString, GenericSearchString>;
|
|
5
|
+
export {};
|
package/dist/string/isIn.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function isIn<GenericInput extends string, GenericValue extends
|
|
2
|
-
export declare function isIn<GenericInput extends string, GenericValue extends
|
|
1
|
+
export declare function isIn<GenericInput extends string, GenericValue extends GenericInput>(array: readonly GenericValue[]): (input: GenericInput) => input is Extract<GenericInput, GenericValue>;
|
|
2
|
+
export declare function isIn<GenericInput extends string, GenericValue extends GenericInput>(input: GenericInput, array: readonly GenericValue[]): input is Extract<GenericInput, GenericValue>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type IsEqual } from "../common";
|
|
2
|
+
type ComputeResult<GenericString extends string, GenericSearchString extends string> = Extract<GenericString, `${GenericSearchString}${string}`> extends infer InferredResult extends GenericString ? IsEqual<InferredResult, never> extends true ? GenericString & `${GenericSearchString}${string}` : InferredResult : never;
|
|
3
|
+
export declare function startsWith<GenericString extends string, GenericSearchString extends string>(searchString: GenericSearchString): (input: GenericString) => input is ComputeResult<GenericString, GenericSearchString>;
|
|
4
|
+
export declare function startsWith<GenericString extends string, GenericSearchString extends string>(input: GenericString, searchString: GenericSearchString): input is ComputeResult<GenericString, GenericSearchString>;
|
|
5
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var result = require('./result.cjs');
|
|
4
|
-
|
|
5
|
-
function matchPrimitive(primitive, theFunction) {
|
|
6
|
-
const formattedPrimitive = primitive instanceof Array
|
|
7
|
-
? primitive
|
|
8
|
-
: [primitive];
|
|
9
|
-
return (input) => {
|
|
10
|
-
if (!result.isResult(input) && formattedPrimitive.includes(input)) {
|
|
11
|
-
return result.result(theFunction(input));
|
|
12
|
-
}
|
|
13
|
-
return input;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.matchPrimitive = matchPrimitive;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type AnyValue } from "..";
|
|
2
|
-
import { type PatternResult } from "./result";
|
|
3
|
-
export declare function matchPrimitive<GenericInput extends AnyValue, GenericMatch extends Exclude<GenericInput, PatternResult>, GenericOutput extends AnyValue>(primitive: GenericMatch | GenericMatch[], theFunction: (predicatedInput: Extract<GenericInput, GenericMatch>) => GenericOutput): (input: GenericInput) => PatternResult<GenericOutput> | Exclude<GenericInput, GenericMatch>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { isResult, result } from './result.mjs';
|
|
2
|
-
|
|
3
|
-
function matchPrimitive(primitive, theFunction) {
|
|
4
|
-
const formattedPrimitive = primitive instanceof Array
|
|
5
|
-
? primitive
|
|
6
|
-
: [primitive];
|
|
7
|
-
return (input) => {
|
|
8
|
-
if (!isResult(input) && formattedPrimitive.includes(input)) {
|
|
9
|
-
return result(theFunction(input));
|
|
10
|
-
}
|
|
11
|
-
return input;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { matchPrimitive };
|