@webdeveric/utils 0.54.1 → 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.
- package/dist/cjs/predicate/factory/index.js +3 -2
- package/dist/cjs/predicate/factory/nonNullable.js +5 -0
- package/dist/cjs/predicate/factory/nullable.js +5 -0
- package/dist/cjs/predicate/factory/optional.js +5 -0
- package/dist/cjs/predicate/factory/withLength.js +4 -1
- package/dist/cjs/predicate/factory/withSize.js +4 -1
- package/dist/cjs/predicate/isOptionalBigInt.js +2 -2
- package/dist/cjs/predicate/isOptionalBoolean.js +2 -2
- package/dist/cjs/predicate/isOptionalISODateString.js +2 -2
- package/dist/cjs/predicate/isOptionalNull.js +2 -2
- package/dist/cjs/predicate/isOptionalNumber.js +2 -2
- package/dist/cjs/predicate/isOptionalString.js +2 -2
- package/dist/cjs/predicate/isOptionalSymbol.js +2 -2
- package/dist/mjs/predicate/factory/index.js +3 -2
- package/dist/mjs/predicate/factory/nonNullable.js +1 -0
- package/dist/mjs/predicate/factory/nullable.js +1 -0
- package/dist/mjs/predicate/factory/optional.js +1 -0
- package/dist/mjs/predicate/factory/withLength.js +4 -1
- package/dist/mjs/predicate/factory/withSize.js +4 -1
- package/dist/mjs/predicate/isOptionalBigInt.js +2 -2
- package/dist/mjs/predicate/isOptionalBoolean.js +2 -2
- package/dist/mjs/predicate/isOptionalISODateString.js +2 -2
- package/dist/mjs/predicate/isOptionalNull.js +2 -2
- package/dist/mjs/predicate/isOptionalNumber.js +2 -2
- package/dist/mjs/predicate/isOptionalString.js +2 -2
- package/dist/mjs/predicate/isOptionalSymbol.js +2 -2
- package/dist/types/predicate/factory/fromEnum.d.ts +2 -2
- package/dist/types/predicate/factory/index.d.ts +3 -2
- package/dist/types/predicate/factory/nonNullable.d.ts +2 -0
- package/dist/types/predicate/factory/nullable.d.ts +2 -0
- package/dist/types/predicate/factory/optional.d.ts +2 -0
- package/dist/types/types/records.d.ts +1 -0
- package/package.json +4 -4
- package/dist/cjs/predicate/factory/maybeNull.js +0 -5
- package/dist/cjs/predicate/factory/maybeUndefined.js +0 -5
- package/dist/mjs/predicate/factory/maybeNull.js +0 -1
- package/dist/mjs/predicate/factory/maybeUndefined.js +0 -1
- package/dist/types/predicate/factory/maybeNull.d.ts +0 -2
- 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("./
|
|
27
|
-
__exportStar(require("./
|
|
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);
|
|
@@ -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 =
|
|
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 =
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isBigInt_js_1 = require("./isBigInt.js");
|
|
6
|
-
exports.isOptionalBigInt = (0,
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isBoolean_js_1 = require("./isBoolean.js");
|
|
6
|
-
exports.isOptionalBoolean = (0,
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isISODateString_js_1 = require("./isISODateString.js");
|
|
6
|
-
exports.isOptionalISODateString = (0,
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isNull_js_1 = require("./isNull.js");
|
|
6
|
-
exports.isOptionalNull = (0,
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isNumber_js_1 = require("./isNumber.js");
|
|
6
|
-
exports.isOptionalNumber = (0,
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isString_js_1 = require("./isString.js");
|
|
6
|
-
exports.isOptionalString = (0,
|
|
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
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isSymbol_js_1 = require("./isSymbol.js");
|
|
6
|
-
exports.isOptionalSymbol = (0,
|
|
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 './
|
|
11
|
-
export * from './
|
|
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,6 +1,9 @@
|
|
|
1
1
|
export function withLength(fn, lengthRange) {
|
|
2
2
|
if (Array.isArray(lengthRange)) {
|
|
3
|
-
const [min =
|
|
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 =
|
|
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 {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isBigInt } from './isBigInt.js';
|
|
3
|
-
export const isOptionalBigInt =
|
|
3
|
+
export const isOptionalBigInt = optional(isBigInt);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isBoolean } from './isBoolean.js';
|
|
3
|
-
export const isOptionalBoolean =
|
|
3
|
+
export const isOptionalBoolean = optional(isBoolean);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isISODateString } from './isISODateString.js';
|
|
3
|
-
export const isOptionalISODateString =
|
|
3
|
+
export const isOptionalISODateString = optional(isISODateString);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isNull } from './isNull.js';
|
|
3
|
-
export const isOptionalNull =
|
|
3
|
+
export const isOptionalNull = optional(isNull);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isNumber } from './isNumber.js';
|
|
3
|
-
export const isOptionalNumber =
|
|
3
|
+
export const isOptionalNumber = optional(isNumber);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isString } from './isString.js';
|
|
3
|
-
export const isOptionalString =
|
|
3
|
+
export const isOptionalString = optional(isString);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isSymbol } from './isSymbol.js';
|
|
3
|
-
export const isOptionalSymbol =
|
|
3
|
+
export const isOptionalSymbol = optional(isSymbol);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const fromEnum: <T extends
|
|
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 './
|
|
11
|
-
export * from './
|
|
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';
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
110
|
+
"vitest": "^3.0.9"
|
|
111
111
|
},
|
|
112
112
|
"pnpm": {
|
|
113
113
|
"onlyBuiltDependencies": [
|
|
@@ -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);
|