is-kit 1.1.6 → 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 +29 -1
- package/dist/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +33 -0
- package/dist/index.mjs +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,13 +120,41 @@ 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`, `isZero`, `isNaN`, `isInfiniteNumber`.
|
|
124
|
+
|
|
123
125
|
```ts
|
|
124
|
-
import {
|
|
126
|
+
import {
|
|
127
|
+
isPrimitive,
|
|
128
|
+
isNumber,
|
|
129
|
+
isInteger,
|
|
130
|
+
isSafeInteger,
|
|
131
|
+
isPositive,
|
|
132
|
+
isNegative,
|
|
133
|
+
isZero,
|
|
134
|
+
isNaN,
|
|
135
|
+
isInfiniteNumber,
|
|
136
|
+
} from 'is-kit';
|
|
125
137
|
|
|
138
|
+
// Any primitive
|
|
126
139
|
isPrimitive('x'); // true
|
|
127
140
|
isPrimitive(123); // true
|
|
128
141
|
isPrimitive(NaN); // true (use isNumber for finite only)
|
|
129
142
|
isPrimitive({}); // false
|
|
143
|
+
|
|
144
|
+
// Numeric helpers
|
|
145
|
+
isNumber(10); // true
|
|
146
|
+
isInteger(42); // true
|
|
147
|
+
isSafeInteger(2 ** 53); // false
|
|
148
|
+
isPositive(3); // true
|
|
149
|
+
isPositive(0); // false
|
|
150
|
+
isNegative(-3); // true
|
|
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
|
|
130
158
|
```
|
|
131
159
|
|
|
132
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.
|
|
@@ -188,6 +201,41 @@ declare const isFiniteNumber: Refine<number, number>;
|
|
|
188
201
|
* @returns Predicate narrowing to finite `number`.
|
|
189
202
|
*/
|
|
190
203
|
declare const isNumber: Predicate<number>;
|
|
204
|
+
/**
|
|
205
|
+
* Checks whether a value is an integer number.
|
|
206
|
+
*
|
|
207
|
+
* Equivalent to `Number.isInteger(value)`.
|
|
208
|
+
* @returns Predicate narrowing to integer `number`.
|
|
209
|
+
*/
|
|
210
|
+
declare const isInteger: Predicate<number>;
|
|
211
|
+
/**
|
|
212
|
+
* Checks whether a value is a safe integer.
|
|
213
|
+
*
|
|
214
|
+
* Equivalent to `Number.isSafeInteger(value)`.
|
|
215
|
+
* @returns Predicate narrowing to safe-integer `number`.
|
|
216
|
+
*/
|
|
217
|
+
declare const isSafeInteger: Predicate<number>;
|
|
218
|
+
/**
|
|
219
|
+
* Checks whether a value is a positive finite number (> 0).
|
|
220
|
+
*
|
|
221
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
222
|
+
* @returns Predicate narrowing to positive `number`.
|
|
223
|
+
*/
|
|
224
|
+
declare const isPositive: Predicate<number>;
|
|
225
|
+
/**
|
|
226
|
+
* Checks whether a value is a negative finite number (< 0).
|
|
227
|
+
*
|
|
228
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
229
|
+
* Note: `-0` is not considered negative (consistent with `< 0`).
|
|
230
|
+
* @returns Predicate narrowing to negative `number`.
|
|
231
|
+
*/
|
|
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>;
|
|
191
239
|
/**
|
|
192
240
|
* Checks whether a value is a boolean.
|
|
193
241
|
*
|
|
@@ -425,4 +473,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
425
473
|
*/
|
|
426
474
|
declare const toBooleanPredicates: (guards: readonly Guard<unknown>[]) => ReadonlyArray<(value: unknown) => boolean>;
|
|
427
475
|
|
|
428
|
-
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, isIterable, isMap, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPrimitive, isPromiseLike, isRegExp, 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.
|
|
@@ -188,6 +201,41 @@ declare const isFiniteNumber: Refine<number, number>;
|
|
|
188
201
|
* @returns Predicate narrowing to finite `number`.
|
|
189
202
|
*/
|
|
190
203
|
declare const isNumber: Predicate<number>;
|
|
204
|
+
/**
|
|
205
|
+
* Checks whether a value is an integer number.
|
|
206
|
+
*
|
|
207
|
+
* Equivalent to `Number.isInteger(value)`.
|
|
208
|
+
* @returns Predicate narrowing to integer `number`.
|
|
209
|
+
*/
|
|
210
|
+
declare const isInteger: Predicate<number>;
|
|
211
|
+
/**
|
|
212
|
+
* Checks whether a value is a safe integer.
|
|
213
|
+
*
|
|
214
|
+
* Equivalent to `Number.isSafeInteger(value)`.
|
|
215
|
+
* @returns Predicate narrowing to safe-integer `number`.
|
|
216
|
+
*/
|
|
217
|
+
declare const isSafeInteger: Predicate<number>;
|
|
218
|
+
/**
|
|
219
|
+
* Checks whether a value is a positive finite number (> 0).
|
|
220
|
+
*
|
|
221
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
222
|
+
* @returns Predicate narrowing to positive `number`.
|
|
223
|
+
*/
|
|
224
|
+
declare const isPositive: Predicate<number>;
|
|
225
|
+
/**
|
|
226
|
+
* Checks whether a value is a negative finite number (< 0).
|
|
227
|
+
*
|
|
228
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
229
|
+
* Note: `-0` is not considered negative (consistent with `< 0`).
|
|
230
|
+
* @returns Predicate narrowing to negative `number`.
|
|
231
|
+
*/
|
|
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>;
|
|
191
239
|
/**
|
|
192
240
|
* Checks whether a value is a boolean.
|
|
193
241
|
*
|
|
@@ -425,4 +473,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
425
473
|
*/
|
|
426
474
|
declare const toBooleanPredicates: (guards: readonly Guard<unknown>[]) => ReadonlyArray<(value: unknown) => boolean>;
|
|
427
475
|
|
|
428
|
-
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, isIterable, isMap, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPrimitive, isPromiseLike, isRegExp, 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,16 +39,22 @@ __export(index_exports, {
|
|
|
39
39
|
isError: () => isError,
|
|
40
40
|
isFiniteNumber: () => isFiniteNumber,
|
|
41
41
|
isFunction: () => isFunction,
|
|
42
|
+
isInfiniteNumber: () => isInfiniteNumber,
|
|
43
|
+
isInteger: () => isInteger,
|
|
42
44
|
isIterable: () => isIterable,
|
|
43
45
|
isMap: () => isMap,
|
|
46
|
+
isNaN: () => isNaN,
|
|
47
|
+
isNegative: () => isNegative,
|
|
44
48
|
isNull: () => isNull,
|
|
45
49
|
isNumber: () => isNumber,
|
|
46
50
|
isNumberPrimitive: () => isNumberPrimitive,
|
|
47
51
|
isObject: () => isObject,
|
|
48
52
|
isPlainObject: () => isPlainObject,
|
|
53
|
+
isPositive: () => isPositive,
|
|
49
54
|
isPrimitive: () => isPrimitive,
|
|
50
55
|
isPromiseLike: () => isPromiseLike,
|
|
51
56
|
isRegExp: () => isRegExp,
|
|
57
|
+
isSafeInteger: () => isSafeInteger,
|
|
52
58
|
isSet: () => isSet,
|
|
53
59
|
isString: () => isString,
|
|
54
60
|
isSymbol: () => isSymbol,
|
|
@@ -57,6 +63,7 @@ __export(index_exports, {
|
|
|
57
63
|
isUndefined: () => isUndefined,
|
|
58
64
|
isWeakMap: () => isWeakMap,
|
|
59
65
|
isWeakSet: () => isWeakSet,
|
|
66
|
+
isZero: () => isZero,
|
|
60
67
|
narrowKeyTo: () => narrowKeyTo,
|
|
61
68
|
nonNull: () => nonNull,
|
|
62
69
|
not: () => not,
|
|
@@ -232,8 +239,27 @@ var isString = define((value) => typeof value === "string");
|
|
|
232
239
|
var isNumberPrimitive = define(
|
|
233
240
|
(value) => typeof value === "number"
|
|
234
241
|
);
|
|
242
|
+
var isNaN = define(Number.isNaN);
|
|
243
|
+
var isInfiniteNumber = and(
|
|
244
|
+
isNumberPrimitive,
|
|
245
|
+
predicateToRefine((n) => n === Infinity || n === -Infinity)
|
|
246
|
+
);
|
|
235
247
|
var isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
236
248
|
var isNumber = and(isNumberPrimitive, isFiniteNumber);
|
|
249
|
+
var isInteger = define(Number.isInteger);
|
|
250
|
+
var isSafeInteger = define(Number.isSafeInteger);
|
|
251
|
+
var isPositive = and(
|
|
252
|
+
isNumber,
|
|
253
|
+
predicateToRefine((n) => n > 0)
|
|
254
|
+
);
|
|
255
|
+
var isNegative = and(
|
|
256
|
+
isNumber,
|
|
257
|
+
predicateToRefine((n) => n < 0)
|
|
258
|
+
);
|
|
259
|
+
var isZero = and(
|
|
260
|
+
isNumber,
|
|
261
|
+
predicateToRefine((n) => n === 0)
|
|
262
|
+
);
|
|
237
263
|
var isBoolean = define((value) => typeof value === "boolean");
|
|
238
264
|
var isBigInt = define((value) => typeof value === "bigint");
|
|
239
265
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
@@ -374,16 +400,22 @@ function narrowKeyTo(guard, key) {
|
|
|
374
400
|
isError,
|
|
375
401
|
isFiniteNumber,
|
|
376
402
|
isFunction,
|
|
403
|
+
isInfiniteNumber,
|
|
404
|
+
isInteger,
|
|
377
405
|
isIterable,
|
|
378
406
|
isMap,
|
|
407
|
+
isNaN,
|
|
408
|
+
isNegative,
|
|
379
409
|
isNull,
|
|
380
410
|
isNumber,
|
|
381
411
|
isNumberPrimitive,
|
|
382
412
|
isObject,
|
|
383
413
|
isPlainObject,
|
|
414
|
+
isPositive,
|
|
384
415
|
isPrimitive,
|
|
385
416
|
isPromiseLike,
|
|
386
417
|
isRegExp,
|
|
418
|
+
isSafeInteger,
|
|
387
419
|
isSet,
|
|
388
420
|
isString,
|
|
389
421
|
isSymbol,
|
|
@@ -392,6 +424,7 @@ function narrowKeyTo(guard, key) {
|
|
|
392
424
|
isUndefined,
|
|
393
425
|
isWeakMap,
|
|
394
426
|
isWeakSet,
|
|
427
|
+
isZero,
|
|
395
428
|
narrowKeyTo,
|
|
396
429
|
nonNull,
|
|
397
430
|
not,
|
package/dist/index.mjs
CHANGED
|
@@ -153,8 +153,27 @@ 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);
|
|
163
|
+
var isInteger = define(Number.isInteger);
|
|
164
|
+
var isSafeInteger = define(Number.isSafeInteger);
|
|
165
|
+
var isPositive = and(
|
|
166
|
+
isNumber,
|
|
167
|
+
predicateToRefine((n) => n > 0)
|
|
168
|
+
);
|
|
169
|
+
var isNegative = and(
|
|
170
|
+
isNumber,
|
|
171
|
+
predicateToRefine((n) => n < 0)
|
|
172
|
+
);
|
|
173
|
+
var isZero = and(
|
|
174
|
+
isNumber,
|
|
175
|
+
predicateToRefine((n) => n === 0)
|
|
176
|
+
);
|
|
158
177
|
var isBoolean = define((value) => typeof value === "boolean");
|
|
159
178
|
var isBigInt = define((value) => typeof value === "bigint");
|
|
160
179
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
@@ -294,16 +313,22 @@ export {
|
|
|
294
313
|
isError,
|
|
295
314
|
isFiniteNumber,
|
|
296
315
|
isFunction,
|
|
316
|
+
isInfiniteNumber,
|
|
317
|
+
isInteger,
|
|
297
318
|
isIterable,
|
|
298
319
|
isMap,
|
|
320
|
+
isNaN,
|
|
321
|
+
isNegative,
|
|
299
322
|
isNull,
|
|
300
323
|
isNumber,
|
|
301
324
|
isNumberPrimitive,
|
|
302
325
|
isObject,
|
|
303
326
|
isPlainObject,
|
|
327
|
+
isPositive,
|
|
304
328
|
isPrimitive,
|
|
305
329
|
isPromiseLike,
|
|
306
330
|
isRegExp,
|
|
331
|
+
isSafeInteger,
|
|
307
332
|
isSet,
|
|
308
333
|
isString,
|
|
309
334
|
isSymbol,
|
|
@@ -312,6 +337,7 @@ export {
|
|
|
312
337
|
isUndefined,
|
|
313
338
|
isWeakMap,
|
|
314
339
|
isWeakSet,
|
|
340
|
+
isZero,
|
|
315
341
|
narrowKeyTo,
|
|
316
342
|
nonNull,
|
|
317
343
|
not,
|