@deessejs/type-testing 0.1.5 → 0.3.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/CHANGELOG.md +35 -1
- package/README.md +118 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/comparison.d.ts +122 -0
- package/dist/runtime/comparison.d.ts.map +1 -0
- package/dist/runtime/comparison.js +180 -0
- package/dist/runtime/comparison.js.map +1 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +5 -0
- package/dist/runtime/index.js.map +1 -0
- package/package.json +2 -1
- package/public/icon.png +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
# @deessejs/type-testing
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: add type utility helpers
|
|
8
|
+
|
|
9
|
+
Add new type utilities for compile-time type testing:
|
|
10
|
+
|
|
11
|
+
### Property Modifiers
|
|
12
|
+
- IsReadonly<T> - Check if all properties are readonly
|
|
13
|
+
- IsRequired<T> - Check if all properties are required
|
|
14
|
+
- IsPublic<T, K> - Check if property is public
|
|
15
|
+
- IsPrivate<T, K> - Check if property is private
|
|
16
|
+
- IsProtected<T, K> - Check if property is protected
|
|
17
|
+
|
|
18
|
+
### Deep Type Manipulation
|
|
19
|
+
- DeepReadonly<T> - Make all properties readonly recursively
|
|
20
|
+
- DeepPartial<T> - Make all properties optional recursively
|
|
21
|
+
- RequiredKeys<T> - Get keys of required properties
|
|
22
|
+
- OptionalKeys<T> - Get keys of optional properties
|
|
23
|
+
|
|
24
|
+
### Function Types
|
|
25
|
+
- IsConstructor<T> - Check if type is a constructor
|
|
26
|
+
- IsAbstract<T> - Check if type is abstract
|
|
27
|
+
|
|
28
|
+
### Other
|
|
29
|
+
- IsNeverEqual<T, U> - Check if T and U are both never
|
|
30
|
+
|
|
31
|
+
## 0.2.0
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- Add runtime type checking utilities with boolean type guards
|
|
36
|
+
|
|
3
37
|
## 0.1.2
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
|
6
40
|
|
|
7
|
-
- Fix
|
|
41
|
+
- Fix .npmignore to include dist folder in published package
|
|
8
42
|
|
|
9
43
|
## 0.1.1
|
|
10
44
|
|
package/README.md
CHANGED
|
@@ -139,6 +139,27 @@ HasProperty<{ a: string }, 'b'> // false
|
|
|
139
139
|
PropertyType<{ a: string }, 'a'> // string
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
### Property Modifiers
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { IsReadonly, IsRequired, IsPublic, IsPrivate, IsProtected } from '@deessejs/type-testing'
|
|
146
|
+
|
|
147
|
+
// Check if all properties are readonly
|
|
148
|
+
IsReadonly<{ readonly a: string }> // true
|
|
149
|
+
IsReadonly<{ a: string }> // false
|
|
150
|
+
|
|
151
|
+
// Check if all properties are required
|
|
152
|
+
IsRequired<{ a: string }> // true
|
|
153
|
+
IsRequired<{ a?: string }> // false
|
|
154
|
+
|
|
155
|
+
// Check property visibility (uses naming convention)
|
|
156
|
+
IsPublic<{ a: string }, 'a'> // true
|
|
157
|
+
IsPrivate<{ __private: string }, '__private'> // true
|
|
158
|
+
IsProtected<{ _protected: string }, '_protected'> // true
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
> **Note**: `IsPublic`, `IsPrivate`, and `IsProtected` use TypeScript's private field naming convention (`__` prefix) and common JavaScript convention (`_` prefix for protected). These are naming-convention-based checks, not actual TypeScript access modifiers (which don't exist for object properties).
|
|
162
|
+
|
|
142
163
|
### Function Types
|
|
143
164
|
|
|
144
165
|
```typescript
|
|
@@ -164,6 +185,91 @@ Length<['a', 'b', 'c']> // 3
|
|
|
164
185
|
Length<[]> // 0
|
|
165
186
|
```
|
|
166
187
|
|
|
188
|
+
### Deep Type Manipulation
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { DeepReadonly, DeepPartial, RequiredKeys, OptionalKeys } from '@deessejs/type-testing'
|
|
192
|
+
|
|
193
|
+
// Make all properties readonly recursively
|
|
194
|
+
DeepReadonly<{ a: string; b: { c: number } }>
|
|
195
|
+
// { readonly a: string; readonly b: { readonly c: number } }
|
|
196
|
+
|
|
197
|
+
// Make all properties optional recursively
|
|
198
|
+
DeepPartial<{ a: string; b: { c: number } }>
|
|
199
|
+
// { a?: string; b?: { c?: number } | undefined }
|
|
200
|
+
|
|
201
|
+
// Get keys of required properties
|
|
202
|
+
RequiredKeys<{ a: string; b?: number }> // 'a'
|
|
203
|
+
|
|
204
|
+
// Get keys of optional properties
|
|
205
|
+
OptionalKeys<{ a: string; b?: number }> // 'b'
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Constructor & Abstract Types
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { IsConstructor, IsAbstract } from '@deessejs/type-testing'
|
|
212
|
+
|
|
213
|
+
class Foo {}
|
|
214
|
+
abstract class Bar {}
|
|
215
|
+
|
|
216
|
+
IsConstructor<typeof Foo> // true
|
|
217
|
+
IsConstructor<Foo> // false (instance)
|
|
218
|
+
IsAbstract<typeof Bar> // true
|
|
219
|
+
IsAbstract<typeof Foo> // false
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Special Equality
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
import { IsNeverEqual } from '@deessejs/type-testing'
|
|
226
|
+
|
|
227
|
+
// Check if both types are never
|
|
228
|
+
// Differs from Equal<never, never> which returns false
|
|
229
|
+
IsNeverEqual<never, never> // true
|
|
230
|
+
IsNeverEqual<any, any> // false (any is not never)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Runtime Type Checking
|
|
234
|
+
|
|
235
|
+
The library also provides runtime type checking utilities:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import {
|
|
239
|
+
// Type check functions returning TypeCheckResult objects
|
|
240
|
+
isString,
|
|
241
|
+
isNumber,
|
|
242
|
+
isBoolean,
|
|
243
|
+
isObject,
|
|
244
|
+
isArray,
|
|
245
|
+
isNull,
|
|
246
|
+
isUndefined,
|
|
247
|
+
|
|
248
|
+
// Boolean type guards (for use in conditionals)
|
|
249
|
+
isStringGuard,
|
|
250
|
+
isNumberGuard,
|
|
251
|
+
isBooleanGuard,
|
|
252
|
+
isObjectGuard,
|
|
253
|
+
isArrayGuard,
|
|
254
|
+
isNullGuard,
|
|
255
|
+
isUndefinedGuard,
|
|
256
|
+
isSymbolGuard,
|
|
257
|
+
isBigIntGuard,
|
|
258
|
+
isFunctionGuard
|
|
259
|
+
} from '@deessejs/type-testing'
|
|
260
|
+
|
|
261
|
+
// TypeCheckResult objects
|
|
262
|
+
const stringResult = isString('hello')
|
|
263
|
+
stringResult.matches // true
|
|
264
|
+
stringResult.value // 'hello'
|
|
265
|
+
stringResult.typeName // 'string'
|
|
266
|
+
|
|
267
|
+
// Boolean type guards
|
|
268
|
+
if (isStringGuard(value)) {
|
|
269
|
+
// value is narrowed to string here
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
167
273
|
## Chainable API
|
|
168
274
|
|
|
169
275
|
### check() - Soft type checking
|
|
@@ -268,6 +374,7 @@ expectFalse<true>() // compile error
|
|
|
268
374
|
| `Equal<T, U>` | Strict equality check |
|
|
269
375
|
| `NotEqual<T, U>` | Inequality check |
|
|
270
376
|
| `SimpleEqual<T, U>` | Simple equality for plain types |
|
|
377
|
+
| `IsNeverEqual<T, U>` | Check if both types are `never` |
|
|
271
378
|
| `IsAny<T>` | Check if type is `any` |
|
|
272
379
|
| `IsNever<T>` | Check if type is `never` |
|
|
273
380
|
| `IsUnknown<T>` | Check if type is `unknown` |
|
|
@@ -283,9 +390,20 @@ expectFalse<true>() // compile error
|
|
|
283
390
|
| `IsUninhabited<T>` | Check if type has no values |
|
|
284
391
|
| `HasProperty<T, K>` | Check if type has property K |
|
|
285
392
|
| `PropertyType<T, K>` | Get type of property K |
|
|
393
|
+
| `IsReadonly<T>` | Check if all properties are readonly |
|
|
394
|
+
| `IsRequired<T>` | Check if all properties are required |
|
|
395
|
+
| `IsPublic<T, K>` | Check if property is public |
|
|
396
|
+
| `IsPrivate<T, K>` | Check if property is private (naming convention) |
|
|
397
|
+
| `IsProtected<T, K>` | Check if property is protected (naming convention) |
|
|
398
|
+
| `DeepReadonly<T>` | Make all properties readonly recursively |
|
|
399
|
+
| `DeepPartial<T>` | Make all properties optional recursively |
|
|
400
|
+
| `RequiredKeys<T>` | Get keys of required properties |
|
|
401
|
+
| `OptionalKeys<T>` | Get keys of optional properties |
|
|
286
402
|
| `Parameters<T>` | Get function parameters as tuple |
|
|
287
403
|
| `ReturnType<T>` | Get function return type |
|
|
288
404
|
| `Parameter<T, N>` | Get parameter at index N |
|
|
405
|
+
| `IsConstructor<T>` | Check if type is a constructor |
|
|
406
|
+
| `IsAbstract<T>` | Check if type is abstract |
|
|
289
407
|
| `Length<T>` | Get tuple/array length |
|
|
290
408
|
| `ExpectTrue<T>` | Assert T is true |
|
|
291
409
|
| `ExpectEqual<T, U>` | Assert T equals U |
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAA;AAGhC,cAAc,gBAAgB,CAAA;AAG9B,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAA;AAGhC,cAAc,gBAAgB,CAAA;AAG9B,cAAc,YAAY,CAAA;AAG1B,cAAc,oBAAoB,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,kBAAkB,CAAA;AAEhC,gBAAgB;AAChB,cAAc,gBAAgB,CAAA;AAE9B,sBAAsB;AACtB,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,kBAAkB,CAAA;AAEhC,gBAAgB;AAChB,cAAc,gBAAgB,CAAA;AAE9B,sBAAsB;AACtB,cAAc,YAAY,CAAA;AAE1B,8BAA8B;AAC9B,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime comparison utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Result of checking if a value matches a type.
|
|
6
|
+
*/
|
|
7
|
+
export interface TypeCheckResult<T> {
|
|
8
|
+
matches: boolean;
|
|
9
|
+
value: T;
|
|
10
|
+
typeName: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Check if a value is a string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const result = isString('hello')
|
|
18
|
+
* result.matches // true
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function isString(value: unknown): TypeCheckResult<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a value is a number.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const result = isNumber(42)
|
|
28
|
+
* result.matches // true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function isNumber(value: unknown): TypeCheckResult<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a value is a boolean.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const result = isBoolean(true)
|
|
38
|
+
* result.matches // true
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function isBoolean(value: unknown): TypeCheckResult<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a value is an object.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const result = isObject({ a: 1 })
|
|
48
|
+
* result.matches // true
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function isObject(value: unknown): TypeCheckResult<object>;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a value is an array.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const result = isArray([1, 2, 3])
|
|
58
|
+
* result.matches // true
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function isArray(value: unknown): TypeCheckResult<unknown[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a value is null.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const result = isNull(null)
|
|
68
|
+
* result.matches // true
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function isNull(value: unknown): TypeCheckResult<null>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a value is undefined.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const result = isUndefined(undefined)
|
|
78
|
+
* result.matches // true
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function isUndefined(value: unknown): TypeCheckResult<undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* Type guard that returns true if the value is a string.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isStringGuard(value: unknown): value is string;
|
|
86
|
+
/**
|
|
87
|
+
* Type guard that returns true if the value is a number.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isNumberGuard(value: unknown): value is number;
|
|
90
|
+
/**
|
|
91
|
+
* Type guard that returns true if the value is a boolean.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isBooleanGuard(value: unknown): value is boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Type guard that returns true if the value is an object (not null, not array).
|
|
96
|
+
*/
|
|
97
|
+
export declare function isObjectGuard(value: unknown): value is object;
|
|
98
|
+
/**
|
|
99
|
+
* Type guard that returns true if the value is an array.
|
|
100
|
+
*/
|
|
101
|
+
export declare function isArrayGuard(value: unknown): value is unknown[];
|
|
102
|
+
/**
|
|
103
|
+
* Type guard that returns true if the value is null.
|
|
104
|
+
*/
|
|
105
|
+
export declare function isNullGuard(value: unknown): value is null;
|
|
106
|
+
/**
|
|
107
|
+
* Type guard that returns true if the value is undefined.
|
|
108
|
+
*/
|
|
109
|
+
export declare function isUndefinedGuard(value: unknown): value is undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Type guard that returns true if the value is a symbol.
|
|
112
|
+
*/
|
|
113
|
+
export declare function isSymbolGuard(value: unknown): value is symbol;
|
|
114
|
+
/**
|
|
115
|
+
* Type guard that returns true if the value is a bigint.
|
|
116
|
+
*/
|
|
117
|
+
export declare function isBigIntGuard(value: unknown): value is bigint;
|
|
118
|
+
/**
|
|
119
|
+
* Type guard that returns true if the value is a function.
|
|
120
|
+
*/
|
|
121
|
+
export declare function isFunctionGuard(value: unknown): value is Function;
|
|
122
|
+
//# sourceMappingURL=comparison.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../../src/runtime/comparison.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,KAA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AAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAEzD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAEnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;GAEG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAEjE"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime comparison utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if a value is a string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const result = isString('hello')
|
|
10
|
+
* result.matches // true
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function isString(value) {
|
|
14
|
+
return {
|
|
15
|
+
matches: typeof value === 'string',
|
|
16
|
+
value: value,
|
|
17
|
+
typeName: typeof value,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if a value is a number.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = isNumber(42)
|
|
26
|
+
* result.matches // true
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function isNumber(value) {
|
|
30
|
+
return {
|
|
31
|
+
matches: typeof value === 'number',
|
|
32
|
+
value: value,
|
|
33
|
+
typeName: typeof value,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if a value is a boolean.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const result = isBoolean(true)
|
|
42
|
+
* result.matches // true
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function isBoolean(value) {
|
|
46
|
+
return {
|
|
47
|
+
matches: typeof value === 'boolean',
|
|
48
|
+
value: value,
|
|
49
|
+
typeName: typeof value,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a value is an object.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const result = isObject({ a: 1 })
|
|
58
|
+
* result.matches // true
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function isObject(value) {
|
|
62
|
+
return {
|
|
63
|
+
matches: typeof value === 'object' && value !== null,
|
|
64
|
+
value: value,
|
|
65
|
+
typeName: typeof value,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if a value is an array.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const result = isArray([1, 2, 3])
|
|
74
|
+
* result.matches // true
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function isArray(value) {
|
|
78
|
+
return {
|
|
79
|
+
matches: Array.isArray(value),
|
|
80
|
+
value: value,
|
|
81
|
+
typeName: Array.isArray(value) ? 'array' : typeof value,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if a value is null.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const result = isNull(null)
|
|
90
|
+
* result.matches // true
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export function isNull(value) {
|
|
94
|
+
return {
|
|
95
|
+
matches: value === null,
|
|
96
|
+
value: value,
|
|
97
|
+
typeName: value === null ? 'null' : typeof value,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if a value is undefined.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const result = isUndefined(undefined)
|
|
106
|
+
* result.matches // true
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export function isUndefined(value) {
|
|
110
|
+
return {
|
|
111
|
+
matches: value === undefined,
|
|
112
|
+
value: value,
|
|
113
|
+
typeName: value === undefined ? 'undefined' : typeof value,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// ============================================
|
|
117
|
+
// Simple boolean type guards
|
|
118
|
+
// ============================================
|
|
119
|
+
/**
|
|
120
|
+
* Type guard that returns true if the value is a string.
|
|
121
|
+
*/
|
|
122
|
+
export function isStringGuard(value) {
|
|
123
|
+
return typeof value === 'string';
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Type guard that returns true if the value is a number.
|
|
127
|
+
*/
|
|
128
|
+
export function isNumberGuard(value) {
|
|
129
|
+
return typeof value === 'number';
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Type guard that returns true if the value is a boolean.
|
|
133
|
+
*/
|
|
134
|
+
export function isBooleanGuard(value) {
|
|
135
|
+
return typeof value === 'boolean';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Type guard that returns true if the value is an object (not null, not array).
|
|
139
|
+
*/
|
|
140
|
+
export function isObjectGuard(value) {
|
|
141
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Type guard that returns true if the value is an array.
|
|
145
|
+
*/
|
|
146
|
+
export function isArrayGuard(value) {
|
|
147
|
+
return Array.isArray(value);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Type guard that returns true if the value is null.
|
|
151
|
+
*/
|
|
152
|
+
export function isNullGuard(value) {
|
|
153
|
+
return value === null;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Type guard that returns true if the value is undefined.
|
|
157
|
+
*/
|
|
158
|
+
export function isUndefinedGuard(value) {
|
|
159
|
+
return value === undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Type guard that returns true if the value is a symbol.
|
|
163
|
+
*/
|
|
164
|
+
export function isSymbolGuard(value) {
|
|
165
|
+
return typeof value === 'symbol';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Type guard that returns true if the value is a bigint.
|
|
169
|
+
*/
|
|
170
|
+
export function isBigIntGuard(value) {
|
|
171
|
+
return typeof value === 'bigint';
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Type guard that returns true if the value is a function.
|
|
175
|
+
*/
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
177
|
+
export function isFunctionGuard(value) {
|
|
178
|
+
return typeof value === 'function';
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=comparison.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparison.js","sourceRoot":"","sources":["../../src/runtime/comparison.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,QAAQ;QAClC,KAAK,EAAE,KAAe;QACtB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,QAAQ;QAClC,KAAK,EAAE,KAAe;QACtB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,SAAS;QACnC,KAAK,EAAE,KAAgB;QACvB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AAC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C;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,SAAS,CAAA;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,KAAK,IAAI,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,KAAK,SAAS,CAAA;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,UAAU,CAAA;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/type-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"lint": "eslint src --ext .ts,.tsx",
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
18
|
"test": "vitest run",
|
|
19
|
+
"test:coverage": "vitest run --coverage",
|
|
19
20
|
"test:watch": "vitest",
|
|
20
21
|
"clean": "rm -rf dist"
|
|
21
22
|
},
|
package/public/icon.png
CHANGED
|
Binary file
|