is-kit 1.1.5 → 1.1.7
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 +18 -1
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +22 -1
- package/dist/index.mjs +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,13 +120,30 @@ 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`.
|
|
124
|
+
|
|
123
125
|
```ts
|
|
124
|
-
import {
|
|
126
|
+
import {
|
|
127
|
+
isPrimitive,
|
|
128
|
+
isNumber,
|
|
129
|
+
isInteger,
|
|
130
|
+
isSafeInteger,
|
|
131
|
+
isPositive,
|
|
132
|
+
isNegative,
|
|
133
|
+
} from 'is-kit';
|
|
125
134
|
|
|
135
|
+
// Any primitive
|
|
126
136
|
isPrimitive('x'); // true
|
|
127
137
|
isPrimitive(123); // true
|
|
128
138
|
isPrimitive(NaN); // true (use isNumber for finite only)
|
|
129
139
|
isPrimitive({}); // false
|
|
140
|
+
|
|
141
|
+
// Numeric helpers
|
|
142
|
+
isNumber(10); // true
|
|
143
|
+
isInteger(42); // true
|
|
144
|
+
isSafeInteger(2 ** 53); // false
|
|
145
|
+
isPositive(0); // false
|
|
146
|
+
isNegative(-0); // false
|
|
130
147
|
```
|
|
131
148
|
|
|
132
149
|
## Core Ideas
|
package/dist/index.d.mts
CHANGED
|
@@ -188,6 +188,35 @@ declare const isFiniteNumber: Refine<number, number>;
|
|
|
188
188
|
* @returns Predicate narrowing to finite `number`.
|
|
189
189
|
*/
|
|
190
190
|
declare const isNumber: Predicate<number>;
|
|
191
|
+
/**
|
|
192
|
+
* Checks whether a value is an integer number.
|
|
193
|
+
*
|
|
194
|
+
* Equivalent to `Number.isInteger(value)`.
|
|
195
|
+
* @returns Predicate narrowing to integer `number`.
|
|
196
|
+
*/
|
|
197
|
+
declare const isInteger: Predicate<number>;
|
|
198
|
+
/**
|
|
199
|
+
* Checks whether a value is a safe integer.
|
|
200
|
+
*
|
|
201
|
+
* Equivalent to `Number.isSafeInteger(value)`.
|
|
202
|
+
* @returns Predicate narrowing to safe-integer `number`.
|
|
203
|
+
*/
|
|
204
|
+
declare const isSafeInteger: Predicate<number>;
|
|
205
|
+
/**
|
|
206
|
+
* Checks whether a value is a positive finite number (> 0).
|
|
207
|
+
*
|
|
208
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
209
|
+
* @returns Predicate narrowing to positive `number`.
|
|
210
|
+
*/
|
|
211
|
+
declare const isPositive: Predicate<number>;
|
|
212
|
+
/**
|
|
213
|
+
* Checks whether a value is a negative finite number (< 0).
|
|
214
|
+
*
|
|
215
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
216
|
+
* Note: `-0` is not considered negative (consistent with `< 0`).
|
|
217
|
+
* @returns Predicate narrowing to negative `number`.
|
|
218
|
+
*/
|
|
219
|
+
declare const isNegative: Predicate<number>;
|
|
191
220
|
/**
|
|
192
221
|
* Checks whether a value is a boolean.
|
|
193
222
|
*
|
|
@@ -425,4 +454,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
425
454
|
*/
|
|
426
455
|
declare const toBooleanPredicates: (guards: readonly Guard<unknown>[]) => ReadonlyArray<(value: unknown) => boolean>;
|
|
427
456
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -188,6 +188,35 @@ declare const isFiniteNumber: Refine<number, number>;
|
|
|
188
188
|
* @returns Predicate narrowing to finite `number`.
|
|
189
189
|
*/
|
|
190
190
|
declare const isNumber: Predicate<number>;
|
|
191
|
+
/**
|
|
192
|
+
* Checks whether a value is an integer number.
|
|
193
|
+
*
|
|
194
|
+
* Equivalent to `Number.isInteger(value)`.
|
|
195
|
+
* @returns Predicate narrowing to integer `number`.
|
|
196
|
+
*/
|
|
197
|
+
declare const isInteger: Predicate<number>;
|
|
198
|
+
/**
|
|
199
|
+
* Checks whether a value is a safe integer.
|
|
200
|
+
*
|
|
201
|
+
* Equivalent to `Number.isSafeInteger(value)`.
|
|
202
|
+
* @returns Predicate narrowing to safe-integer `number`.
|
|
203
|
+
*/
|
|
204
|
+
declare const isSafeInteger: Predicate<number>;
|
|
205
|
+
/**
|
|
206
|
+
* Checks whether a value is a positive finite number (> 0).
|
|
207
|
+
*
|
|
208
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
209
|
+
* @returns Predicate narrowing to positive `number`.
|
|
210
|
+
*/
|
|
211
|
+
declare const isPositive: Predicate<number>;
|
|
212
|
+
/**
|
|
213
|
+
* Checks whether a value is a negative finite number (< 0).
|
|
214
|
+
*
|
|
215
|
+
* Uses `isNumber` internally to exclude NaN and ±Infinity.
|
|
216
|
+
* Note: `-0` is not considered negative (consistent with `< 0`).
|
|
217
|
+
* @returns Predicate narrowing to negative `number`.
|
|
218
|
+
*/
|
|
219
|
+
declare const isNegative: Predicate<number>;
|
|
191
220
|
/**
|
|
192
221
|
* Checks whether a value is a boolean.
|
|
193
222
|
*
|
|
@@ -425,4 +454,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
425
454
|
*/
|
|
426
455
|
declare const toBooleanPredicates: (guards: readonly Guard<unknown>[]) => ReadonlyArray<(value: unknown) => boolean>;
|
|
427
456
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -39,16 +39,20 @@ __export(index_exports, {
|
|
|
39
39
|
isError: () => isError,
|
|
40
40
|
isFiniteNumber: () => isFiniteNumber,
|
|
41
41
|
isFunction: () => isFunction,
|
|
42
|
+
isInteger: () => isInteger,
|
|
42
43
|
isIterable: () => isIterable,
|
|
43
44
|
isMap: () => isMap,
|
|
45
|
+
isNegative: () => isNegative,
|
|
44
46
|
isNull: () => isNull,
|
|
45
47
|
isNumber: () => isNumber,
|
|
46
48
|
isNumberPrimitive: () => isNumberPrimitive,
|
|
47
49
|
isObject: () => isObject,
|
|
48
50
|
isPlainObject: () => isPlainObject,
|
|
51
|
+
isPositive: () => isPositive,
|
|
49
52
|
isPrimitive: () => isPrimitive,
|
|
50
53
|
isPromiseLike: () => isPromiseLike,
|
|
51
54
|
isRegExp: () => isRegExp,
|
|
55
|
+
isSafeInteger: () => isSafeInteger,
|
|
52
56
|
isSet: () => isSet,
|
|
53
57
|
isString: () => isString,
|
|
54
58
|
isSymbol: () => isSymbol,
|
|
@@ -234,6 +238,16 @@ var isNumberPrimitive = define(
|
|
|
234
238
|
);
|
|
235
239
|
var isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
236
240
|
var isNumber = and(isNumberPrimitive, isFiniteNumber);
|
|
241
|
+
var isInteger = define(Number.isInteger);
|
|
242
|
+
var isSafeInteger = define(Number.isSafeInteger);
|
|
243
|
+
var isPositive = and(
|
|
244
|
+
isNumber,
|
|
245
|
+
predicateToRefine((n) => n > 0)
|
|
246
|
+
);
|
|
247
|
+
var isNegative = and(
|
|
248
|
+
isNumber,
|
|
249
|
+
predicateToRefine((n) => n < 0)
|
|
250
|
+
);
|
|
237
251
|
var isBoolean = define((value) => typeof value === "boolean");
|
|
238
252
|
var isBigInt = define((value) => typeof value === "bigint");
|
|
239
253
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
@@ -271,7 +285,10 @@ function tupleOf(...guards) {
|
|
|
271
285
|
|
|
272
286
|
// src/core/combinators/one-of.ts
|
|
273
287
|
function oneOf(...guards) {
|
|
274
|
-
|
|
288
|
+
const predicates = toBooleanPredicates(
|
|
289
|
+
guards
|
|
290
|
+
);
|
|
291
|
+
return (input) => predicates.some((guard) => guard(input));
|
|
275
292
|
}
|
|
276
293
|
|
|
277
294
|
// src/core/combinators/record.ts
|
|
@@ -371,16 +388,20 @@ function narrowKeyTo(guard, key) {
|
|
|
371
388
|
isError,
|
|
372
389
|
isFiniteNumber,
|
|
373
390
|
isFunction,
|
|
391
|
+
isInteger,
|
|
374
392
|
isIterable,
|
|
375
393
|
isMap,
|
|
394
|
+
isNegative,
|
|
376
395
|
isNull,
|
|
377
396
|
isNumber,
|
|
378
397
|
isNumberPrimitive,
|
|
379
398
|
isObject,
|
|
380
399
|
isPlainObject,
|
|
400
|
+
isPositive,
|
|
381
401
|
isPrimitive,
|
|
382
402
|
isPromiseLike,
|
|
383
403
|
isRegExp,
|
|
404
|
+
isSafeInteger,
|
|
384
405
|
isSet,
|
|
385
406
|
isString,
|
|
386
407
|
isSymbol,
|
package/dist/index.mjs
CHANGED
|
@@ -155,6 +155,16 @@ var isNumberPrimitive = define(
|
|
|
155
155
|
);
|
|
156
156
|
var isFiniteNumber = predicateToRefine(Number.isFinite);
|
|
157
157
|
var isNumber = and(isNumberPrimitive, isFiniteNumber);
|
|
158
|
+
var isInteger = define(Number.isInteger);
|
|
159
|
+
var isSafeInteger = define(Number.isSafeInteger);
|
|
160
|
+
var isPositive = and(
|
|
161
|
+
isNumber,
|
|
162
|
+
predicateToRefine((n) => n > 0)
|
|
163
|
+
);
|
|
164
|
+
var isNegative = and(
|
|
165
|
+
isNumber,
|
|
166
|
+
predicateToRefine((n) => n < 0)
|
|
167
|
+
);
|
|
158
168
|
var isBoolean = define((value) => typeof value === "boolean");
|
|
159
169
|
var isBigInt = define((value) => typeof value === "bigint");
|
|
160
170
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
@@ -192,7 +202,10 @@ function tupleOf(...guards) {
|
|
|
192
202
|
|
|
193
203
|
// src/core/combinators/one-of.ts
|
|
194
204
|
function oneOf(...guards) {
|
|
195
|
-
|
|
205
|
+
const predicates = toBooleanPredicates(
|
|
206
|
+
guards
|
|
207
|
+
);
|
|
208
|
+
return (input) => predicates.some((guard) => guard(input));
|
|
196
209
|
}
|
|
197
210
|
|
|
198
211
|
// src/core/combinators/record.ts
|
|
@@ -291,16 +304,20 @@ export {
|
|
|
291
304
|
isError,
|
|
292
305
|
isFiniteNumber,
|
|
293
306
|
isFunction,
|
|
307
|
+
isInteger,
|
|
294
308
|
isIterable,
|
|
295
309
|
isMap,
|
|
310
|
+
isNegative,
|
|
296
311
|
isNull,
|
|
297
312
|
isNumber,
|
|
298
313
|
isNumberPrimitive,
|
|
299
314
|
isObject,
|
|
300
315
|
isPlainObject,
|
|
316
|
+
isPositive,
|
|
301
317
|
isPrimitive,
|
|
302
318
|
isPromiseLike,
|
|
303
319
|
isRegExp,
|
|
320
|
+
isSafeInteger,
|
|
304
321
|
isSet,
|
|
305
322
|
isString,
|
|
306
323
|
isSymbol,
|