@webdeveric/utils 0.55.0 → 0.56.0

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.
Files changed (41) hide show
  1. package/dist/cjs/predicate/factory/shape.js +3 -2
  2. package/dist/cjs/predicate/index.js +8 -0
  3. package/dist/cjs/predicate/isAny.js +5 -0
  4. package/dist/cjs/predicate/isArray.js +5 -0
  5. package/dist/cjs/predicate/isBinaryNumberString.js +5 -0
  6. package/dist/cjs/predicate/isHexNumberString.js +5 -0
  7. package/dist/cjs/predicate/isNumericValue.js +1 -1
  8. package/dist/cjs/predicate/isOctalNumberString.js +5 -0
  9. package/dist/cjs/predicate/isOptionalArray.js +6 -0
  10. package/dist/cjs/predicate/isOptionalObject.js +6 -0
  11. package/dist/cjs/predicate/isUnknown.js +5 -0
  12. package/dist/mjs/predicate/factory/shape.js +3 -2
  13. package/dist/mjs/predicate/index.js +8 -0
  14. package/dist/mjs/predicate/isAny.js +1 -0
  15. package/dist/mjs/predicate/isArray.js +1 -0
  16. package/dist/mjs/predicate/isBinaryNumberString.js +2 -0
  17. package/dist/mjs/predicate/isHexNumberString.js +2 -0
  18. package/dist/mjs/predicate/isNumericValue.js +1 -1
  19. package/dist/mjs/predicate/isOctalNumberString.js +2 -0
  20. package/dist/mjs/predicate/isOptionalArray.js +3 -0
  21. package/dist/mjs/predicate/isOptionalObject.js +3 -0
  22. package/dist/mjs/predicate/isUnknown.js +1 -0
  23. package/dist/types/predicate/index.d.ts +8 -0
  24. package/dist/types/predicate/isAny.d.ts +1 -0
  25. package/dist/types/predicate/isAnyObject.d.ts +1 -2
  26. package/dist/types/predicate/isArray.d.ts +1 -0
  27. package/dist/types/predicate/isAsyncIterable.d.ts +1 -1
  28. package/dist/types/predicate/isBinaryNumberString.d.ts +1 -0
  29. package/dist/types/predicate/isDigitsString.d.ts +1 -1
  30. package/dist/types/predicate/isHexNumberString.d.ts +1 -0
  31. package/dist/types/predicate/isIntString.d.ts +1 -1
  32. package/dist/types/predicate/isNumericString.d.ts +1 -1
  33. package/dist/types/predicate/isObject.d.ts +1 -2
  34. package/dist/types/predicate/isOctalNumberString.d.ts +1 -0
  35. package/dist/types/predicate/isOptionalArray.d.ts +1 -0
  36. package/dist/types/predicate/isOptionalObject.d.ts +1 -0
  37. package/dist/types/predicate/isUnknown.d.ts +1 -0
  38. package/dist/types/types/common.d.ts +1 -1
  39. package/dist/types/types/numbers.d.ts +6 -0
  40. package/dist/types/types/strings.d.ts +2 -1
  41. package/package.json +3 -3
@@ -5,7 +5,8 @@ const isAnyObject_js_1 = require("../isAnyObject.js");
5
5
  const literal_js_1 = require("./literal.js");
6
6
  const matching_js_1 = require("./matching.js");
