@webdeveric/utils 0.54.0 → 0.55.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 (42) hide show
  1. package/dist/cjs/predicate/factory/index.js +3 -2
  2. package/dist/cjs/predicate/factory/nonNullable.js +5 -0
  3. package/dist/cjs/predicate/factory/nullable.js +5 -0
  4. package/dist/cjs/predicate/factory/optional.js +5 -0
  5. package/dist/cjs/predicate/factory/range.js +3 -4
  6. package/dist/cjs/predicate/factory/withLength.js +4 -1
  7. package/dist/cjs/predicate/factory/withSize.js +4 -1
  8. package/dist/cjs/predicate/isOptionalBigInt.js +2 -2
  9. package/dist/cjs/predicate/isOptionalBoolean.js +2 -2
  10. package/dist/cjs/predicate/isOptionalISODateString.js +2 -2
  11. package/dist/cjs/predicate/isOptionalNull.js +2 -2
  12. package/dist/cjs/predicate/isOptionalNumber.js +2 -2
  13. package/dist/cjs/predicate/isOptionalString.js +2 -2
  14. package/dist/cjs/predicate/isOptionalSymbol.js +2 -2
  15. package/dist/mjs/predicate/factory/index.js +3 -2
  16. package/dist/mjs/predicate/factory/nonNullable.js +1 -0
  17. package/dist/mjs/predicate/factory/nullable.js +1 -0
  18. package/dist/mjs/predicate/factory/optional.js +1 -0
  19. package/dist/mjs/predicate/factory/range.js +2 -2
  20. package/dist/mjs/predicate/factory/withLength.js +4 -1
  21. package/dist/mjs/predicate/factory/withSize.js +4 -1
  22. package/dist/mjs/predicate/isOptionalBigInt.js +2 -2
  23. package/dist/mjs/predicate/isOptionalBoolean.js +2 -2
  24. package/dist/mjs/predicate/isOptionalISODateString.js +2 -2
  25. package/dist/mjs/predicate/isOptionalNull.js +2 -2
  26. package/dist/mjs/predicate/isOptionalNumber.js +2 -2
  27. package/dist/mjs/predicate/isOptionalString.js +2 -2
  28. package/dist/mjs/predicate/isOptionalSymbol.js +2 -2
  29. package/dist/types/predicate/factory/fromEnum.d.ts +2 -2
  30. package/dist/types/predicate/factory/index.d.ts +3 -2
  31. package/dist/types/predicate/factory/nonNullable.d.ts +2 -0
  32. package/dist/types/predicate/factory/nullable.d.ts +2 -0
  33. package/dist/types/predicate/factory/optional.d.ts +2 -0
  34. package/dist/types/predicate/factory/range.d.ts +2 -1
  35. package/dist/types/types/records.d.ts +1 -0
  36. package/package.json +4 -4
  37. package/dist/cjs/predicate/factory/maybeNull.js +0 -5
  38. package/dist/cjs/predicate/factory/maybeUndefined.js +0 -5
  39. package/dist/mjs/predicate/factory/maybeNull.js +0 -1
  40. package/dist/mjs/predicate/factory/maybeUndefined.js +0 -1
  41. package/dist/types/predicate/factory/maybeNull.d.ts +0 -2
  42. package/dist/types/predicate/factory/maybeUndefined.d.ts +0 -2
@@ -23,8 +23,9 @@ __exportStar(require("./is.js"), exports);
23
23
  __exportStar(require("./literal.js"), exports);
24
24
  __exportStar(require("./matching.js"), exports);
25
25
  __exportStar(require("./maybeArray.js"), exports);
26
- __exportStar(require("./maybeNull.js"), exports);
27
- __exportStar(require("./maybeUndefined.js"), exports);
26
+ __exportStar(require("./nonNullable.js"), exports);
27
+ __exportStar(require("./nullable.js"), exports);
28
+ __exportStar(require("./optional.js"), exports);
28
29
  __exportStar(require("./range.js"), exports);
