@webdeveric/utils 0.45.1 → 0.47.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/assertion/assertIsInt32.js +10 -0
- package/dist/cjs/assertion/index.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/jsonParse.js +8 -0
- package/dist/cjs/predicate/index.js +2 -0
- package/dist/cjs/predicate/isAnyObjectWithOwn.js +9 -0
- package/dist/cjs/predicate/isInt32.js +8 -0
- package/dist/cjs/predicate-factory/createStringLengthRangePredicate.js +10 -0
- package/dist/cjs/predicate-factory/index.js +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/numbers.js +2 -0
- package/dist/mjs/assertion/assertIsInt32.js +7 -0
- package/dist/mjs/assertion/index.js +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/jsonParse.js +5 -0
- package/dist/mjs/predicate/index.js +2 -0
- package/dist/mjs/predicate/isAnyObjectWithOwn.js +5 -0
- package/dist/mjs/predicate/isInt32.js +5 -0
- package/dist/mjs/predicate-factory/createStringLengthRangePredicate.js +6 -0
- package/dist/mjs/predicate-factory/index.js +1 -0
- package/dist/mjs/types/index.js +1 -0
- package/dist/mjs/types/numbers.js +1 -0
- package/dist/types/assertion/assertIsInt32.d.ts +2 -0
- package/dist/types/assertion/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/jsonParse.d.ts +5 -0
- package/dist/types/predicate/index.d.ts +2 -0
- package/dist/types/predicate/isAnyObjectWithOwn.d.ts +1 -0
- package/dist/types/predicate/isInt32.d.ts +2 -0
- package/dist/types/predicate/isNonNullable.d.ts +1 -1
- package/dist/types/predicate-factory/createStringLengthRangePredicate.d.ts +2 -0
- package/dist/types/predicate-factory/index.d.ts +1 -0
- package/dist/types/types/branded.d.ts +6 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/numbers.d.ts +2 -0
- package/dist/types/types/utils.d.ts +4 -3
- package/package.json +9 -9
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsInt32 = assertIsInt32;
|
|
4
|
+
const isInt32_js_1 = require("../predicate/isInt32.js");
|
|
5
|
+
const getError_js_1 = require("./getError.js");
|
|
6
|
+
function assertIsInt32(input, error = 'input is not an Int32') {
|
|
7
|
+
if (!(0, isInt32_js_1.isInt32)(input)) {
|
|
8
|
+
throw (0, getError_js_1.getError)(error);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -23,6 +23,7 @@ __exportStar(require("./assertIsBooleanArray.js"), exports);
|
|
|
23
23
|
__exportStar(require("./assertIsDigitsString.js"), exports);
|
|
24
24
|
__exportStar(require("./assertIsFiniteNumber.js"), exports);
|
|
25
25
|
__exportStar(require("./assertIsFunction.js"), exports);
|
|
26
|
+
__exportStar(require("./assertIsInt32.js"), exports);
|
|
26
27
|
__exportStar(require("./assertIsInteger.js"), exports);
|
|
27
28
|
__exportStar(require("./assertIsIntString.js"), exports);
|
|
28
29
|
__exportStar(require("./assertIsIterable.js"), exports);
|
package/dist/cjs/index.js
CHANGED
|
@@ -49,6 +49,7 @@ __exportStar(require("./inRange.js"), exports);
|
|
|
49
49
|
__exportStar(require("./isEmpty.js"), exports);
|
|
50
50
|
__exportStar(require("./iterateForever.js"), exports);
|
|
51
51
|
__exportStar(require("./joinStrings.js"), exports);
|
|
52
|
+
__exportStar(require("./jsonParse.js"), exports);
|
|
52
53
|
__exportStar(require("./looksLikeURL.js"), exports);
|
|
53
54
|
__exportStar(require("./normalize.js"), exports);
|
|
54
55
|
__exportStar(require("./parseNumber.js"), exports);
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./isAnyObject.js"), exports);
|
|
18
18
|
__exportStar(require("./isAnyObjectWith.js"), exports);
|
|
19
|
+
__exportStar(require("./isAnyObjectWithOwn.js"), exports);
|
|
19
20
|
__exportStar(require("./isAsyncIterable.js"), exports);
|
|
20
21
|
__exportStar(require("./isBigInt.js"), exports);
|
|
21
22
|
__exportStar(require("./isBigIntArray.js"), exports);
|
|
@@ -24,6 +25,7 @@ __exportStar(require("./isBooleanArray.js"), exports);
|
|
|
24
25
|
__exportStar(require("./isDigitsString.js"), exports);
|
|
25
26
|
__exportStar(require("./isFiniteNumber.js"), exports);
|
|
26
27
|
__exportStar(require("./isFunction.js"), exports);
|
|
28
|
+
__exportStar(require("./isInt32.js"), exports);
|
|
27
29
|
__exportStar(require("./isInteger.js"), exports);
|
|
28
30
|
__exportStar(require("./isIntString.js"), exports);
|
|
29
31
|
__exportStar(require("./isISODateString.js"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAnyObjectWithOwn = void 0;
|
|
4
|
+
const asArray_js_1 = require("../asArray.js");
|
|
5
|
+
const isAnyObject_js_1 = require("./isAnyObject.js");
|
|
6
|
+
const isAnyObjectWithOwn = (input, properties) => {
|
|
7
|
+
return (0, isAnyObject_js_1.isAnyObject)(input) && (0, asArray_js_1.asArray)(properties).every((property) => Object.hasOwn(input, property));
|
|
8
|
+
};
|
|
9
|
+
exports.isAnyObjectWithOwn = isAnyObjectWithOwn;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInt32 = isInt32;
|
|
4
|
+
function isInt32(input) {
|
|
5
|
+
const int32Min = -2_147_483_648;
|
|
6
|
+
const int32Max = 2_147_483_647;
|
|
7
|
+
return typeof input === 'number' && Number.isInteger(input) && input >= int32Min && input <= int32Max;
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStringLengthRangePredicate = void 0;
|
|
4
|
+
const createStringLengthRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
|
|
5
|
+
if (min < 0) {
|
|
6
|
+
throw new RangeError('min must be >= 0');
|
|
7
|
+
}
|
|
8
|
+
return (input) => typeof input === 'string' && input.length >= min && input.length <= max;
|
|
9
|
+
};
|
|
10
|
+
exports.createStringLengthRangePredicate = createStringLengthRangePredicate;
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./anyOf.js"), exports);
|
|
|
19
19
|
__exportStar(require("./createIsEnumPredicate.js"), exports);
|
|
20
20
|
__exportStar(require("./createIsInstanceOfPredicate.js"), exports);
|
|
21
21
|
__exportStar(require("./createIsTuplePredicate.js"), exports);
|
|
22
|
+
__exportStar(require("./createStringLengthRangePredicate.js"), exports);
|
|
22
23
|
__exportStar(require("./createStringMatchingPredicate.js"), exports);
|
|
23
24
|
__exportStar(require("./everyItem.js"), exports);
|
|
24
25
|
__exportStar(require("./maybeArray.js"), exports);
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./branded.js"), exports);
|
|
|
19
19
|
__exportStar(require("./common.js"), exports);
|
|
20
20
|
__exportStar(require("./date-time.js"), exports);
|
|
21
21
|
__exportStar(require("./functions.js"), exports);
|
|
22
|
+
__exportStar(require("./numbers.js"), exports);
|
|
22
23
|
__exportStar(require("./objects.js"), exports);
|
|
23
24
|
__exportStar(require("./records.js"), exports);
|
|
24
25
|
__exportStar(require("./strings.js"), exports);
|
|
@@ -7,6 +7,7 @@ export * from './assertIsBooleanArray.js';
|
|
|
7
7
|
export * from './assertIsDigitsString.js';
|
|
8
8
|
export * from './assertIsFiniteNumber.js';
|
|
9
9
|
export * from './assertIsFunction.js';
|
|
10
|
+
export * from './assertIsInt32.js';
|
|
10
11
|
export * from './assertIsInteger.js';
|
|
11
12
|
export * from './assertIsIntString.js';
|
|
12
13
|
export * from './assertIsIterable.js';
|
package/dist/mjs/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export * from './inRange.js';
|
|
|
33
33
|
export * from './isEmpty.js';
|
|
34
34
|
export * from './iterateForever.js';
|
|
35
35
|
export * from './joinStrings.js';
|
|
36
|
+
export * from './jsonParse.js';
|
|
36
37
|
export * from './looksLikeURL.js';
|
|
37
38
|
export * from './normalize.js';
|
|
38
39
|
export * from './parseNumber.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './isAnyObject.js';
|
|
2
2
|
export * from './isAnyObjectWith.js';
|
|
3
|
+
export * from './isAnyObjectWithOwn.js';
|
|
3
4
|
export * from './isAsyncIterable.js';
|
|
4
5
|
export * from './isBigInt.js';
|
|
5
6
|
export * from './isBigIntArray.js';
|
|
@@ -8,6 +9,7 @@ export * from './isBooleanArray.js';
|
|
|
8
9
|
export * from './isDigitsString.js';
|
|
9
10
|
export * from './isFiniteNumber.js';
|
|
10
11
|
export * from './isFunction.js';
|
|
12
|
+
export * from './isInt32.js';
|
|
11
13
|
export * from './isInteger.js';
|
|
12
14
|
export * from './isIntString.js';
|
|
13
15
|
export * from './isISODateString.js';
|
|
@@ -3,6 +3,7 @@ export * from './anyOf.js';
|
|
|
3
3
|
export * from './createIsEnumPredicate.js';
|
|
4
4
|
export * from './createIsInstanceOfPredicate.js';
|
|
5
5
|
export * from './createIsTuplePredicate.js';
|
|
6
|
+
export * from './createStringLengthRangePredicate.js';
|
|
6
7
|
export * from './createStringMatchingPredicate.js';
|
|
7
8
|
export * from './everyItem.js';
|
|
8
9
|
export * from './maybeArray.js';
|
package/dist/mjs/types/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,6 +7,7 @@ export * from './assertIsBooleanArray.js';
|
|
|
7
7
|
export * from './assertIsDigitsString.js';
|
|
8
8
|
export * from './assertIsFiniteNumber.js';
|
|
9
9
|
export * from './assertIsFunction.js';
|
|
10
|
+
export * from './assertIsInt32.js';
|
|
10
11
|
export * from './assertIsInteger.js';
|
|
11
12
|
export * from './assertIsIntString.js';
|
|
12
13
|
export * from './assertIsIterable.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export * from './inRange.js';
|
|
|
33
33
|
export * from './isEmpty.js';
|
|
34
34
|
export * from './iterateForever.js';
|
|
35
35
|
export * from './joinStrings.js';
|
|
36
|
+
export * from './jsonParse.js';
|
|
36
37
|
export * from './looksLikeURL.js';
|
|
37
38
|
export * from './normalize.js';
|
|
38
39
|
export * from './parseNumber.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TypeAssertionFn } from './types/functions.js';
|
|
2
|
+
export type JsonReviver = Parameters<JSON['parse']>[1];
|
|
3
|
+
export declare function jsonParse(input: string): unknown;
|
|
4
|
+
export declare function jsonParse(input: string, reviver?: JsonReviver): unknown;
|
|
5
|
+
export declare function jsonParse<T>(input: string, reviver: JsonReviver | undefined, assertionFn: TypeAssertionFn<T>): T;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './isAnyObject.js';
|
|
2
2
|
export * from './isAnyObjectWith.js';
|
|
3
|
+
export * from './isAnyObjectWithOwn.js';
|
|
3
4
|
export * from './isAsyncIterable.js';
|
|
4
5
|
export * from './isBigInt.js';
|
|
5
6
|
export * from './isBigIntArray.js';
|
|
@@ -8,6 +9,7 @@ export * from './isBooleanArray.js';
|
|
|
8
9
|
export * from './isDigitsString.js';
|
|
9
10
|
export * from './isFiniteNumber.js';
|
|
10
11
|
export * from './isFunction.js';
|
|
12
|
+
export * from './isInt32.js';
|
|
11
13
|
export * from './isInteger.js';
|
|
12
14
|
export * from './isIntString.js';
|
|
13
15
|
export * from './isISODateString.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isAnyObjectWithOwn: <T, P extends PropertyKey>(input: T, properties: P | P[]) => input is T & Record<P, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isNonNullable: <T>(input:
|
|
1
|
+
export declare const isNonNullable: <T>(input: T) => input is NonNullable<T>;
|
|
@@ -3,6 +3,7 @@ export * from './anyOf.js';
|
|
|
3
3
|
export * from './createIsEnumPredicate.js';
|
|
4
4
|
export * from './createIsInstanceOfPredicate.js';
|
|
5
5
|
export * from './createIsTuplePredicate.js';
|
|
6
|
+
export * from './createStringLengthRangePredicate.js';
|
|
6
7
|
export * from './createStringMatchingPredicate.js';
|
|
7
8
|
export * from './everyItem.js';
|
|
8
9
|
export * from './maybeArray.js';
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import type { Primitive } from './common.js';
|
|
1
2
|
declare const brand: unique symbol;
|
|
2
|
-
type Brand<Id> = {
|
|
3
|
+
export type Brand<Id> = {
|
|
3
4
|
[brand]: Id;
|
|
4
5
|
};
|
|
5
6
|
export type Branded<Type, Id> = Type & Brand<Id>;
|
|
7
|
+
export type Unbranded<Type> = Type extends Branded<infer Inner, unknown> ? Omit<Inner, typeof brand> : Type;
|
|
8
|
+
export type RemoveBranding<Type> = Type extends Primitive ? Unbranded<Type> : {
|
|
9
|
+
[Property in keyof Type]: Type extends Primitive ? Unbranded<Type[Property]> : RemoveBranding<Type[Property]>;
|
|
10
|
+
};
|
|
6
11
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export type IfNever<Type, T, F> = [Type] extends [never] ? T : F;
|
|
1
2
|
export type IfCommonKeys<Target, Source, T, F> = IfNever<keyof (Target | Source), F, T>;
|
|
2
|
-
export type IfDefined<Type,
|
|
3
|
+
export type IfDefined<Type, T, F> = undefined extends Type ? F : T;
|
|
4
|
+
export type IfUnknown<Type, T, F> = unknown extends Type ? T : F;
|
|
3
5
|
export type IfPromise<Type, T, F> = Type extends Promise<any> ? T : F;
|
|
4
|
-
export type NotPromise<
|
|
5
|
-
export type IfNever<Type, N, O> = [Type] extends [never] ? N : O;
|
|
6
|
+
export type NotPromise<Type> = Type extends Promise<any> ? never : Type;
|
|
6
7
|
export type CanBeUndefined<Type, T, F> = Type | undefined extends Type ? T : F;
|
|
7
8
|
export type ReturnTypeDefault<Func, Default = undefined> = Func extends (...args: any[]) => infer R ? R : Default;
|
|
8
9
|
export type DeepNonNullable<Type> = Type extends Record<PropertyKey, unknown> ? {
|
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.47.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@
|
|
69
|
+
"packageManager": "pnpm@10.2.0+sha512.0d27364e0139c6aadeed65ada153135e0ca96c8da42123bd50047f961339dc7a758fc2e944b428f52be570d1bd3372455c1c65fa2e7aa0bfbf931190f9552001",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -85,28 +85,28 @@
|
|
|
85
85
|
},
|
|
86
86
|
"prettier": "@webdeveric/prettier-config",
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"@commitlint/config-conventional": "^19.
|
|
88
|
+
"@commitlint/config-conventional": "^19.7.1",
|
|
89
89
|
"@commitlint/types": "^19.5.0",
|
|
90
|
-
"@types/node": "^22.
|
|
91
|
-
"@vitest/coverage-v8": "^3.0.
|
|
90
|
+
"@types/node": "^22.13.1",
|
|
91
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
92
92
|
"@webdeveric/eslint-config-ts": "^0.11.0",
|
|
93
93
|
"@webdeveric/prettier-config": "^0.3.0",
|
|
94
|
-
"commitlint": "^19.
|
|
94
|
+
"commitlint": "^19.7.1",
|
|
95
95
|
"commitlint-plugin-cspell": "^0.1.1",
|
|
96
96
|
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
97
|
-
"cspell": "^8.17.
|
|
97
|
+
"cspell": "^8.17.3",
|
|
98
98
|
"eslint": "^8.57.1",
|
|
99
99
|
"eslint-config-prettier": "^10.0.1",
|
|
100
100
|
"eslint-import-resolver-typescript": "^3.7.0",
|
|
101
101
|
"eslint-plugin-import": "^2.31.0",
|
|
102
102
|
"husky": "^9.1.7",
|
|
103
103
|
"jsdom": "^26.0.0",
|
|
104
|
-
"lint-staged": "^15.4.
|
|
104
|
+
"lint-staged": "^15.4.3",
|
|
105
105
|
"prettier": "^3.4.2",
|
|
106
106
|
"rimraf": "^6.0.1",
|
|
107
107
|
"semantic-release": "^24.2.1",
|
|
108
108
|
"typescript": "^5.7.3",
|
|
109
109
|
"validate-package-exports": "^0.8.0",
|
|
110
|
-
"vitest": "^3.0.
|
|
110
|
+
"vitest": "^3.0.5"
|
|
111
111
|
}
|
|
112
112
|
}
|