@infra-blocks/types 0.20.0 → 0.21.0
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/lib/cjs/func.d.ts +32 -3
- package/lib/esm/func.d.ts +32 -3
- package/package.json +2 -1
package/lib/cjs/func.d.ts
CHANGED
|
@@ -9,16 +9,28 @@ export type AbstractConstructor<R = object, A extends any[] = any[]> = abstract
|
|
|
9
9
|
*/
|
|
10
10
|
export type AsyncFactory<P extends unknown[], R> = (...params: P) => Promise<R>;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The async flavor of {@link Parser}.
|
|
13
|
+
*/
|
|
14
|
+
export type AsyncParser<Output, Input = unknown> = (input: Input) => Promise<Output>;
|
|
15
|
+
/**
|
|
16
|
+
* The async flavor of {@link Predicate}.
|
|
17
|
+
*/
|
|
18
|
+
export type AsyncPredicate<T> = (item: T) => Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* The async flavor of {@link Provider}.
|
|
13
21
|
*/
|
|
14
22
|
export type AsyncProvider<T> = () => Promise<T>;
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
24
|
+
* The async flavor of {@link Transform}.
|
|
25
|
+
*/
|
|
26
|
+
export type AsyncTransform<I, O> = (input: I) => Promise<O>;
|
|
27
|
+
/**
|
|
28
|
+
* Convenient type to easily represent any "callable" types and to avoid using
|
|
17
29
|
* "any" in client code.
|
|
18
30
|
*/
|
|
19
31
|
export type Callable = (...args: never[]) => unknown;
|
|
20
32
|
/**
|
|
21
|
-
* Convenient type alias for constructors.
|
|
33
|
+
* Convenient type alias for *callable* constructors (excluding abstract ones).
|
|
22
34
|
*/
|
|
23
35
|
export type Constructor<R = object, A extends any[] = any[]> = new (...args: A) => R;
|
|
24
36
|
/**
|
|
@@ -29,6 +41,15 @@ export type ErrorHandler<T extends Error = Error> = (err: T) => void;
|
|
|
29
41
|
* A type alias for a function that creates objects of a given type.
|
|
30
42
|
*/
|
|
31
43
|
export type Factory<P extends unknown[], R> = (...params: P) => R;
|
|
44
|
+
/**
|
|
45
|
+
* A type alias for parser functions.
|
|
46
|
+
*
|
|
47
|
+
* The input of parser functions defaults to `unknown`, but can be specified.
|
|
48
|
+
* Parsers are functions that take loosely typed input and return a stricter version,
|
|
49
|
+
* often performing validation in the process. Parsers should be expected to throw
|
|
50
|
+
* errors on validation failures.
|
|
51
|
+
*/
|
|
52
|
+
export type Parser<O, I = unknown> = Transform<I, O>;
|
|
32
53
|
/**
|
|
33
54
|
* A type alias for single element predicate functions.
|
|
34
55
|
*/
|
|
@@ -37,6 +58,14 @@ export type Predicate<T> = (item: T) => boolean;
|
|
|
37
58
|
* A type alias for functions that return a value of a given type without arguments.
|
|
38
59
|
*/
|
|
39
60
|
export type Provider<T> = () => T;
|
|
61
|
+
/**
|
|
62
|
+
* A type alias for transformation functions.
|
|
63
|
+
*
|
|
64
|
+
* A transform takes a value of type I and returns a value of type O. Unlike {@link Parser},
|
|
65
|
+
* transforms are typically not expected to perform validation and therefore aren't
|
|
66
|
+
* expected to throw errors.
|
|
67
|
+
*/
|
|
68
|
+
export type Transform<I, O> = (input: I) => O;
|
|
40
69
|
/**
|
|
41
70
|
* A type alias for type guards.
|
|
42
71
|
*/
|
package/lib/esm/func.d.ts
CHANGED
|
@@ -9,16 +9,28 @@ export type AbstractConstructor<R = object, A extends any[] = any[]> = abstract
|
|
|
9
9
|
*/
|
|
10
10
|
export type AsyncFactory<P extends unknown[], R> = (...params: P) => Promise<R>;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The async flavor of {@link Parser}.
|
|
13
|
+
*/
|
|
14
|
+
export type AsyncParser<Output, Input = unknown> = (input: Input) => Promise<Output>;
|
|
15
|
+
/**
|
|
16
|
+
* The async flavor of {@link Predicate}.
|
|
17
|
+
*/
|
|
18
|
+
export type AsyncPredicate<T> = (item: T) => Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* The async flavor of {@link Provider}.
|
|
13
21
|
*/
|
|
14
22
|
export type AsyncProvider<T> = () => Promise<T>;
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
24
|
+
* The async flavor of {@link Transform}.
|
|
25
|
+
*/
|
|
26
|
+
export type AsyncTransform<I, O> = (input: I) => Promise<O>;
|
|
27
|
+
/**
|
|
28
|
+
* Convenient type to easily represent any "callable" types and to avoid using
|
|
17
29
|
* "any" in client code.
|
|
18
30
|
*/
|
|
19
31
|
export type Callable = (...args: never[]) => unknown;
|
|
20
32
|
/**
|
|
21
|
-
* Convenient type alias for constructors.
|
|
33
|
+
* Convenient type alias for *callable* constructors (excluding abstract ones).
|
|
22
34
|
*/
|
|
23
35
|
export type Constructor<R = object, A extends any[] = any[]> = new (...args: A) => R;
|
|
24
36
|
/**
|
|
@@ -29,6 +41,15 @@ export type ErrorHandler<T extends Error = Error> = (err: T) => void;
|
|
|
29
41
|
* A type alias for a function that creates objects of a given type.
|
|
30
42
|
*/
|
|
31
43
|
export type Factory<P extends unknown[], R> = (...params: P) => R;
|
|
44
|
+
/**
|
|
45
|
+
* A type alias for parser functions.
|
|
46
|
+
*
|
|
47
|
+
* The input of parser functions defaults to `unknown`, but can be specified.
|
|
48
|
+
* Parsers are functions that take loosely typed input and return a stricter version,
|
|
49
|
+
* often performing validation in the process. Parsers should be expected to throw
|
|
50
|
+
* errors on validation failures.
|
|
51
|
+
*/
|
|
52
|
+
export type Parser<O, I = unknown> = Transform<I, O>;
|
|
32
53
|
/**
|
|
33
54
|
* A type alias for single element predicate functions.
|
|
34
55
|
*/
|
|
@@ -37,6 +58,14 @@ export type Predicate<T> = (item: T) => boolean;
|
|
|
37
58
|
* A type alias for functions that return a value of a given type without arguments.
|
|
38
59
|
*/
|
|
39
60
|
export type Provider<T> = () => T;
|
|
61
|
+
/**
|
|
62
|
+
* A type alias for transformation functions.
|
|
63
|
+
*
|
|
64
|
+
* A transform takes a value of type I and returns a value of type O. Unlike {@link Parser},
|
|
65
|
+
* transforms are typically not expected to perform validation and therefore aren't
|
|
66
|
+
* expected to throw errors.
|
|
67
|
+
*/
|
|
68
|
+
export type Transform<I, O> = (input: I) => O;
|
|
40
69
|
/**
|
|
41
70
|
* A type alias for type guards.
|
|
42
71
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infra-blocks/types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Typescript types utility package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"type",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@typescript-eslint/parser": "^5.59.8",
|
|
47
47
|
"c8": "^8.0.0",
|
|
48
48
|
"conditional-type-checks": "^1.0.6",
|
|
49
|
+
"expect-type": "^1.3.0",
|
|
49
50
|
"lefthook": "^2.0.8",
|
|
50
51
|
"mocha": "^10.2.0",
|
|
51
52
|
"ts-node": "^10.9.1",
|