7
7
  const shape = (objectShape) => {
8
- const entries = Object.entries(objectShape).map(([key, value]) => {
8
+ const entries = Reflect.ownKeys(objectShape).map((key) => {
9
+ const value = Reflect.get(objectShape, key);
9
10
  const predicate = typeof value === 'function'
10
11
  ? value
11
12
  : value instanceof RegExp
@@ -15,6 +16,6 @@ const shape = (objectShape) => {
15
16
  : (0, literal_js_1.literal)(value);
16
17
  return [key, predicate];
17
18
  });
18
- return (input) => (0, isAnyObject_js_1.isAnyObject)(input) && entries.every(([key, predicate]) => predicate(input[key]));
19
+ return (input) => (0, isAnyObject_js_1.isAnyObject)(input) && entries.every(([key, predicate]) => predicate(Reflect.get(input, key)));
19
20
  };
20
21
  exports.shape = shape;
@@ -14,17 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./isAny.js"), exports);
17
18
  __exportStar(require("./isAnyObject.js"), exports);
18
19
  __exportStar(require("./isAnyObjectWith.js"), exports);
19
20
  __exportStar(require("./isAnyObjectWithOwn.js"), exports);
21
+ __exportStar(require("./isArray.js"), exports);
20
22
  __exportStar(require("./isAsyncIterable.js"), exports);
21
23
  __exportStar(require("./isBigInt.js"), exports);
22
24
  __exportStar(require("./isBigIntArray.js"), exports);
25
+ __exportStar(require("./isBinaryNumberString.js"), exports);
23
26
  __exportStar(require("./isBoolean.js"), exports);
24
27
  __exportStar(require("./isBooleanArray.js"), exports);
25
28
  __exportStar(require("./isDigitsString.js"), exports);
26
29
  __exportStar(require("./isFiniteNumber.js"), exports);
27
30
  __exportStar(require("./isFunction.js"), exports);
31
+ __exportStar(require("./isHexNumberString.js"), exports);
28
32
  __exportStar(require("./isInt32.js"), exports);
29
33
  __exportStar(require("./isInteger.js"), exports);
30
34
  __exportStar(require("./isIntString.js"), exports);
@@ -41,11 +45,14 @@ __exportStar(require("./isNumericValue.js"), exports);
41
45
  __exportStar(require("./isNumericValueArray.js"), exports);
42
46
  __exportStar(require("./isObject.js"), exports);
43
47
  __exportStar(require("./isObjectWith.js"), exports);
48
+ __exportStar(require("./isOctalNumberString.js"), exports);
49
+ __exportStar(require("./isOptionalArray.js"), exports);
44
50
  __exportStar(require("./isOptionalBigInt.js"), exports);
45
51
  __exportStar(require("./isOptionalBoolean.js"), exports);
46
52
  __exportStar(require("./isOptionalISODateString.js"), exports);
47
53
  __exportStar(require("./isOptionalNull.js"), exports);
48
54
  __exportStar(require("./isOptionalNumber.js"), exports);
55
+ __exportStar(require("./isOptionalObject.js"), exports);
49
56
  __exportStar(require("./isOptionalString.js"), exports);
50
57
  __exportStar(require("./isOptionalSymbol.js"), exports);
51
58
  __exportStar(require("./isPositiveFiniteNumber.js"), exports);
@@ -64,3 +71,4 @@ __exportStar(require("./isSymbol.js"), exports);
64
71
  __exportStar(require("./isSymbolArray.js"), exports);
65
72
  __exportStar(require("./isUndefined.js"), exports);
66
73
  __exportStar(require("./isUndefinedArray.js"), exports);
74
+ __exportStar(require("./isUnknown.js"), exports);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAny = void 0;
4
+ const isAny = (_input) => true;
5
+ exports.isAny = isAny;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isArray = void 0;
4
+ const isArray = (input) => Array.isArray(input);
5
+ exports.isArray = isArray;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBinaryNumberString = void 0;
4
+ const matching_js_1 = require("./factory/matching.js");
5
+ exports.isBinaryNumberString = (0, matching_js_1.matching)(/^0b[01]+$/i);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHexNumberString = void 0;
4
+ const matching_js_1 = require("./factory/matching.js");
5
+ exports.isHexNumberString = (0, matching_js_1.matching)(/^0x[0-9a-f]+$/i);
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumericValue = void 0;
4
4
  const isNumericString_js_1 = require("./isNumericString.js");
5
- const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || (0, isNumericString_js_1.isNumericString)(input);
5
+ const isNumericValue = (input) => (typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'bigint' || (0, isNumericString_js_1.isNumericString)(input);
6
6
  exports.isNumericValue = isNumericValue;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOctalNumberString = void 0;
4
+ const matching_js_1 = require("./factory/matching.js");
5
+ exports.isOctalNumberString = (0, matching_js_1.matching)(/^0o[0-7]+$/i);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOptionalArray = void 0;
4
+ const optional_js_1 = require("./factory/optional.js");
5
+ const isArray_js_1 = require("./isArray.js");
6
+ exports.isOptionalArray = (0, optional_js_1.optional)(isArray_js_1.isArray);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOptionalObject = void 0;
4
+ const optional_js_1 = require("./factory/optional.js");
5
+ const isObject_js_1 = require("./isObject.js");
6
+ exports.isOptionalObject = (0, optional_js_1.optional)(isObject_js_1.isObject);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUnknown = void 0;
4
+ const isUnknown = (_input) => true;
5
+ exports.isUnknown = isUnknown;
@@ -2,7 +2,8 @@ import { isAnyObject } from '../isAnyObject.js';
2
2
  import { literal } from './literal.js';
3
3
  import { matching } from './matching.js';
4
4
  export const shape = (objectShape) => {
5
- const entries = Object.entries(objectShape).map(([key, value]) => {
5
+ const entries = Reflect.ownKeys(objectShape).map((key) => {
6
+ const value = Reflect.get(objectShape, key);
6
7
  const predicate = typeof value === 'function'
7
8
  ? value
8
9
  : value instanceof RegExp
@@ -12,5 +13,5 @@ export const shape = (objectShape) => {
12
13
  : literal(value);
13
14
  return [key, predicate];
14
15
  });
15
- return (input) => isAnyObject(input) && entries.every(([key, predicate]) => predicate(input[key]));
16
+ return (input) => isAnyObject(input) && entries.every(([key, predicate]) => predicate(Reflect.get(input, key)));
16
17
  };
@@ -1,14 +1,18 @@
1
+ export * from './isAny.js';
1
2
  export * from './isAnyObject.js';
2
3
  export * from './isAnyObjectWith.js';
3
4
  export * from './isAnyObjectWithOwn.js';
5
+ export * from './isArray.js';
4
6
  export * from './isAsyncIterable.js';
5
7
  export * from './isBigInt.js';
6
8
  export * from './isBigIntArray.js';
9
+ export * from './isBinaryNumberString.js';
7
10
  export * from './isBoolean.js';
8
11
  export * from './isBooleanArray.js';
9
12
  export * from './isDigitsString.js';
10
13
  export * from './isFiniteNumber.js';
11
14
  export * from './isFunction.js';
15
+ export * from './isHexNumberString.js';
12
16
  export * from './isInt32.js';
13
17
  export * from './isInteger.js';
14
18
  export * from './isIntString.js';
@@ -25,11 +29,14 @@ export * from './isNumericValue.js';
25
29
  export * from './isNumericValueArray.js';
26
30
  export * from './isObject.js';
27
31
  export * from './isObjectWith.js';
32
+ export * from './isOctalNumberString.js';
33
+ export * from './isOptionalArray.js';
28
34
  export * from './isOptionalBigInt.js';
29
35
  export * from './isOptionalBoolean.js';
30
36
  export * from './isOptionalISODateString.js';
31
37
  export * from './isOptionalNull.js';
32
38
  export * from './isOptionalNumber.js';
39
+ export * from './isOptionalObject.js';
33
40
  export * from './isOptionalString.js';
34
41
  export * from './isOptionalSymbol.js';
35
42
  export * from './isPositiveFiniteNumber.js';
@@ -48,3 +55,4 @@ export * from './isSymbol.js';
48
55
  export * from './isSymbolArray.js';
49
56
  export * from './isUndefined.js';
50
57
  export * from './isUndefinedArray.js';
58
+ export * from './isUnknown.js';
@@ -0,0 +1 @@
1
+ export const isAny = (_input) => true;
@@ -0,0 +1 @@
1
+ export const isArray = (input) => Array.isArray(input);
@@ -0,0 +1,2 @@
1
+ import { matching } from './factory/matching.js';
2
+ export const isBinaryNumberString = matching(/^0b[01]+$/i);
@@ -0,0 +1,2 @@
1
+ import { matching } from './factory/matching.js';
2
+ export const isHexNumberString = matching(/^0x[0-9a-f]+$/i);
@@ -1,2 +1,2 @@
1
1
  import { isNumericString } from './isNumericString.js';
2
- export const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || isNumericString(input);
2
+ export const isNumericValue = (input) => (typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'bigint' || isNumericString(input);
@@ -0,0 +1,2 @@
1
+ import { matching } from './factory/matching.js';
2
+ export const isOctalNumberString = matching(/^0o[0-7]+$/i);
@@ -0,0 +1,3 @@
1
+ import { optional } from './factory/optional.js';
2
+ import { isArray } from './isArray.js';
3
+ export const isOptionalArray = optional(isArray);
@@ -0,0 +1,3 @@
1
+ import { optional } from './factory/optional.js';
2
+ import { isObject } from './isObject.js';
3
+ export const isOptionalObject = optional(isObject);
@@ -0,0 +1 @@
1
+ export const isUnknown = (_input) => true;
@@ -1,14 +1,18 @@
1
+ export * from './isAny.js';
1
2
  export * from './isAnyObject.js';
2
3
  export * from './isAnyObjectWith.js';
3
4
  export * from './isAnyObjectWithOwn.js';
5
+ export * from './isArray.js';
4
6
  export * from './isAsyncIterable.js';
5
7
  export * from './isBigInt.js';
6
8
  export * from './isBigIntArray.js';
9
+ export * from './isBinaryNumberString.js';
7
10
  export * from './isBoolean.js';
8
11
  export * from './isBooleanArray.js';
9
12
  export * from './isDigitsString.js';
10
13
  export * from './isFiniteNumber.js';
11
14
  export * from './isFunction.js';
15
+ export * from './isHexNumberString.js';
12
16
  export * from './isInt32.js';
13
17
  export * from './isInteger.js';
14
18
  export * from './isIntString.js';
@@ -25,11 +29,14 @@ export * from './isNumericValue.js';
25
29
  export * from './isNumericValueArray.js';
26
30
  export * from './isObject.js';
27
31
  export * from './isObjectWith.js';
32
+ export * from './isOctalNumberString.js';
33
+ export * from './isOptionalArray.js';
28
34
  export * from './isOptionalBigInt.js';
29
35
  export * from './isOptionalBoolean.js';
30
36
  export * from './isOptionalISODateString.js';
31
37
  export * from './isOptionalNull.js';
32
38
  export * from './isOptionalNumber.js';
39
+ export * from './isOptionalObject.js';
33
40
  export * from './isOptionalString.js';
34
41
  export * from './isOptionalSymbol.js';
35
42
  export * from './isPositiveFiniteNumber.js';
@@ -48,3 +55,4 @@ export * from './isSymbol.js';
48
55
  export * from './isSymbolArray.js';
49
56
  export * from './isUndefined.js';
50
57
  export * from './isUndefinedArray.js';
58
+ export * from './isUnknown.js';
@@ -0,0 +1 @@
1
+ export declare const isAny: (_input: unknown) => _input is any;
@@ -1,2 +1 @@
1
- import type { UnknownRecord } from '../types/records.js';
2
- export declare const isAnyObject: <T>(input: T) => input is T & UnknownRecord;
1
+ export declare const isAnyObject: (input: unknown) => input is object;
@@ -0,0 +1 @@
1
+ export declare const isArray: (input: unknown) => input is unknown[];
@@ -1 +1 @@
1
- export declare const isAsyncIterable: <T>(input: unknown) => input is AsyncIterable<T>;
1
+ export declare const isAsyncIterable: (input: unknown) => input is AsyncIterable<unknown>;
@@ -0,0 +1 @@
1
+ export declare const isBinaryNumberString: import("../index.js").TypePredicateFn<`0b${number}` | `0B${number}`>;
@@ -1 +1 @@
1
- export declare const isDigitsString: import("../index.js").TypePredicateFn<`${number}`>;
1
+ export declare const isDigitsString: import("../index.js").TypePredicateFn<`${number}` | `${bigint}`>;
@@ -0,0 +1 @@
1
+ export declare const isHexNumberString: import("../index.js").TypePredicateFn<`0x${string}` | `0X${string}`>;
@@ -1 +1 @@
1
- export declare const isIntString: import("../index.js").TypePredicateFn<`${number}`>;
1
+ export declare const isIntString: import("../index.js").TypePredicateFn<`${number}` | `${bigint}`>;
@@ -1 +1 @@
1
- export declare const isNumericString: import("../index.js").TypePredicateFn<`${number}`>;
1
+ export declare const isNumericString: import("../index.js").TypePredicateFn<`${number}` | `${bigint}`>;
@@ -1,2 +1 @@
1
- import type { UnknownRecord } from '../types/records.js';
2
- export declare const isObject: <T>(input: T) => input is T & UnknownRecord;
1
+ export declare const isObject: (input: unknown) => input is object;
@@ -0,0 +1 @@
1
+ export declare const isOctalNumberString: import("../index.js").TypePredicateFn<`0o${number}` | `0O${number}`>;
@@ -0,0 +1 @@
1
+ export declare const isOptionalArray: import("../index.js").TypePredicateFn<unknown[] | undefined>;
@@ -0,0 +1 @@
1
+ export declare const isOptionalObject: import("../index.js").TypePredicateFn<object | undefined>;
@@ -0,0 +1 @@
1
+ export declare const isUnknown: (_input: unknown) => _input is unknown;
@@ -1,6 +1,6 @@
1
1
  import type { NotPromise } from './utils.js';
2
2
  export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
3
- export type NumericString<T extends string | number = number> = `${T}` extends `${number}` ? `${T}` : never;
3
+ export type NumericString<T extends string | number | bigint = number | bigint> = `${T}` extends `${number | bigint}` ? `${T}` : never;
4
4
  export type NumericValue = number | bigint | NumericString;
5
5
  export type JsonObject = {
6
6
  [key: string]: JsonValue;
@@ -1,3 +1,9 @@
1
1
  import type { Branded } from './branded.js';
2
+ export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
3
+ export type DecimalNumberString = `${'-' | '+' | ''}${Digit}${number}`;
4
+ export type HexNumberString = `0${'x' | 'X'}${string}`;
5
+ export type OctalNumberString = `0${'o' | 'O'}${number}`;
6
+ export type BinaryNumberString = `0${'b' | 'B'}${number}`;
7
+ export type ExponentiationString = `${number}${'e' | 'E'}${number}`;
2
8
  export type Int32 = Branded<number, 'Int32'>;
3
9
  export type NumberRange = [min: number] | [min: number, max: undefined] | [min: number, max: number] | [min: undefined, max: number];
@@ -1,7 +1,8 @@
1
+ import type { Digit } from './numbers.js';
1
2
  export type EmptyString = '';
2
3
  export type Space = ' ';
3
4
  export type AlphaCharacter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
4
- export type NumericCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
5
+ export type NumericCharacter = `${Digit}`;
5
6
  export type AlphanumericCharacter = AlphaCharacter | Capitalize<AlphaCharacter> | NumericCharacter;
6
7
  export type MaybePlural<T extends string> = T | `${T}s`;
7
8
  export type StripWhitespace<Type extends string> = string extends Type ? Type : Type extends `${infer First}${infer Rest}` ? First extends Space ? StripWhitespace<Rest> : `${First}${StripWhitespace<Rest>}` : EmptyString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "0.55.0",
4
+ "version": "0.56.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@10.6.4+sha512.da3d715bfd22a9a105e6e8088cfc7826699332ded60c423b14ec613a185f1602206702ff0fe4c438cb15c979081ce4cb02568e364b15174503a63c7a8e2a5f6c",
69
+ "packageManager": "pnpm@10.6.5+sha512.cdf928fca20832cd59ec53826492b7dc25dc524d4370b6b4adbf65803d32efaa6c1c88147c0ae4e8d579a6c9eec715757b50d4fa35eea179d868eada4ed043af",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
@@ -87,7 +87,7 @@
87
87
  "devDependencies": {
88
88
  "@commitlint/config-conventional": "^19.8.0",
89
89
  "@commitlint/types": "^19.8.0",
90
- "@types/node": "^22.13.10",
90
+ "@types/node": "^22.13.11",
91
91
  "@vitest/coverage-v8": "^3.0.9",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",