@orkestrel/validator 0.0.1
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/README.md +948 -0
- package/dist/arrays.d.ts +168 -0
- package/dist/collections.d.ts +72 -0
- package/dist/constants.d.ts +13 -0
- package/dist/emptiness.d.ts +119 -0
- package/dist/errors.d.ts +29 -0
- package/dist/factories.d.ts +24 -0
- package/dist/functions.d.ts +85 -0
- package/dist/guards.d.ts +297 -0
- package/dist/helpers.d.ts +223 -0
- package/dist/index.cjs +781 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +781 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives.d.ts +219 -0
- package/dist/types.d.ts +256 -0
- package/package.json +50 -0
package/dist/arrays.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow an unknown value to an array.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Value to test.
|
|
5
|
+
* @returns `true` when the value is an array.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isArray([1, 2])
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function isArray<T = unknown>(value: readonly T[]): boolean;
|
|
12
|
+
export declare function isArray<T = unknown>(value: unknown): value is readonly T[];
|
|
13
|
+
/**
|
|
14
|
+
* Narrow an unknown value to `DataView`.
|
|
15
|
+
*
|
|
16
|
+
* @param value - Value to test.
|
|
17
|
+
* @returns `true` when the value is a `DataView`.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* isDataView(new DataView(new ArrayBuffer(8)))
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function isDataView(value: DataView): boolean;
|
|
24
|
+
export declare function isDataView(value: unknown): value is DataView;
|
|
25
|
+
/**
|
|
26
|
+
* Narrow an unknown value to any `ArrayBufferView`.
|
|
27
|
+
*
|
|
28
|
+
* @param value - Value to test.
|
|
29
|
+
* @returns `true` when the value is a typed array or `DataView`.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* isArrayBufferView(new Uint8Array(4))
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function isArrayBufferView(value: ArrayBufferView): boolean;
|
|
36
|
+
export declare function isArrayBufferView(value: unknown): value is ArrayBufferView;
|
|
37
|
+
/**
|
|
38
|
+
* Narrow an unknown value to `Int8Array`.
|
|
39
|
+
*
|
|
40
|
+
* @param value - Value to test.
|
|
41
|
+
* @returns `true` when the value is an `Int8Array`.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* isInt8Array(new Int8Array(1))
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function isInt8Array(value: Int8Array): boolean;
|
|
48
|
+
export declare function isInt8Array(value: unknown): value is Int8Array;
|
|
49
|
+
/**
|
|
50
|
+
* Narrow an unknown value to `Uint8Array`.
|
|
51
|
+
*
|
|
52
|
+
* @param value - Value to test.
|
|
53
|
+
* @returns `true` when the value is a `Uint8Array`.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* isUint8Array(new Uint8Array(1))
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function isUint8Array(value: Uint8Array): boolean;
|
|
60
|
+
export declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* Narrow an unknown value to `Uint8ClampedArray`.
|
|
63
|
+
*
|
|
64
|
+
* @param value - Value to test.
|
|
65
|
+
* @returns `true` when the value is a `Uint8ClampedArray`.
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* isUint8ClampedArray(new Uint8ClampedArray(1))
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function isUint8ClampedArray(value: Uint8ClampedArray): boolean;
|
|
72
|
+
export declare function isUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
|
|
73
|
+
/**
|
|
74
|
+
* Narrow an unknown value to `Int16Array`.
|
|
75
|
+
*
|
|
76
|
+
* @param value - Value to test.
|
|
77
|
+
* @returns `true` when the value is an `Int16Array`.
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* isInt16Array(new Int16Array(1))
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function isInt16Array(value: Int16Array): boolean;
|
|
84
|
+
export declare function isInt16Array(value: unknown): value is Int16Array;
|
|
85
|
+
/**
|
|
86
|
+
* Narrow an unknown value to `Uint16Array`.
|
|
87
|
+
*
|
|
88
|
+
* @param value - Value to test.
|
|
89
|
+
* @returns `true` when the value is a `Uint16Array`.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* isUint16Array(new Uint16Array(1))
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function isUint16Array(value: Uint16Array): boolean;
|
|
96
|
+
export declare function isUint16Array(value: unknown): value is Uint16Array;
|
|
97
|
+
/**
|
|
98
|
+
* Narrow an unknown value to `Int32Array`.
|
|
99
|
+
*
|
|
100
|
+
* @param value - Value to test.
|
|
101
|
+
* @returns `true` when the value is an `Int32Array`.
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* isInt32Array(new Int32Array(1))
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function isInt32Array(value: Int32Array): boolean;
|
|
108
|
+
export declare function isInt32Array(value: unknown): value is Int32Array;
|
|
109
|
+
/**
|
|
110
|
+
* Narrow an unknown value to `Uint32Array`.
|
|
111
|
+
*
|
|
112
|
+
* @param value - Value to test.
|
|
113
|
+
* @returns `true` when the value is a `Uint32Array`.
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* isUint32Array(new Uint32Array(1))
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function isUint32Array(value: Uint32Array): boolean;
|
|
120
|
+
export declare function isUint32Array(value: unknown): value is Uint32Array;
|
|
121
|
+
/**
|
|
122
|
+
* Narrow an unknown value to `Float32Array`.
|
|
123
|
+
*
|
|
124
|
+
* @param value - Value to test.
|
|
125
|
+
* @returns `true` when the value is a `Float32Array`.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* isFloat32Array(new Float32Array(1))
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function isFloat32Array(value: Float32Array): boolean;
|
|
132
|
+
export declare function isFloat32Array(value: unknown): value is Float32Array;
|
|
133
|
+
/**
|
|
134
|
+
* Narrow an unknown value to `Float64Array`.
|
|
135
|
+
*
|
|
136
|
+
* @param value - Value to test.
|
|
137
|
+
* @returns `true` when the value is a `Float64Array`.
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* isFloat64Array(new Float64Array(1))
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function isFloat64Array(value: Float64Array): boolean;
|
|
144
|
+
export declare function isFloat64Array(value: unknown): value is Float64Array;
|
|
145
|
+
/**
|
|
146
|
+
* Narrow an unknown value to `BigInt64Array` when supported.
|
|
147
|
+
*
|
|
148
|
+
* @param value - Value to test.
|
|
149
|
+
* @returns `true` when the value is a `BigInt64Array`.
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* isBigInt64Array(typeof BigInt64Array === 'undefined' ? undefined : new BigInt64Array(1))
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function isBigInt64Array(value: BigInt64Array): boolean;
|
|
156
|
+
export declare function isBigInt64Array(value: unknown): value is BigInt64Array;
|
|
157
|
+
/**
|
|
158
|
+
* Narrow an unknown value to `BigUint64Array` when supported.
|
|
159
|
+
*
|
|
160
|
+
* @param value - Value to test.
|
|
161
|
+
* @returns `true` when the value is a `BigUint64Array`.
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* isBigUint64Array(typeof BigUint64Array === 'undefined' ? undefined : new BigUint64Array(1))
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function isBigUint64Array(value: BigUint64Array): boolean;
|
|
168
|
+
export declare function isBigUint64Array(value: unknown): value is BigUint64Array;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow an unknown value to `Map`.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Value to test.
|
|
5
|
+
* @returns `true` when the value is a `Map`.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isMap(new Map())
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function isMap<K = unknown, V = unknown>(value: ReadonlyMap<K, V>): boolean;
|
|
12
|
+
export declare function isMap<K = unknown, V = unknown>(value: unknown): value is ReadonlyMap<K, V>;
|
|
13
|
+
/**
|
|
14
|
+
* Narrow an unknown value to `Set`.
|
|
15
|
+
*
|
|
16
|
+
* @param value - Value to test.
|
|
17
|
+
* @returns `true` when the value is a `Set`.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* isSet(new Set())
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function isSet<T = unknown>(value: ReadonlySet<T>): boolean;
|
|
24
|
+
export declare function isSet<T = unknown>(value: unknown): value is ReadonlySet<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Narrow an unknown value to `WeakMap`.
|
|
27
|
+
*
|
|
28
|
+
* @param value - Value to test.
|
|
29
|
+
* @returns `true` when the value is a `WeakMap`.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* isWeakMap(new WeakMap())
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function isWeakMap(value: WeakMap<object, unknown>): boolean;
|
|
36
|
+
export declare function isWeakMap(value: unknown): value is WeakMap<object, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Narrow an unknown value to `WeakSet`.
|
|
39
|
+
*
|
|
40
|
+
* @param value - Value to test.
|
|
41
|
+
* @returns `true` when the value is a `WeakSet`.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* isWeakSet(new WeakSet())
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function isWeakSet(value: WeakSet<object>): boolean;
|
|
48
|
+
export declare function isWeakSet(value: unknown): value is WeakSet<object>;
|
|
49
|
+
/**
|
|
50
|
+
* Narrow an unknown value to a non-null object.
|
|
51
|
+
*
|
|
52
|
+
* @param value - Value to test.
|
|
53
|
+
* @returns `true` when the value is an object and not `null`.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* isObject({})
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function isObject(value: object): boolean;
|
|
60
|
+
export declare function isObject(value: unknown): value is object;
|
|
61
|
+
/**
|
|
62
|
+
* Narrow an unknown value to a plain string-keyed record.
|
|
63
|
+
*
|
|
64
|
+
* @param value - Value to test.
|
|
65
|
+
* @returns `true` when the value is a non-array object.
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* isRecord({ id: 'u1' })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function isRecord(value: Record<string, unknown>): boolean;
|
|
72
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ValidationRuleName } from './types.js';
|
|
2
|
+
/** Ordered evaluation of all built-in validation rules. */
|
|
3
|
+
export declare const VALIDATION_RULE_NAMES: readonly ValidationRuleName[];
|
|
4
|
+
/** Basic email format: local@domain.tld. */
|
|
5
|
+
export declare const EMAIL_PATTERN: RegExp;
|
|
6
|
+
/** HTTP or HTTPS URL. */
|
|
7
|
+
export declare const URL_PATTERN: RegExp;
|
|
8
|
+
/** Numeric value: integer or decimal, optionally negative. */
|
|
9
|
+
export declare const NUMERIC_PATTERN: RegExp;
|
|
10
|
+
/** Integer value, optionally negative. */
|
|
11
|
+
export declare const INTEGER_PATTERN: RegExp;
|
|
12
|
+
/** Letters and digits only. */
|
|
13
|
+
export declare const ALPHANUMERIC_PATTERN: RegExp;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow an unknown value to the empty string.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Value to test.
|
|
5
|
+
* @returns `true` when the value is `''`.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isEmptyString('')
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function isEmptyString(value: unknown): value is '';
|
|
12
|
+
/**
|
|
13
|
+
* Narrow an unknown value to an empty array.
|
|
14
|
+
*
|
|
15
|
+
* @param value - Value to test.
|
|
16
|
+
* @returns `true` when the value is an empty array.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* isEmptyArray([])
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function isEmptyArray(value: []): boolean;
|
|
23
|
+
export declare function isEmptyArray(value: unknown): value is readonly [];
|
|
24
|
+
/**
|
|
25
|
+
* Narrow an unknown value to an empty plain object.
|
|
26
|
+
*
|
|
27
|
+
* @param value - Value to test.
|
|
28
|
+
* @returns `true` when the value has no enumerable string or symbol keys.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* isEmptyObject({})
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function isEmptyObject(value: Record<string | symbol, never>): boolean;
|
|
35
|
+
export declare function isEmptyObject(value: unknown): value is Record<string | symbol, never>;
|
|
36
|
+
/**
|
|
37
|
+
* Narrow an unknown value to an empty map.
|
|
38
|
+
*
|
|
39
|
+
* @param value - Value to test.
|
|
40
|
+
* @returns `true` when the value is a map with size `0`.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* isEmptyMap(new Map())
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function isEmptyMap(value: ReadonlyMap<never, never>): boolean;
|
|
47
|
+
export declare function isEmptyMap(value: unknown): value is ReadonlyMap<never, never>;
|
|
48
|
+
/**
|
|
49
|
+
* Narrow an unknown value to an empty set.
|
|
50
|
+
*
|
|
51
|
+
* @param value - Value to test.
|
|
52
|
+
* @returns `true` when the value is a set with size `0`.
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* isEmptySet(new Set())
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function isEmptySet(value: ReadonlySet<never>): boolean;
|
|
59
|
+
export declare function isEmptySet(value: unknown): value is ReadonlySet<never>;
|
|
60
|
+
/**
|
|
61
|
+
* Narrow an unknown value to a non-empty string.
|
|
62
|
+
*
|
|
63
|
+
* @param value - Value to test.
|
|
64
|
+
* @returns `true` when the value is a string with length greater than `0`.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* isNonEmptyString('value')
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function isNonEmptyString(value: string): boolean;
|
|
71
|
+
export declare function isNonEmptyString(value: unknown): value is string;
|
|
72
|
+
/**
|
|
73
|
+
* Narrow an unknown value to a non-empty array.
|
|
74
|
+
*
|
|
75
|
+
* @param value - Value to test.
|
|
76
|
+
* @returns `true` when the value is an array with at least one item.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* isNonEmptyArray([1])
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function isNonEmptyArray<T = unknown>(value: [T, ...T[]]): boolean;
|
|
83
|
+
export declare function isNonEmptyArray<T = unknown>(value: unknown): value is readonly [T, ...T[]];
|
|
84
|
+
/**
|
|
85
|
+
* Narrow an unknown value to a non-empty plain object.
|
|
86
|
+
*
|
|
87
|
+
* @param value - Value to test.
|
|
88
|
+
* @returns `true` when the value has at least one enumerable key.
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* isNonEmptyObject({ id: '1' })
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function isNonEmptyObject(value: Record<string | symbol, unknown>): boolean;
|
|
95
|
+
export declare function isNonEmptyObject(value: unknown): value is Record<string | symbol, unknown>;
|
|
96
|
+
/**
|
|
97
|
+
* Narrow an unknown value to a non-empty map.
|
|
98
|
+
*
|
|
99
|
+
* @param value - Value to test.
|
|
100
|
+
* @returns `true` when the value is a map with at least one entry.
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* isNonEmptyMap(new Map([['a', 1]]))
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function isNonEmptyMap<K = unknown, V = unknown>(value: ReadonlyMap<K, V>): boolean;
|
|
107
|
+
export declare function isNonEmptyMap<K = unknown, V = unknown>(value: unknown): value is ReadonlyMap<K, V>;
|
|
108
|
+
/**
|
|
109
|
+
* Narrow an unknown value to a non-empty set.
|
|
110
|
+
*
|
|
111
|
+
* @param value - Value to test.
|
|
112
|
+
* @returns `true` when the value is a set with at least one entry.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* isNonEmptySet(new Set([1]))
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function isNonEmptySet<T = unknown>(value: ReadonlySet<T>): boolean;
|
|
119
|
+
export declare function isNonEmptySet<T = unknown>(value: unknown): value is ReadonlySet<T>;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ValidatorErrorCode, ValidatorErrorContext } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown for invalid validator configuration.
|
|
4
|
+
*
|
|
5
|
+
* @param code - Machine-readable validator error code.
|
|
6
|
+
* @param message - Human-readable explanation.
|
|
7
|
+
* @param context - Additional error context.
|
|
8
|
+
* @returns A configured `ValidatorError` instance.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* throw new ValidatorError('INVALID_PATTERN', 'Pattern is invalid')
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class ValidatorError extends Error {
|
|
15
|
+
readonly code: ValidatorErrorCode;
|
|
16
|
+
readonly context: ValidatorErrorContext;
|
|
17
|
+
constructor(code: ValidatorErrorCode, message: string, context?: ValidatorErrorContext);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Narrow an unknown value to `ValidatorError`.
|
|
21
|
+
*
|
|
22
|
+
* @param value - Value to test.
|
|
23
|
+
* @returns `true` when the value is a `ValidatorError`.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* isValidatorError(new ValidatorError('INVALID_RULES', 'Invalid rules'))
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function isValidatorError(value: unknown): value is ValidatorError;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Guard, GuardsShape, ShapeGuardResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize an enum-like object into its distinct public values.
|
|
4
|
+
*
|
|
5
|
+
* @param enumeration - Enum object or enum-like map.
|
|
6
|
+
* @returns A normalized list of accepted enum values.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* createEnumValues({ idle: 'IDLE', busy: 'BUSY' })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function createEnumValues<E extends Record<string, string | number>>(enumeration: E): readonly (string | number)[];
|
|
13
|
+
/**
|
|
14
|
+
* Build an exact shape guard from a guard shape and optional-key configuration.
|
|
15
|
+
*
|
|
16
|
+
* @param shape - Guard shape to apply.
|
|
17
|
+
* @param optional - Optional keys, or `true` to make every key optional.
|
|
18
|
+
* @returns A guard enforcing exact string keys and per-property validation.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const isUser = createShapeGuard({ id: isString })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createShapeGuard<S extends GuardsShape, K extends Array<keyof S & string> | true | undefined>(shape: S, optional?: K): Guard<ShapeGuardResult<S, K>>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AnyAsyncFunction, AnyFunction, ZeroArgAsyncFunction, ZeroArgFunction } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Narrow a function to one with no declared parameters.
|
|
4
|
+
*
|
|
5
|
+
* @param value - Function to inspect.
|
|
6
|
+
* @returns `true` when the function has zero declared parameters.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isZeroArg(() => true)
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function isZeroArg<F extends ZeroArgFunction>(value: F): value is F;
|
|
13
|
+
export declare function isZeroArg(value: AnyFunction): value is ZeroArgFunction;
|
|
14
|
+
/**
|
|
15
|
+
* Narrow a function to a native async function.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Function to inspect.
|
|
18
|
+
* @returns `true` when the function is a native async function.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* isAsyncFunction(async () => true)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function isAsyncFunction<F extends AnyAsyncFunction>(value: F): value is F;
|
|
25
|
+
export declare function isAsyncFunction(value: unknown): value is AnyAsyncFunction;
|
|
26
|
+
/**
|
|
27
|
+
* Narrow a function to a generator function.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Function to inspect.
|
|
30
|
+
* @returns `true` when the function is a generator function.
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* isGeneratorFunction(function* () { yield 1 })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function isGeneratorFunction<F extends (...args: unknown[]) => Generator<unknown, unknown, unknown>>(value: F): value is F;
|
|
37
|
+
export declare function isGeneratorFunction(value: unknown): value is (...args: unknown[]) => Generator<unknown, unknown, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Narrow a function to an async generator function.
|
|
40
|
+
*
|
|
41
|
+
* @param value - Function to inspect.
|
|
42
|
+
* @returns `true` when the function is an async generator function.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* isAsyncGeneratorFunction(async function* () { yield 1 })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function isAsyncGeneratorFunction<F extends (...args: unknown[]) => AsyncGenerator<unknown, unknown, unknown>>(value: F): value is F;
|
|
49
|
+
export declare function isAsyncGeneratorFunction(value: unknown): value is (...args: unknown[]) => AsyncGenerator<unknown, unknown, unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* Narrow a function to a zero-argument async function.
|
|
52
|
+
*
|
|
53
|
+
* @param value - Function to inspect.
|
|
54
|
+
* @returns `true` when the function is async and has no declared parameters.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* isZeroArgAsync(async () => true)
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function isZeroArgAsync<F extends ZeroArgAsyncFunction>(value: F): value is F;
|
|
61
|
+
export declare function isZeroArgAsync(value: unknown): value is ZeroArgAsyncFunction;
|
|
62
|
+
/**
|
|
63
|
+
* Narrow a function to a zero-argument generator function.
|
|
64
|
+
*
|
|
65
|
+
* @param value - Function to inspect.
|
|
66
|
+
* @returns `true` when the function is a generator with no declared parameters.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* isZeroArgGenerator(function* () { yield 1 })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function isZeroArgGenerator<F extends (...args: unknown[]) => Generator<unknown, unknown, unknown>>(value: F): value is F;
|
|
73
|
+
export declare function isZeroArgGenerator(value: unknown): value is () => Generator<unknown, unknown, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Narrow a function to a zero-argument async generator function.
|
|
76
|
+
*
|
|
77
|
+
* @param value - Function to inspect.
|
|
78
|
+
* @returns `true` when the function is an async generator with no declared parameters.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* isZeroArgAsyncGenerator(async function* () { yield 1 })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function isZeroArgAsyncGenerator<F extends (...args: unknown[]) => AsyncGenerator<unknown, unknown, unknown>>(value: F): value is F;
|
|
85
|
+
export declare function isZeroArgAsyncGenerator(value: unknown): value is () => AsyncGenerator<unknown, unknown, unknown>;
|