is-kit 1.1.4 → 1.1.6
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/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +25 -5
- package/dist/index.mjs +25 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -278,12 +278,15 @@ declare function struct<S extends Schema>(schema: S, options?: {
|
|
|
278
278
|
|
|
279
279
|
/**
|
|
280
280
|
* Creates a guard that matches when the input is one of the provided literal values.
|
|
281
|
-
* Uses `Object.is` for exact value semantics.
|
|
281
|
+
* Uses `Object.is` for exact value semantics. For large sets, keeps O(1) lookups while
|
|
282
|
+
* preserving `+0` vs `-0` by tracking zero variants explicitly in addition to a `Set`.
|
|
282
283
|
*
|
|
283
|
-
* @param values Literal primitives to compare against.
|
|
284
|
+
* @param values Literal primitives to compare against (varargs or single readonly tuple array).
|
|
284
285
|
* @returns Predicate narrowing to the union of the provided literal values.
|
|
285
286
|
*/
|
|
286
287
|
declare function oneOfValues<const T extends ReadonlyArray<Primitive>>(...values: T): Predicate<T[number]>;
|
|
288
|
+
declare function oneOfValues<const T extends ReadonlyArray<Primitive>>(values: T): Predicate<T[number]>;
|
|
289
|
+
declare function oneOfValues<const T extends ReadonlyArray<Primitive>>(...valuesOrArray: T | [T]): Predicate<T[number]>;
|
|
287
290
|
|
|
288
291
|
/**
|
|
289
292
|
* Checks whether a value is a function.
|
package/dist/index.d.ts
CHANGED
|
@@ -278,12 +278,15 @@ declare function struct<S extends Schema>(schema: S, options?: {
|
|
|
278
278
|
|
|
279
279
|
/**
|
|
280
280
|
* Creates a guard that matches when the input is one of the provided literal values.
|
|
281
|
-
* Uses `Object.is` for exact value semantics.
|
|
281
|
+
* Uses `Object.is` for exact value semantics. For large sets, keeps O(1) lookups while
|
|
282
|
+
* preserving `+0` vs `-0` by tracking zero variants explicitly in addition to a `Set`.
|
|
282
283
|
*
|
|
283
|
-
* @param values Literal primitives to compare against.
|
|
284
|
+
* @param values Literal primitives to compare against (varargs or single readonly tuple array).
|
|
284
285
|
* @returns Predicate narrowing to the union of the provided literal values.
|
|
285
286
|
*/
|
|
286
287
|
declare function oneOfValues<const T extends ReadonlyArray<Primitive>>(...values: T): Predicate<T[number]>;
|
|
288
|
+
declare function oneOfValues<const T extends ReadonlyArray<Primitive>>(values: T): Predicate<T[number]>;
|
|
289
|
+
declare function oneOfValues<const T extends ReadonlyArray<Primitive>>(...valuesOrArray: T | [T]): Predicate<T[number]>;
|
|
287
290
|
|
|
288
291
|
/**
|
|
289
292
|
* Checks whether a value is a function.
|
package/dist/index.js
CHANGED
|
@@ -271,7 +271,10 @@ function tupleOf(...guards) {
|
|
|
271
271
|
|
|
272
272
|
// src/core/combinators/one-of.ts
|
|
273
273
|
function oneOf(...guards) {
|
|
274
|
-
|
|
274
|
+
const predicates = toBooleanPredicates(
|
|
275
|
+
guards
|
|
276
|
+
);
|
|
277
|
+
return (input) => predicates.some((guard) => guard(input));
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
// src/core/combinators/record.ts
|
|
@@ -311,15 +314,32 @@ function struct(schema, options) {
|
|
|
311
314
|
|
|
312
315
|
// src/core/combinators/one-of-values.ts
|
|
313
316
|
var ONE_OF_VALUES_LINEAR_SCAN_MAX = 8;
|
|
314
|
-
function oneOfValues(...
|
|
315
|
-
|
|
316
|
-
|
|
317
|
+
function oneOfValues(...args) {
|
|
318
|
+
const isSingleArrayArg = define((value) => {
|
|
319
|
+
if (!Array.isArray(value)) return false;
|
|
320
|
+
return value.length === 1 && Array.isArray(value[0]);
|
|
321
|
+
});
|
|
322
|
+
const items = isSingleArrayArg(args) ? args[0] : args;
|
|
323
|
+
if (items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX) {
|
|
317
324
|
return function(input) {
|
|
318
325
|
return items.some((value) => Object.is(value, input));
|
|
319
326
|
};
|
|
320
327
|
}
|
|
321
|
-
|
|
328
|
+
let hasPositiveZero = false;
|
|
329
|
+
let hasNegativeZero = false;
|
|
330
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
331
|
+
for (const literalValue of items) {
|
|
332
|
+
if (typeof literalValue === "number" && (Object.is(literalValue, 0) || Object.is(literalValue, -0))) {
|
|
333
|
+
if (Object.is(literalValue, -0)) hasNegativeZero = true;
|
|
334
|
+
else hasPositiveZero = true;
|
|
335
|
+
} else {
|
|
336
|
+
valueSet.add(literalValue);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
322
339
|
return function(input) {
|
|
340
|
+
if (typeof input === "number" && (Object.is(input, 0) || Object.is(input, -0))) {
|
|
341
|
+
return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
|
|
342
|
+
}
|
|
323
343
|
return valueSet.has(input);
|
|
324
344
|
};
|
|
325
345
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -192,7 +192,10 @@ function tupleOf(...guards) {
|
|
|
192
192
|
|
|
193
193
|
// src/core/combinators/one-of.ts
|
|
194
194
|
function oneOf(...guards) {
|
|
195
|
-
|
|
195
|
+
const predicates = toBooleanPredicates(
|
|
196
|
+
guards
|
|
197
|
+
);
|
|
198
|
+
return (input) => predicates.some((guard) => guard(input));
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
// src/core/combinators/record.ts
|
|
@@ -232,15 +235,32 @@ function struct(schema, options) {
|
|
|
232
235
|
|
|
233
236
|
// src/core/combinators/one-of-values.ts
|
|
234
237
|
var ONE_OF_VALUES_LINEAR_SCAN_MAX = 8;
|
|
235
|
-
function oneOfValues(...
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
function oneOfValues(...args) {
|
|
239
|
+
const isSingleArrayArg = define((value) => {
|
|
240
|
+
if (!Array.isArray(value)) return false;
|
|
241
|
+
return value.length === 1 && Array.isArray(value[0]);
|
|
242
|
+
});
|
|
243
|
+
const items = isSingleArrayArg(args) ? args[0] : args;
|
|
244
|
+
if (items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX) {
|
|
238
245
|
return function(input) {
|
|
239
246
|
return items.some((value) => Object.is(value, input));
|
|
240
247
|
};
|
|
241
248
|
}
|
|
242
|
-
|
|
249
|
+
let hasPositiveZero = false;
|
|
250
|
+
let hasNegativeZero = false;
|
|
251
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
252
|
+
for (const literalValue of items) {
|
|
253
|
+
if (typeof literalValue === "number" && (Object.is(literalValue, 0) || Object.is(literalValue, -0))) {
|
|
254
|
+
if (Object.is(literalValue, -0)) hasNegativeZero = true;
|
|
255
|
+
else hasPositiveZero = true;
|
|
256
|
+
} else {
|
|
257
|
+
valueSet.add(literalValue);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
243
260
|
return function(input) {
|
|
261
|
+
if (typeof input === "number" && (Object.is(input, 0) || Object.is(input, -0))) {
|
|
262
|
+
return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
|
|
263
|
+
}
|
|
244
264
|
return valueSet.has(input);
|
|
245
265
|
};
|
|
246
266
|
}
|