is-kit 1.16.2 → 1.16.3
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 +15 -11
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/index.mjs +5 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<img
|
|
5
|
-
src="https://raw.githubusercontent.com/
|
|
5
|
+
src="https://raw.githubusercontent.com/necoz-oss/is-kit/main/docs/public/iskit_image.png"
|
|
6
6
|
width="600"
|
|
7
7
|
alt="is-kit logo"
|
|
8
8
|
/>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<a href="https://www.npmjs.com/package/is-kit">
|
|
19
19
|
<img src="https://img.shields.io/npm/dt/is-kit.svg" alt="npm downloads">
|
|
20
20
|
</a>
|
|
21
|
-
<a href="https://github.com/
|
|
21
|
+
<a href="https://github.com/necoz-oss/is-kit/blob/main/LICENSE">
|
|
22
22
|
<img src="https://img.shields.io/npm/l/is-kit.svg?sanitize=true" alt="License">
|
|
23
23
|
</a>
|
|
24
24
|
</p>
|
|
@@ -144,6 +144,10 @@ const isPositiveNumber = and(
|
|
|
144
144
|
);
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
> **Note:** `isNumber` accepts only finite numbers. It rejects `NaN`, `Infinity`,
|
|
148
|
+
> and `-Infinity`, so it is stricter than `typeof value === 'number'`.
|
|
149
|
+
> Use `isNumberPrimitive` when you want the full JavaScript `number` primitive domain.
|
|
150
|
+
|
|
147
151
|
You can also refine one property of an already-typed parent value.
|
|
148
152
|
|
|
149
153
|
```ts
|
|
@@ -166,7 +170,7 @@ The original `Item` type is preserved while its checked `value` property is
|
|
|
166
170
|
narrowed. This lets a reusable guard carry child narrowing back to the parent
|
|
167
171
|
through `filter`, `find`, and control flow.
|
|
168
172
|
|
|
169
|
-
For an `unknown` value at a runtime boundary, build an object guard and
|
|
173
|
+
For an `unknown` value at a runtime boundary, build an object guard and validate
|
|
170
174
|
it.
|
|
171
175
|
|
|
172
176
|
```ts
|
|
@@ -278,7 +282,7 @@ const isSlug = (value: unknown): value is string =>
|
|
|
278
282
|
Install the `is-kit` plugin from this repository's Codex Marketplace:
|
|
279
283
|
|
|
280
284
|
```bash
|
|
281
|
-
codex plugin marketplace add
|
|
285
|
+
codex plugin marketplace add necoz-oss/is-kit
|
|
282
286
|
codex plugin add is-kit@is-kit
|
|
283
287
|
```
|
|
284
288
|
|
|
@@ -314,7 +318,7 @@ If you are new to the library, these are the pieces to remember:
|
|
|
314
318
|
- `predicateToRefine(fn)` upgrades an existing predicate so it can participate in narrowing chains.
|
|
315
319
|
- `refineKey(key, guard)` carries a child refinement back onto its parent type.
|
|
316
320
|
- `struct({...})` builds an object-shape guard.
|
|
317
|
-
- `safeParse(guard, value)`
|
|
321
|
+
- `safeParse(guard, value)` wraps guard validation in a small tagged result object.
|
|
318
322
|
- `assert(guard, value)` throws if the value does not match.
|
|
319
323
|
|
|
320
324
|
## ⚒️ Common Usage
|
|
@@ -526,7 +530,7 @@ Use `isNil` for a direct nullish check instead of hand-rolling
|
|
|
526
530
|
`isNull(x) || isUndefined(x)`. Use `isNotNil` for the inverse check or to
|
|
527
531
|
remove nullish values while preserving `Array.prototype.filter` narrowing.
|
|
528
532
|
|
|
529
|
-
### 9.
|
|
533
|
+
### 9. Validate or assert unknown input
|
|
530
534
|
|
|
531
535
|
Use `safeParse` when you want a result object, and `assert` when invalid data should stop execution.
|
|
532
536
|
|
|
@@ -797,7 +801,7 @@ For the full API list and dedicated pages, use the docs site below.
|
|
|
797
801
|
|
|
798
802
|
### Public types
|
|
799
803
|
|
|
800
|
-
Start with the primary types for guard authoring,
|
|
804
|
+
Start with the primary types for guard authoring, validation, and schema inference:
|
|
801
805
|
|
|
802
806
|
- `Predicate`, `Guard`, `Refinement`, `Refine`, `ParseResult`, `Primitive`
|
|
803
807
|
- `InferSchema`, `StructOptions`, `TypedStructShape`, `TypedStructFields`
|
|
@@ -866,10 +870,10 @@ Pick a guard, compose it, and ship with confidence 🚀
|
|
|
866
870
|
|
|
867
871
|
## Star History
|
|
868
872
|
|
|
869
|
-
<a href="https://www.star-history.com/?repos=
|
|
873
|
+
<a href="https://www.star-history.com/?repos=necoz-oss%2Fis-kit&type=date&legend=top-left">
|
|
870
874
|
<picture>
|
|
871
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=
|
|
872
|
-
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=
|
|
873
|
-
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=
|
|
875
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=necoz-oss/is-kit&type=date&theme=dark&legend=top-left" />
|
|
876
|
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=necoz-oss/is-kit&type=date&legend=top-left" />
|
|
877
|
+
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=necoz-oss/is-kit&type=date&legend=top-left" />
|
|
874
878
|
</picture>
|
|
875
879
|
</a>
|
package/dist/index.d.mts
CHANGED
|
@@ -461,6 +461,10 @@ export declare const isInfiniteNumber: Predicate<number>;
|
|
|
461
461
|
export declare const isFiniteNumber: Refine<number, number>;
|
|
462
462
|
/**
|
|
463
463
|
* Checks whether a value is a finite number.
|
|
464
|
+
*
|
|
465
|
+
* Rejects `NaN`, `Infinity`, and `-Infinity`, so it is stricter than
|
|
466
|
+
* `typeof value === 'number'`. Use {@link isNumberPrimitive} for the full
|
|
467
|
+
* `number` primitive domain.
|
|
464
468
|
* @returns Predicate narrowing to finite `number`.
|
|
465
469
|
*/
|
|
466
470
|
export declare const isNumber: Predicate<number>;
|
|
@@ -677,7 +681,7 @@ export declare const isTypedArray: Predicate<ArrayBufferView<ArrayBufferLike>>;
|
|
|
677
681
|
* Checks whether a value is an `Error`.
|
|
678
682
|
*
|
|
679
683
|
* @returns Predicate narrowing to `Error`.
|
|
680
|
-
* @see https://github.com/
|
|
684
|
+
* @see https://github.com/necoz-oss/is-kit/issues/325
|
|
681
685
|
*/
|
|
682
686
|
export declare const isError: Predicate<Error>;
|
|
683
687
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -461,6 +461,10 @@ export declare const isInfiniteNumber: Predicate<number>;
|
|
|
461
461
|
export declare const isFiniteNumber: Refine<number, number>;
|
|
462
462
|
/**
|
|
463
463
|
* Checks whether a value is a finite number.
|
|
464
|
+
*
|
|
465
|
+
* Rejects `NaN`, `Infinity`, and `-Infinity`, so it is stricter than
|
|
466
|
+
* `typeof value === 'number'`. Use {@link isNumberPrimitive} for the full
|
|
467
|
+
* `number` primitive domain.
|
|
464
468
|
* @returns Predicate narrowing to finite `number`.
|
|
465
469
|
*/
|
|
466
470
|
export declare const isNumber: Predicate<number>;
|
|
@@ -677,7 +681,7 @@ export declare const isTypedArray: Predicate<ArrayBufferView<ArrayBufferLike>>;
|
|
|
677
681
|
* Checks whether a value is an `Error`.
|
|
678
682
|
*
|
|
679
683
|
* @returns Predicate narrowing to `Error`.
|
|
680
|
-
* @see https://github.com/
|
|
684
|
+
* @see https://github.com/necoz-oss/is-kit/issues/325
|
|
681
685
|
*/
|
|
682
686
|
export declare const isError: Predicate<Error>;
|
|
683
687
|
/**
|
package/dist/index.js
CHANGED
|
@@ -179,7 +179,7 @@ const isTypedArray = define((value) => typedArrayName?.call(value) !== void 0);
|
|
|
179
179
|
* Checks whether a value is an `Error`.
|
|
180
180
|
*
|
|
181
181
|
* @returns Predicate narrowing to `Error`.
|
|
182
|
-
* @see https://github.com/
|
|
182
|
+
* @see https://github.com/necoz-oss/is-kit/issues/325
|
|
183
183
|
*/
|
|
184
184
|
const isError = define((value) => {
|
|
185
185
|
try {
|
|
@@ -422,6 +422,10 @@ const isInfiniteNumber = and(isNumberPrimitive, predicateToRefine((n) => n === I
|
|
|
422
422
|
const isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
423
423
|
/**
|
|
424
424
|
* Checks whether a value is a finite number.
|
|
425
|
+
*
|
|
426
|
+
* Rejects `NaN`, `Infinity`, and `-Infinity`, so it is stricter than
|
|
427
|
+
* `typeof value === 'number'`. Use {@link isNumberPrimitive} for the full
|
|
428
|
+
* `number` primitive domain.
|
|
425
429
|
* @returns Predicate narrowing to finite `number`.
|
|
426
430
|
*/
|
|
427
431
|
const isNumber = and(isNumberPrimitive, isFiniteNumber);
|
package/dist/index.mjs
CHANGED
|
@@ -178,7 +178,7 @@ const isTypedArray = define((value) => typedArrayName?.call(value) !== void 0);
|
|
|
178
178
|
* Checks whether a value is an `Error`.
|
|
179
179
|
*
|
|
180
180
|
* @returns Predicate narrowing to `Error`.
|
|
181
|
-
* @see https://github.com/
|
|
181
|
+
* @see https://github.com/necoz-oss/is-kit/issues/325
|
|
182
182
|
*/
|
|
183
183
|
const isError = define((value) => {
|
|
184
184
|
try {
|
|
@@ -421,6 +421,10 @@ const isInfiniteNumber = and(isNumberPrimitive, predicateToRefine((n) => n === I
|
|
|
421
421
|
const isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
422
422
|
/**
|
|
423
423
|
* Checks whether a value is a finite number.
|
|
424
|
+
*
|
|
425
|
+
* Rejects `NaN`, `Infinity`, and `-Infinity`, so it is stricter than
|
|
426
|
+
* `typeof value === 'number'`. Use {@link isNumberPrimitive} for the full
|
|
427
|
+
* `number` primitive domain.
|
|
424
428
|
* @returns Predicate narrowing to finite `number`.
|
|
425
429
|
*/
|
|
426
430
|
const isNumber = and(isNumberPrimitive, isFiniteNumber);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "is-kit",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"description": "Zero-dependency TypeScript runtime validation toolkit for composable type guards and natural type narrowing.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"sideEffects": false,
|
|
53
53
|
"repository": {
|
|
54
54
|
"type": "git",
|
|
55
|
-
"url": "git+https://github.com/
|
|
55
|
+
"url": "git+https://github.com/necoz-oss/is-kit.git"
|
|
56
56
|
},
|
|
57
57
|
"bugs": {
|
|
58
|
-
"url": "https://github.com/
|
|
58
|
+
"url": "https://github.com/necoz-oss/is-kit/issues"
|
|
59
59
|
},
|
|
60
60
|
"homepage": "https://is-kit.dev/",
|
|
61
61
|
"author": "nyaomaru",
|