is-kit 1.1.8 → 1.1.10

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.js CHANGED
@@ -200,8 +200,8 @@ var isTypedArray = define(
200
200
  var isError = define(
201
201
  (value) => value instanceof Error || getTag(value) === "[object Error]"
202
202
  );
203
- var isURL = typeof URL !== "undefined" ? define((value) => value instanceof URL) : define((_value) => false);
204
- var isBlob = typeof Blob !== "undefined" ? define((value) => value instanceof Blob) : define((_value) => false);
203
+ var isURL = typeof URL !== "undefined" ? define((value) => value instanceof URL) : define(() => false);
204
+ var isBlob = typeof Blob !== "undefined" ? define((value) => value instanceof Blob) : define(() => false);
205
205
 
206
206
  // src/core/equals.ts
207
207
  function equals(target) {
@@ -318,44 +318,41 @@ function recordOf(keyFunction, valueFunction) {
318
318
  }
319
319
 
320
320
  // src/core/combinators/struct.ts
321
+ var hasRequiredKeys = (obj, schema, keys) => keys.every((key) => key in obj && schema[key](obj[key]));
322
+ var hasOnlyAllowedKeys = (obj, allowed) => Object.keys(obj).every((key) => allowed.has(key));
321
323
  function struct(schema, options) {
322
324
  const schemaKeys = Object.keys(schema);
323
325
  const allowed = options?.exact ? new Set(schemaKeys) : null;
324
326
  return (input) => {
325
327
  if (!isPlainObject(input)) return false;
326
328
  const obj = input;
327
- for (const key of schemaKeys) {
328
- if (!(key in obj)) return false;
329
- const guard = schema[key];
330
- if (!guard(obj[key])) return false;
331
- }
332
- if (allowed) {
333
- for (const key of Object.keys(obj)) {
334
- if (!allowed.has(key)) return false;
335
- }
336
- }
337
- return true;
329
+ if (!hasRequiredKeys(obj, schema, schemaKeys)) return false;
330
+ if (!allowed) return true;
331
+ return hasOnlyAllowedKeys(obj, allowed);
338
332
  };
339
333
  }
340
334
 
341
335
  // src/core/combinators/one-of-values.ts
342
336
  var ONE_OF_VALUES_LINEAR_SCAN_MAX = 8;
343
- function oneOfValues(...args) {
344
- const isSingleArrayArg = define((value) => {
345
- if (!Array.isArray(value)) return false;
346
- return value.length === 1 && Array.isArray(value[0]);
347
- });
348
- const items = isSingleArrayArg(args) ? args[0] : args;
349
- if (items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX) {
350
- return function(input) {
351
- return items.some((value) => Object.is(value, input));
352
- };
353
- }
337
+ var isSingleArrayArg = define(
338
+ (value) => Array.isArray(value) && value.length === 1 && Array.isArray(value[0])
339
+ );
340
+ var isZeroNumber = and(
341
+ isNumber,
342
+ predicateToRefine((value) => value === 0)
343
+ );
344
+ var normalizeValues = (args) => isSingleArrayArg(args) ? args[0] : args;
345
+ var createLinearPredicate = (items) => {
346
+ return function(input) {
347
+ return items.some((value) => Object.is(value, input));
348
+ };
349
+ };
350
+ var createSetPredicate = (items) => {
354
351
  let hasPositiveZero = false;
355
352
  let hasNegativeZero = false;
356
353
  const valueSet = /* @__PURE__ */ new Set();
357
354
  for (const literalValue of items) {
358
- if (typeof literalValue === "number" && (Object.is(literalValue, 0) || Object.is(literalValue, -0))) {
355
+ if (isZeroNumber(literalValue)) {
359
356
  if (Object.is(literalValue, -0)) hasNegativeZero = true;
360
357
  else hasPositiveZero = true;
361
358
  } else {
@@ -363,11 +360,15 @@ function oneOfValues(...args) {
363
360
  }
364
361
  }
365
362
  return function(input) {
366
- if (typeof input === "number" && (Object.is(input, 0) || Object.is(input, -0))) {
363
+ if (isZeroNumber(input)) {
367
364
  return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
368
365
  }
369
366
  return valueSet.has(input);
370
367
  };
368
+ };
369
+ function oneOfValues(...args) {
370
+ const items = normalizeValues(args);
371
+ return items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX ? createLinearPredicate(items) : createSetPredicate(items);
371
372
  }
372
373
 
373
374
  // src/core/key.ts
package/dist/index.mjs CHANGED
@@ -114,8 +114,8 @@ var isTypedArray = define(
114
114
  var isError = define(
115
115
  (value) => value instanceof Error || getTag(value) === "[object Error]"
116
116
  );
117
- var isURL = typeof URL !== "undefined" ? define((value) => value instanceof URL) : define((_value) => false);
118
- var isBlob = typeof Blob !== "undefined" ? define((value) => value instanceof Blob) : define((_value) => false);
117
+ var isURL = typeof URL !== "undefined" ? define((value) => value instanceof URL) : define(() => false);
118
+ var isBlob = typeof Blob !== "undefined" ? define((value) => value instanceof Blob) : define(() => false);
119
119
 
120
120
  // src/core/equals.ts
121
121
  function equals(target) {
@@ -232,44 +232,41 @@ function recordOf(keyFunction, valueFunction) {
232
232
  }
233
233
 
234
234
  // src/core/combinators/struct.ts
235
+ var hasRequiredKeys = (obj, schema, keys) => keys.every((key) => key in obj && schema[key](obj[key]));
236
+ var hasOnlyAllowedKeys = (obj, allowed) => Object.keys(obj).every((key) => allowed.has(key));
235
237
  function struct(schema, options) {
236
238
  const schemaKeys = Object.keys(schema);
237
239
  const allowed = options?.exact ? new Set(schemaKeys) : null;
238
240
  return (input) => {
239
241
  if (!isPlainObject(input)) return false;
240
242
  const obj = input;
241
- for (const key of schemaKeys) {
242
- if (!(key in obj)) return false;
243
- const guard = schema[key];
244
- if (!guard(obj[key])) return false;
245
- }
246
- if (allowed) {
247
- for (const key of Object.keys(obj)) {
248
- if (!allowed.has(key)) return false;
249
- }
250
- }
251
- return true;
243
+ if (!hasRequiredKeys(obj, schema, schemaKeys)) return false;
244
+ if (!allowed) return true;
245
+ return hasOnlyAllowedKeys(obj, allowed);
252
246
  };
253
247
  }
254
248
 
255
249
  // src/core/combinators/one-of-values.ts
256
250
  var ONE_OF_VALUES_LINEAR_SCAN_MAX = 8;
257
- function oneOfValues(...args) {
258
- const isSingleArrayArg = define((value) => {
259
- if (!Array.isArray(value)) return false;
260
- return value.length === 1 && Array.isArray(value[0]);
261
- });
262
- const items = isSingleArrayArg(args) ? args[0] : args;
263
- if (items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX) {
264
- return function(input) {
265
- return items.some((value) => Object.is(value, input));
266
- };
267
- }
251
+ var isSingleArrayArg = define(
252
+ (value) => Array.isArray(value) && value.length === 1 && Array.isArray(value[0])
253
+ );
254
+ var isZeroNumber = and(
255
+ isNumber,
256
+ predicateToRefine((value) => value === 0)
257
+ );
258
+ var normalizeValues = (args) => isSingleArrayArg(args) ? args[0] : args;
259
+ var createLinearPredicate = (items) => {
260
+ return function(input) {
261
+ return items.some((value) => Object.is(value, input));
262
+ };
263
+ };
264
+ var createSetPredicate = (items) => {
268
265
  let hasPositiveZero = false;
269
266
  let hasNegativeZero = false;
270
267
  const valueSet = /* @__PURE__ */ new Set();
271
268
  for (const literalValue of items) {
272
- if (typeof literalValue === "number" && (Object.is(literalValue, 0) || Object.is(literalValue, -0))) {
269
+ if (isZeroNumber(literalValue)) {
273
270
  if (Object.is(literalValue, -0)) hasNegativeZero = true;
274
271
  else hasPositiveZero = true;
275
272
  } else {
@@ -277,11 +274,15 @@ function oneOfValues(...args) {
277
274
  }
278
275
  }
279
276
  return function(input) {
280
- if (typeof input === "number" && (Object.is(input, 0) || Object.is(input, -0))) {
277
+ if (isZeroNumber(input)) {
281
278
  return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
282
279
  }
283
280
  return valueSet.has(input);
284
281
  };
282
+ };
283
+ function oneOfValues(...args) {
284
+ const items = normalizeValues(args);
285
+ return items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX ? createLinearPredicate(items) : createSetPredicate(items);
285
286
  }
286
287
 
287
288
  // src/core/key.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
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",
@@ -39,10 +39,13 @@
39
39
  "devDependencies": {
40
40
  "@eslint/js": "^9.33.0",
41
41
  "@types/jest": "^30.0.0",
42
+ "@typescript-eslint/eslint-plugin": "^8.12.0",
43
+ "@typescript-eslint/parser": "^8.12.0",
42
44
  "eslint": "^9.33.0",
43
45
  "eslint-config-prettier": "^10.1.8",
44
46
  "eslint-plugin-prettier": "^5.5.4",
45
47
  "jest": "^30.0.5",
48
+ "lefthook": "^2.0.13",
46
49
  "prettier": "^3.6.2",
47
50
  "ts-jest": "^29.4.1",
48
51
  "tsd": "^0.33.0",