is-kit 1.1.7 → 1.1.8
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 +12 -1
- package/dist/index.d.mts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +15 -0
- package/dist/index.mjs +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ When validating complex shapes, reach for `struct` — and friends like `arrayOf
|
|
|
120
120
|
|
|
121
121
|
Built-in primitives: `isString`, `isNumber` (finite), `isBoolean`, `isBigInt`, `isSymbol`, `isUndefined`, `isNull` — and a preset `isPrimitive` for any primitive.
|
|
122
122
|
|
|
123
|
-
Numeric helpers are included for common cases: `isInteger`, `isSafeInteger`, `isPositive`, `isNegative`.
|
|
123
|
+
Numeric helpers are included for common cases: `isInteger`, `isSafeInteger`, `isPositive`, `isNegative`, `isZero`, `isNaN`, `isInfiniteNumber`.
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
126
|
import {
|
|
@@ -130,6 +130,9 @@ import {
|
|
|
130
130
|
isSafeInteger,
|
|
131
131
|
isPositive,
|
|
132
132
|
isNegative,
|
|
133
|
+
isZero,
|
|
134
|
+
isNaN,
|
|
135
|
+
isInfiniteNumber,
|
|
133
136
|
} from 'is-kit';
|
|
134
137
|
|
|
135
138
|
// Any primitive
|
|
@@ -142,8 +145,16 @@ isPrimitive({}); // false
|
|
|
142
145
|
isNumber(10); // true
|
|
143
146
|
isInteger(42); // true
|
|
144
147
|
isSafeInteger(2 ** 53); // false
|
|
148
|
+
isPositive(3); // true
|
|
145
149
|
isPositive(0); // false
|
|
150
|
+
isNegative(-3); // true
|
|
146
151
|
isNegative(-0); // false
|
|
152
|
+
isZero(0); // true
|
|
153
|
+
isZero(1); // false
|
|
154
|
+
isNaN(NaN); // true
|
|
155
|
+
isNaN(0); // false
|
|
156
|
+
isInfiniteNumber(Infinity); // true
|
|
157
|
+
isInfiniteNumber(1); // false
|
|
147
158
|
```
|
|
148
159
|
|
|
149
160
|
## Core Ideas
|
package/dist/index.d.mts
CHANGED
|
@@ -178,6 +178,19 @@ declare const isString: Predicate<string>;
|
|
|
178
178
|
* @returns Predicate narrowing to `number` (primitive-only).
|
|
179
179
|
*/
|
|
180
180
|
declare const isNumberPrimitive: Predicate<number>;
|
|
181
|
+
/**
|
|
182
|
+
* Checks whether a value is `NaN`.
|
|
183
|
+
*
|
|
184
|
+
* Equivalent to `Number.isNaN(value)` without coercion.
|
|
185
|
+
* @returns Predicate narrowing to `number` (`NaN` only).
|
|
186
|
+
*/
|
|
187
|
+
declare const isNaN: Predicate<number>;
|
|
188
|
+
/**
|
|
189
|
+
* Checks whether a value is an infinite number (±Infinity).
|
|
190
|
+
*
|
|
191
|
+
* @returns Predicate narrowing to `number` (Infinity or -Infinity).
|
|
192
|
+
*/
|
|
193
|
+
declare const isInfiniteNumber: Predicate<number>;
|
|
181
194
|
/**
|
|
182
195
|
* Checks whether a number is finite.
|
|
183
196
|
* @returns Refinement that accepts only finite numbers.
|
|
@@ -217,6 +230,12 @@ declare const isPositive: Predicate<number>;
|
|
|
217
230
|
* @returns Predicate narrowing to negative `number`.
|
|
218
231
|
*/
|
|
219
232
|
declare const isNegative: Predicate<number>;
|
|
233
|
+
/**
|
|
234
|
+
* Checks whether a value is a finite number that equals zero (including `-0`).
|
|
235
|
+
*
|
|
236
|
+
* @returns Predicate narrowing to zero `number`.
|
|
237
|
+
*/
|
|
238
|
+
declare const isZero: Predicate<number>;
|
|
220
239
|
/**
|
|
221
240
|
* Checks whether a value is a boolean.
|
|
222
241
|
*
|
|
@@ -454,4 +473,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
454
473
|
*/
|
|
455
474
|
declare const toBooleanPredicates: (guards: readonly Guard<unknown>[]) => ReadonlyArray<(value: unknown) => boolean>;
|
|
456
475
|
|
|
457
|
-
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, define, equals, equalsBy, equalsKey, guardIn, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInteger, isIterable, isMap, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
|
476
|
+
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, define, equals, equalsBy, equalsKey, guardIn, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,19 @@ declare const isString: Predicate<string>;
|
|
|
178
178
|
* @returns Predicate narrowing to `number` (primitive-only).
|
|
179
179
|
*/
|
|
180
180
|
declare const isNumberPrimitive: Predicate<number>;
|
|
181
|
+
/**
|
|
182
|
+
* Checks whether a value is `NaN`.
|
|
183
|
+
*
|
|
184
|
+
* Equivalent to `Number.isNaN(value)` without coercion.
|
|
185
|
+
* @returns Predicate narrowing to `number` (`NaN` only).
|
|
186
|
+
*/
|
|
187
|
+
declare const isNaN: Predicate<number>;
|
|
188
|
+
/**
|
|
189
|
+
* Checks whether a value is an infinite number (±Infinity).
|
|
190
|
+
*
|
|
191
|
+
* @returns Predicate narrowing to `number` (Infinity or -Infinity).
|
|
192
|
+
*/
|
|
193
|
+
declare const isInfiniteNumber: Predicate<number>;
|
|
181
194
|
/**
|
|
182
195
|
* Checks whether a number is finite.
|
|
183
196
|
* @returns Refinement that accepts only finite numbers.
|
|
@@ -217,6 +230,12 @@ declare const isPositive: Predicate<number>;
|
|
|
217
230
|
* @returns Predicate narrowing to negative `number`.
|
|
218
231
|
*/
|
|
219
232
|
declare const isNegative: Predicate<number>;
|
|
233
|
+
/**
|
|
234
|
+
* Checks whether a value is a finite number that equals zero (including `-0`).
|
|
235
|
+
*
|
|
236
|
+
* @returns Predicate narrowing to zero `number`.
|
|
237
|
+
*/
|
|
238
|
+
declare const isZero: Predicate<number>;
|
|
220
239
|
/**
|
|
221
240
|
* Checks whether a value is a boolean.
|
|
222
241
|
*
|
|
@@ -454,4 +473,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
454
473
|
*/
|
|
455
474
|
declare const toBooleanPredicates: (guards: readonly Guard<unknown>[]) => ReadonlyArray<(value: unknown) => boolean>;
|
|
456
475
|
|
|
457
|
-
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, define, equals, equalsBy, equalsKey, guardIn, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInteger, isIterable, isMap, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
|
476
|
+
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, define, equals, equalsBy, equalsKey, guardIn, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
package/dist/index.js
CHANGED
|
@@ -39,9 +39,11 @@ __export(index_exports, {
|
|
|
39
39
|
isError: () => isError,
|
|
40
40
|
isFiniteNumber: () => isFiniteNumber,
|
|
41
41
|
isFunction: () => isFunction,
|
|
42
|
+
isInfiniteNumber: () => isInfiniteNumber,
|
|
42
43
|
isInteger: () => isInteger,
|
|
43
44
|
isIterable: () => isIterable,
|
|
44
45
|
isMap: () => isMap,
|
|
46
|
+
isNaN: () => isNaN,
|
|
45
47
|
isNegative: () => isNegative,
|
|
46
48
|
isNull: () => isNull,
|
|
47
49
|
isNumber: () => isNumber,
|
|
@@ -61,6 +63,7 @@ __export(index_exports, {
|
|
|
61
63
|
isUndefined: () => isUndefined,
|
|
62
64
|
isWeakMap: () => isWeakMap,
|
|
63
65
|
isWeakSet: () => isWeakSet,
|
|
66
|
+
isZero: () => isZero,
|
|
64
67
|
narrowKeyTo: () => narrowKeyTo,
|
|
65
68
|
nonNull: () => nonNull,
|
|
66
69
|
not: () => not,
|
|
@@ -236,6 +239,11 @@ var isString = define((value) => typeof value === "string");
|
|
|
236
239
|
var isNumberPrimitive = define(
|
|
237
240
|
(value) => typeof value === "number"
|
|
238
241
|
);
|
|
242
|
+
var isNaN = define(Number.isNaN);
|
|
243
|
+
var isInfiniteNumber = and(
|
|
244
|
+
isNumberPrimitive,
|
|
245
|
+
predicateToRefine((n) => n === Infinity || n === -Infinity)
|
|
246
|
+
);
|
|
239
247
|
var isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
240
248
|
var isNumber = and(isNumberPrimitive, isFiniteNumber);
|
|
241
249
|
var isInteger = define(Number.isInteger);
|
|
@@ -248,6 +256,10 @@ var isNegative = and(
|
|
|
248
256
|
isNumber,
|
|
249
257
|
predicateToRefine((n) => n < 0)
|
|
250
258
|
);
|
|
259
|
+
var isZero = and(
|
|
260
|
+
isNumber,
|
|
261
|
+
predicateToRefine((n) => n === 0)
|
|
262
|
+
);
|
|
251
263
|
var isBoolean = define((value) => typeof value === "boolean");
|
|
252
264
|
var isBigInt = define((value) => typeof value === "bigint");
|
|
253
265
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
@@ -388,9 +400,11 @@ function narrowKeyTo(guard, key) {
|
|
|
388
400
|
isError,
|
|
389
401
|
isFiniteNumber,
|
|
390
402
|
isFunction,
|
|
403
|
+
isInfiniteNumber,
|
|
391
404
|
isInteger,
|
|
392
405
|
isIterable,
|
|
393
406
|
isMap,
|
|
407
|
+
isNaN,
|
|
394
408
|
isNegative,
|
|
395
409
|
isNull,
|
|
396
410
|
isNumber,
|
|
@@ -410,6 +424,7 @@ function narrowKeyTo(guard, key) {
|
|
|
410
424
|
isUndefined,
|
|
411
425
|
isWeakMap,
|
|
412
426
|
isWeakSet,
|
|
427
|
+
isZero,
|
|
413
428
|
narrowKeyTo,
|
|
414
429
|
nonNull,
|
|
415
430
|
not,
|
package/dist/index.mjs
CHANGED
|
@@ -153,6 +153,11 @@ var isString = define((value) => typeof value === "string");
|
|
|
153
153
|
var isNumberPrimitive = define(
|
|
154
154
|
(value) => typeof value === "number"
|
|
155
155
|
);
|
|
156
|
+
var isNaN = define(Number.isNaN);
|
|
157
|
+
var isInfiniteNumber = and(
|
|
158
|
+
isNumberPrimitive,
|
|
159
|
+
predicateToRefine((n) => n === Infinity || n === -Infinity)
|
|
160
|
+
);
|
|
156
161
|
var isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
157
162
|
var isNumber = and(isNumberPrimitive, isFiniteNumber);
|
|
158
163
|
var isInteger = define(Number.isInteger);
|
|
@@ -165,6 +170,10 @@ var isNegative = and(
|
|
|
165
170
|
isNumber,
|
|
166
171
|
predicateToRefine((n) => n < 0)
|
|
167
172
|
);
|
|
173
|
+
var isZero = and(
|
|
174
|
+
isNumber,
|
|
175
|
+
predicateToRefine((n) => n === 0)
|
|
176
|
+
);
|
|
168
177
|
var isBoolean = define((value) => typeof value === "boolean");
|
|
169
178
|
var isBigInt = define((value) => typeof value === "bigint");
|
|
170
179
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
@@ -304,9 +313,11 @@ export {
|
|
|
304
313
|
isError,
|
|
305
314
|
isFiniteNumber,
|
|
306
315
|
isFunction,
|
|
316
|
+
isInfiniteNumber,
|
|
307
317
|
isInteger,
|
|
308
318
|
isIterable,
|
|
309
319
|
isMap,
|
|
320
|
+
isNaN,
|
|
310
321
|
isNegative,
|
|
311
322
|
isNull,
|
|
312
323
|
isNumber,
|
|
@@ -326,6 +337,7 @@ export {
|
|
|
326
337
|
isUndefined,
|
|
327
338
|
isWeakMap,
|
|
328
339
|
isWeakSet,
|
|
340
|
+
isZero,
|
|
329
341
|
narrowKeyTo,
|
|
330
342
|
nonNull,
|
|
331
343
|
not,
|