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 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
- return (input) => guards.some((guard) => guard(input));
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(...values) {
315
- if (values.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX) {
316
- const items = values;
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
- const valueSet = new Set(values);
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
- return (input) => guards.some((guard) => guard(input));
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(...values) {
236
- if (values.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX) {
237
- const items = values;
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
- const valueSet = new Set(values);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Make 'isXXX' easier. Let's make your code type safe and more readable!",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",