29
30
  __exportStar(require("./shape.js"), exports);
30
31
  __exportStar(require("./stringLength.js"), exports);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonNullable = void 0;
4
+ const nonNullable = (predicate) => (input) => input != null && predicate(input);
5
+ exports.nonNullable = nonNullable;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nullable = void 0;
4
+ const nullable = (predicate) => (input) => input === null || predicate(input);
5
+ exports.nullable = nullable;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optional = void 0;
4
+ const optional = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
5
+ exports.optional = optional;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.range = void 0;
4
- const range = (min, max) => {
3
+ exports.range = range;
4
+ function range(min, max) {
5
5
  if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
6
6
  throw new RangeError('min and max cannot be -Infinity and Infinity');
7
7
  }
@@ -12,5 +12,4 @@ const range = (min, max) => {
12
12
  throw new RangeError('min must be less than max');
13
13
  }
14
14
  return (input) => (typeof input === 'number' || typeof input === 'bigint') && input >= min && input <= max;
15
- };
16
- exports.range = range;
15
+ }
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withLength = withLength;
4
4
  function withLength(fn, lengthRange) {
5
5
  if (Array.isArray(lengthRange)) {
6
- const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = lengthRange;
6
+ const [min = 0, max = Number.POSITIVE_INFINITY] = lengthRange;
7
+ if (min < 0) {
8
+ throw new RangeError('min must be greater than or equal to 0');
9
+ }
7
10
  if (min > max) {
8
11
  throw new RangeError('min cannot be greater than max');
9
12
  }
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withSize = withSize;
4
4
  function withSize(fn, sizeRange) {
5
5
  if (Array.isArray(sizeRange)) {
6
- const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = sizeRange;
6
+ const [min = 0, max = Number.POSITIVE_INFINITY] = sizeRange;
7
+ if (min < 0) {
8
+ throw new RangeError('min must be greater than or equal to 0');
9
+ }
7
10
  if (min > max) {
8
11
  throw new RangeError('min cannot be greater than max');
9
12
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalBigInt = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isBigInt_js_1 = require("./isBigInt.js");
6
- exports.isOptionalBigInt = (0, maybeUndefined_js_1.maybeUndefined)(isBigInt_js_1.isBigInt);
6
+ exports.isOptionalBigInt = (0, optional_js_1.optional)(isBigInt_js_1.isBigInt);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalBoolean = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isBoolean_js_1 = require("./isBoolean.js");
6
- exports.isOptionalBoolean = (0, maybeUndefined_js_1.maybeUndefined)(isBoolean_js_1.isBoolean);
6
+ exports.isOptionalBoolean = (0, optional_js_1.optional)(isBoolean_js_1.isBoolean);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalISODateString = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isISODateString_js_1 = require("./isISODateString.js");
6
- exports.isOptionalISODateString = (0, maybeUndefined_js_1.maybeUndefined)(isISODateString_js_1.isISODateString);
6
+ exports.isOptionalISODateString = (0, optional_js_1.optional)(isISODateString_js_1.isISODateString);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalNull = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isNull_js_1 = require("./isNull.js");
6
- exports.isOptionalNull = (0, maybeUndefined_js_1.maybeUndefined)(isNull_js_1.isNull);
6
+ exports.isOptionalNull = (0, optional_js_1.optional)(isNull_js_1.isNull);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalNumber = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isNumber_js_1 = require("./isNumber.js");
6
- exports.isOptionalNumber = (0, maybeUndefined_js_1.maybeUndefined)(isNumber_js_1.isNumber);
6
+ exports.isOptionalNumber = (0, optional_js_1.optional)(isNumber_js_1.isNumber);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalString = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isString_js_1 = require("./isString.js");
6
- exports.isOptionalString = (0, maybeUndefined_js_1.maybeUndefined)(isString_js_1.isString);
6
+ exports.isOptionalString = (0, optional_js_1.optional)(isString_js_1.isString);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isOptionalSymbol = void 0;
4
- const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
4
+ const optional_js_1 = require("./factory/optional.js");
5
5
  const isSymbol_js_1 = require("./isSymbol.js");
6
- exports.isOptionalSymbol = (0, maybeUndefined_js_1.maybeUndefined)(isSymbol_js_1.isSymbol);
6
+ exports.isOptionalSymbol = (0, optional_js_1.optional)(isSymbol_js_1.isSymbol);
@@ -7,8 +7,9 @@ export * from './is.js';
7
7
  export * from './literal.js';
8
8
  export * from './matching.js';
9
9
  export * from './maybeArray.js';
10
- export * from './maybeNull.js';
11
- export * from './maybeUndefined.js';
10
+ export * from './nonNullable.js';
11
+ export * from './nullable.js';
12
+ export * from './optional.js';
12
13
  export * from './range.js';
13
14
  export * from './shape.js';
14
15
  export * from './stringLength.js';
@@ -0,0 +1 @@
1
+ export const nonNullable = (predicate) => (input) => input != null && predicate(input);
@@ -0,0 +1 @@
1
+ export const nullable = (predicate) => (input) => input === null || predicate(input);
@@ -0,0 +1 @@
1
+ export const optional = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
@@ -1,4 +1,4 @@
1
- export const range = (min, max) => {
1
+ export function range(min, max) {
2
2
  if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
3
3
  throw new RangeError('min and max cannot be -Infinity and Infinity');
4
4
  }
@@ -9,4 +9,4 @@ export const range = (min, max) => {
9
9
  throw new RangeError('min must be less than max');
10
10
  }
11
11
  return (input) => (typeof input === 'number' || typeof input === 'bigint') && input >= min && input <= max;
12
- };
12
+ }
@@ -1,6 +1,9 @@
1
1
  export function withLength(fn, lengthRange) {
2
2
  if (Array.isArray(lengthRange)) {
3
- const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = lengthRange;
3
+ const [min = 0, max = Number.POSITIVE_INFINITY] = lengthRange;
4
+ if (min < 0) {
5
+ throw new RangeError('min must be greater than or equal to 0');
6
+ }
4
7
  if (min > max) {
5
8
  throw new RangeError('min cannot be greater than max');
6
9
  }
@@ -1,6 +1,9 @@
1
1
  export function withSize(fn, sizeRange) {
2
2
  if (Array.isArray(sizeRange)) {
3
- const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = sizeRange;
3
+ const [min = 0, max = Number.POSITIVE_INFINITY] = sizeRange;
4
+ if (min < 0) {
5
+ throw new RangeError('min must be greater than or equal to 0');
6
+ }
4
7
  if (min > max) {
5
8
  throw new RangeError('min cannot be greater than max');
6
9
  }
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isBigInt } from './isBigInt.js';
3
- export const isOptionalBigInt = maybeUndefined(isBigInt);
3
+ export const isOptionalBigInt = optional(isBigInt);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isBoolean } from './isBoolean.js';
3
- export const isOptionalBoolean = maybeUndefined(isBoolean);
3
+ export const isOptionalBoolean = optional(isBoolean);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isISODateString } from './isISODateString.js';
3
- export const isOptionalISODateString = maybeUndefined(isISODateString);
3
+ export const isOptionalISODateString = optional(isISODateString);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isNull } from './isNull.js';
3
- export const isOptionalNull = maybeUndefined(isNull);
3
+ export const isOptionalNull = optional(isNull);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isNumber } from './isNumber.js';
3
- export const isOptionalNumber = maybeUndefined(isNumber);
3
+ export const isOptionalNumber = optional(isNumber);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isString } from './isString.js';
3
- export const isOptionalString = maybeUndefined(isString);
3
+ export const isOptionalString = optional(isString);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from './factory/maybeUndefined.js';
1
+ import { optional } from './factory/optional.js';
2
2
  import { isSymbol } from './isSymbol.js';
3
- export const isOptionalSymbol = maybeUndefined(isSymbol);
3
+ export const isOptionalSymbol = optional(isSymbol);
@@ -1,3 +1,3 @@
1
1
  import type { TypePredicateFn } from '../../types/functions.js';
2
- import type { UnknownRecord } from '../../types/records.js';
3
- export declare const fromEnum: <T extends UnknownRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
2
+ import type { EnumRecord } from '../../types/records.js';
3
+ export declare const fromEnum: <T extends EnumRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
@@ -7,8 +7,9 @@ export * from './is.js';
7
7
  export * from './literal.js';
8
8
  export * from './matching.js';
9
9
  export * from './maybeArray.js';
10
- export * from './maybeNull.js';
11
- export * from './maybeUndefined.js';
10
+ export * from './nonNullable.js';
11
+ export * from './nullable.js';
12
+ export * from './optional.js';
12
13
  export * from './range.js';
13
14
  export * from './shape.js';
14
15
  export * from './stringLength.js';
@@ -0,0 +1,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const nonNullable: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<NonNullable<T>>;
@@ -0,0 +1,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const nullable: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | null>;
@@ -0,0 +1,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const optional: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | undefined>;
@@ -1,2 +1,3 @@
1
1
  import type { TypePredicateFn } from '../../types/functions.js';
2
- export declare const range: <Type extends number | bigint>(min: Type, max: Type) => TypePredicateFn<Type>;
2
+ export declare function range(min: number, max: number): TypePredicateFn<number>;
3
+ export declare function range(min: bigint, max: bigint): TypePredicateFn<bigint>;
@@ -2,6 +2,7 @@ export type AnyRecord = Record<PropertyKey, any>;
2
2
  export type UnknownRecord = Record<PropertyKey, unknown>;
3
3
  export type NeverRecord = Record<PropertyKey, never>;
4
4
  export type StringRecord = Record<string, string>;
5
+ export type EnumRecord = Record<string, string | number>;
5
6
  export type RemoveIndex<Type> = {
6
7
  [Key in keyof Type as symbol extends Key ? never : string extends Key ? never : number extends Key ? never : Key]: Type[Key];
7
8
  };
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.54.0",
4
+ "version": "0.55.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.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6",
69
+ "packageManager": "pnpm@10.6.4+sha512.da3d715bfd22a9a105e6e8088cfc7826699332ded60c423b14ec613a185f1602206702ff0fe4c438cb15c979081ce4cb02568e364b15174503a63c7a8e2a5f6c",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
@@ -88,7 +88,7 @@
88
88
  "@commitlint/config-conventional": "^19.8.0",
89
89
  "@commitlint/types": "^19.8.0",
90
90
  "@types/node": "^22.13.10",
91
- "@vitest/coverage-v8": "^3.0.8",
91
+ "@vitest/coverage-v8": "^3.0.9",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
94
  "commitlint": "^19.8.0",
@@ -107,7 +107,7 @@
107
107
  "semantic-release": "^24.2.3",
108
108
  "typescript": "^5.8.2",
109
109
  "validate-package-exports": "^0.8.0",
110
- "vitest": "^3.0.8"
110
+ "vitest": "^3.0.9"
111
111
  },
112
112
  "pnpm": {
113
113
  "onlyBuiltDependencies": [
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maybeNull = void 0;
4
- const maybeNull = (predicate) => (input) => input === null || predicate(input);
5
- exports.maybeNull = maybeNull;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maybeUndefined = void 0;
4
- const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
5
- exports.maybeUndefined = maybeUndefined;
@@ -1 +0,0 @@
1
- export const maybeNull = (predicate) => (input) => input === null || predicate(input);
@@ -1 +0,0 @@
1
- export const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
@@ -1,2 +0,0 @@
1
- import type { TypePredicateFn } from '../../types/functions.js';
2
- export declare const maybeNull: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | null>;
@@ -1,2 +0,0 @@
1
- import type { TypePredicateFn } from '../../types/functions.js';
2
- export declare const maybeUndefined: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | undefined>;