@duplojs/utils 1.1.11 → 1.1.13
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/array/index.cjs +2 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.mjs +1 -0
- package/dist/array/toTuple.cjs +12 -0
- package/dist/array/toTuple.d.ts +12 -0
- package/dist/array/toTuple.mjs +10 -0
- package/dist/common/equal.d.ts +13 -2
- package/dist/common/kind.cjs +15 -12
- package/dist/common/kind.d.ts +2 -2
- package/dist/common/kind.mjs +15 -12
- package/dist/common/types/index.d.ts +1 -0
- package/dist/common/types/unwrapArray.d.ts +1 -0
- package/dist/string/types/digit.d.ts +1 -0
- package/dist/string/types/index.d.ts +2 -0
- package/dist/string/types/number.d.ts +1 -0
- package/package.json +1 -1
package/dist/array/index.cjs
CHANGED
|
@@ -50,6 +50,7 @@ var replace$1 = require('./findAndSplice/replace.cjs');
|
|
|
50
50
|
var sum = require('./sum.cjs');
|
|
51
51
|
var length = require('./length.cjs');
|
|
52
52
|
var coalescing = require('./coalescing.cjs');
|
|
53
|
+
var toTuple = require('./toTuple.cjs');
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
|
|
@@ -105,3 +106,4 @@ exports.findAndSpliceReplace = replace$1.findAndSpliceReplace;
|
|
|
105
106
|
exports.sum = sum.sum;
|
|
106
107
|
exports.length = length.length;
|
|
107
108
|
exports.coalescing = coalescing.coalescing;
|
|
109
|
+
exports.toTuple = toTuple.toTuple;
|
package/dist/array/index.d.ts
CHANGED
package/dist/array/index.mjs
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function toTuple(...args) {
|
|
4
|
+
if (args.length === 1) {
|
|
5
|
+
const [shape] = args;
|
|
6
|
+
return (input) => toTuple(input, shape);
|
|
7
|
+
}
|
|
8
|
+
const [input, shapeObject] = args;
|
|
9
|
+
return shapeObject.map((theFunction) => theFunction(input));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.toTuple = toTuple;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type FixDeepFunctionInfer, type AnyFunction } from "../common";
|
|
2
|
+
type ShapeTuple<GenericInput extends unknown = unknown> = readonly [
|
|
3
|
+
(input: GenericInput) => unknown,
|
|
4
|
+
...((input: GenericInput) => unknown)[]
|
|
5
|
+
];
|
|
6
|
+
type ComputesResult<GenericShapeTuple extends ShapeTuple<any>> = GenericShapeTuple extends readonly [
|
|
7
|
+
infer InferredFirst extends AnyFunction,
|
|
8
|
+
...infer InferredRest extends ShapeTuple<any> | readonly []
|
|
9
|
+
] ? InferredRest extends ShapeTuple<any> ? ComputesResult<InferredRest> extends infer inferredResult extends readonly any[] ? [ReturnType<InferredFirst>, ...inferredResult] : never : [ReturnType<InferredFirst>] : never;
|
|
10
|
+
export declare function toTuple<GenericInput extends unknown, GenericShapeTuple extends ShapeTuple<NoInfer<GenericInput>>>(shapeObject: ShapeTuple<NoInfer<GenericInput>> & GenericShapeTuple): (input: GenericInput) => ComputesResult<NoInfer<GenericShapeTuple>>;
|
|
11
|
+
export declare function toTuple<GenericInput extends unknown, GenericShapeTuple extends ShapeTuple<GenericInput>>(input: GenericInput, shapeObject: FixDeepFunctionInfer<ShapeTuple<GenericInput>, GenericShapeTuple>): ComputesResult<GenericShapeTuple>;
|
|
12
|
+
export {};
|
package/dist/common/equal.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { type Or, type UnionContain } from "./types";
|
|
1
2
|
export type EligibleEqual = string | null | number | undefined | bigint | boolean | symbol;
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
type ExpectLiteral<GenericValue extends EligibleEqual> = Or<[
|
|
4
|
+
UnionContain<GenericValue, string>,
|
|
5
|
+
UnionContain<GenericValue, number>,
|
|
6
|
+
UnionContain<GenericValue, boolean>,
|
|
7
|
+
UnionContain<GenericValue, bigint>,
|
|
8
|
+
UnionContain<GenericValue, symbol>
|
|
9
|
+
]> extends true ? never : GenericValue;
|
|
10
|
+
export declare function equal<GenericInput extends EligibleEqual, GenericValue extends GenericInput>(value: ExpectLiteral<GenericValue> | ExpectLiteral<GenericValue>[]): (input: GenericInput) => input is NoInfer<GenericValue>;
|
|
11
|
+
export declare function equal<GenericInput extends EligibleEqual, GenericValue extends GenericInput>(value: GenericValue | GenericValue[]): (input: GenericInput) => boolean;
|
|
12
|
+
export declare function equal<GenericInput extends EligibleEqual, GenericValue extends GenericInput>(input: GenericInput, value: ExpectLiteral<GenericValue> | ExpectLiteral<GenericValue>[]): input is GenericValue;
|
|
13
|
+
export declare function equal<GenericInput extends EligibleEqual, GenericValue extends GenericInput>(input: GenericInput, value: GenericValue | GenericValue[]): boolean;
|
|
14
|
+
export {};
|
package/dist/common/kind.cjs
CHANGED
|
@@ -35,22 +35,21 @@ function createKindNamespace(namespace) {
|
|
|
35
35
|
return kindHandler;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function kindHeritage(uniqueName, kind) {
|
|
38
|
+
function kindHeritage(uniqueName, kind, parent) {
|
|
39
39
|
const uniqueKind = createKind(uniqueName);
|
|
40
40
|
const kinds = kind instanceof Array
|
|
41
41
|
? kind
|
|
42
42
|
: [kind];
|
|
43
|
-
const
|
|
44
|
-
for (const kind of kinds) {
|
|
45
|
-
this[kind.runTimeKey] = params[kind.definition.name] ?? null;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
kinds.forEach((value) => {
|
|
49
|
-
ParentKindClass.prototype[value.runTimeKey] = null;
|
|
43
|
+
const Extendable = (parent ?? class {
|
|
50
44
|
});
|
|
51
|
-
ParentKindClass
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
const ParentKindClass = (class extends Extendable {
|
|
46
|
+
constructor(params = {}, parentParams = []) {
|
|
47
|
+
super(...parentParams);
|
|
48
|
+
for (const kind of kinds) {
|
|
49
|
+
this[kind.runTimeKey] = params[kind.definition.name] ?? null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static [Symbol.hasInstance](value) {
|
|
54
53
|
if (!uniqueKind.has(value)) {
|
|
55
54
|
return false;
|
|
56
55
|
}
|
|
@@ -60,8 +59,12 @@ function kindHeritage(uniqueName, kind) {
|
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
return true;
|
|
63
|
-
}
|
|
62
|
+
}
|
|
64
63
|
});
|
|
64
|
+
kinds.forEach((value) => {
|
|
65
|
+
ParentKindClass.prototype[value.runTimeKey] = null;
|
|
66
|
+
});
|
|
67
|
+
ParentKindClass.prototype[uniqueKind.runTimeKey] = null;
|
|
65
68
|
return ParentKindClass;
|
|
66
69
|
}
|
|
67
70
|
function isRuntimeKind(value) {
|
package/dist/common/kind.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ForbiddenString } from "../string";
|
|
2
|
-
import { type Or, type IsEqual, type BreakGenericLink, type Adaptor, type UnionToIntersection } from "./types";
|
|
2
|
+
import { type Or, type IsEqual, type BreakGenericLink, type Adaptor, type UnionToIntersection, type AnyConstructor, type NeverCoalescing, type And } from "./types";
|
|
3
3
|
import { type GetPropsWithValue, type PartialKeys } from "../object";
|
|
4
4
|
export interface KindHandler<GenericKindDefinition extends KindDefinition = KindDefinition> {
|
|
5
5
|
definition: GenericKindDefinition;
|
|
@@ -49,6 +49,6 @@ export declare function createKindNamespace<GenericNamespace extends string>(nam
|
|
|
49
49
|
export type KindHeritageConstructorParams<GenericKindHandler extends KindHandler> = {
|
|
50
50
|
[KindHandler in GenericKindHandler as KindHandler["definition"]["name"]]: KindHandler["definition"]["value"];
|
|
51
51
|
} extends infer InferredResult extends object ? PartialKeys<InferredResult, GetPropsWithValue<InferredResult, unknown>> : never;
|
|
52
|
-
export declare function kindHeritage<GenericUniqueName extends string, GenericKindHandler extends KindHandler>(uniqueName: GenericUniqueName & ForbiddenKindCharacters<GenericUniqueName>, kind: GenericKindHandler | GenericKindHandler[]): new (...args: IsEqual<GenericKindHandler extends KindHandler ? IsEqual<GenericKindHandler["definition"]["value"], unknown> : never, true> extends true ? [params?: KindHeritageConstructorParams<GenericKindHandler>] : [params: KindHeritageConstructorParams<GenericKindHandler>]) => UnionToIntersection<(GenericKindHandler extends KindHandler ? Kind<GenericKindHandler["definition"]> : never) | Kind<KindDefinition<GenericUniqueName, unknown
|
|
52
|
+
export declare function kindHeritage<GenericUniqueName extends string, GenericKindHandler extends KindHandler, GenericParent extends AnyConstructor = never>(uniqueName: GenericUniqueName & ForbiddenKindCharacters<GenericUniqueName>, kind: GenericKindHandler | GenericKindHandler[], parent?: GenericParent): new (...args: And<[IsEqual<GenericKindHandler extends KindHandler ? IsEqual<GenericKindHandler["definition"]["value"], unknown> : never, true>, IsEqual<GenericParent, never>]> extends true ? [params?: KindHeritageConstructorParams<GenericKindHandler>] : [params: KindHeritageConstructorParams<GenericKindHandler>, ...parentArgs: IsEqual<ConstructorParameters<GenericParent>, never> extends true ? [parentParams?: ConstructorParameters<GenericParent>] : [parentParams: ConstructorParameters<GenericParent>]]) => UnionToIntersection<(GenericKindHandler extends KindHandler ? Kind<GenericKindHandler["definition"]> : never) | Kind<KindDefinition<GenericUniqueName, unknown>> | NeverCoalescing<GenericParent, {}>>;
|
|
53
53
|
export declare function isRuntimeKind(value: string): boolean;
|
|
54
54
|
export {};
|
package/dist/common/kind.mjs
CHANGED
|
@@ -33,22 +33,21 @@ function createKindNamespace(namespace) {
|
|
|
33
33
|
return kindHandler;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
function kindHeritage(uniqueName, kind) {
|
|
36
|
+
function kindHeritage(uniqueName, kind, parent) {
|
|
37
37
|
const uniqueKind = createKind(uniqueName);
|
|
38
38
|
const kinds = kind instanceof Array
|
|
39
39
|
? kind
|
|
40
40
|
: [kind];
|
|
41
|
-
const
|
|
42
|
-
for (const kind of kinds) {
|
|
43
|
-
this[kind.runTimeKey] = params[kind.definition.name] ?? null;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
kinds.forEach((value) => {
|
|
47
|
-
ParentKindClass.prototype[value.runTimeKey] = null;
|
|
41
|
+
const Extendable = (parent ?? class {
|
|
48
42
|
});
|
|
49
|
-
ParentKindClass
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const ParentKindClass = (class extends Extendable {
|
|
44
|
+
constructor(params = {}, parentParams = []) {
|
|
45
|
+
super(...parentParams);
|
|
46
|
+
for (const kind of kinds) {
|
|
47
|
+
this[kind.runTimeKey] = params[kind.definition.name] ?? null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
static [Symbol.hasInstance](value) {
|
|
52
51
|
if (!uniqueKind.has(value)) {
|
|
53
52
|
return false;
|
|
54
53
|
}
|
|
@@ -58,8 +57,12 @@ function kindHeritage(uniqueName, kind) {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
return true;
|
|
61
|
-
}
|
|
60
|
+
}
|
|
62
61
|
});
|
|
62
|
+
kinds.forEach((value) => {
|
|
63
|
+
ParentKindClass.prototype[value.runTimeKey] = null;
|
|
64
|
+
});
|
|
65
|
+
ParentKindClass.prototype[uniqueKind.runTimeKey] = null;
|
|
63
66
|
return ParentKindClass;
|
|
64
67
|
}
|
|
65
68
|
function isRuntimeKind(value) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UnwrapArray<GenericValue extends unknown> = GenericValue extends readonly any[] ? GenericValue[number] : GenericValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Number = `${number}`;
|