@webdeveric/utils 0.75.0 → 0.77.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/assertIsSafeInteger.js +10 -0
- package/dist/cjs/assertion/index.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/numbers.js +7 -0
- package/dist/cjs/predicate/index.js +3 -0
- package/dist/cjs/predicate/isInt32.js +2 -3
- package/dist/cjs/predicate/isNullish.js +5 -0
- package/dist/cjs/predicate/isSafeInteger.js +5 -0
- package/dist/cjs/predicate/isUInt32.js +7 -0
- package/dist/cjs/randomInt.js +15 -11
- package/dist/cjs/sort/byRandom.js +2 -1
- package/dist/mjs/assertion/assertIsSafeInteger.js +7 -0
- package/dist/mjs/assertion/index.js +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/numbers.js +4 -0
- package/dist/mjs/predicate/index.js +3 -0
- package/dist/mjs/predicate/isInt32.js +1 -2
- package/dist/mjs/predicate/isNullish.js +1 -0
- package/dist/mjs/predicate/isSafeInteger.js +1 -0
- package/dist/mjs/predicate/isUInt32.js +4 -0
- package/dist/mjs/randomInt.js +15 -11
- package/dist/mjs/sort/byRandom.js +2 -1
- package/dist/types/assertion/assertIsSafeInteger.d.ts +1 -0
- package/dist/types/assertion/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/numbers.d.ts +4 -0
- package/dist/types/predicate/index.d.ts +3 -0
- package/dist/types/predicate/isNullish.d.ts +1 -0
- package/dist/types/predicate/isSafeInteger.d.ts +1 -0
- package/dist/types/predicate/isUInt32.d.ts +2 -0
- package/dist/types/types/numbers.d.ts +1 -0
- package/package.json +17 -23
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsSafeInteger = assertIsSafeInteger;
|
|
4
|
+
const isSafeInteger_js_1 = require("../predicate/isSafeInteger.js");
|
|
5
|
+
const getError_js_1 = require("./getError.js");
|
|
6
|
+
function assertIsSafeInteger(input, error = 'input is not a safe integer') {
|
|
7
|
+
if (!(0, isSafeInteger_js_1.isSafeInteger)(input)) {
|
|
8
|
+
throw (0, getError_js_1.getError)(error);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -49,6 +49,7 @@ __exportStar(require("./assertIsPrimitive.js"), exports);
|
|
|
49
49
|
__exportStar(require("./assertIsPromiseFulfilledResult.js"), exports);
|
|
50
50
|
__exportStar(require("./assertIsPromiseRejectedResult.js"), exports);
|
|
51
51
|
__exportStar(require("./assertIsPropertyKey.js"), exports);
|
|
52
|
+
__exportStar(require("./assertIsSafeInteger.js"), exports);
|
|
52
53
|
__exportStar(require("./assertIsSizeAware.js"), exports);
|
|
53
54
|
__exportStar(require("./assertIsString.js"), exports);
|
|
54
55
|
__exportStar(require("./assertIsStringArray.js"), exports);
|
package/dist/cjs/index.js
CHANGED
|
@@ -58,6 +58,7 @@ __exportStar(require("./joinStrings.js"), exports);
|
|
|
58
58
|
__exportStar(require("./jsonParse.js"), exports);
|
|
59
59
|
__exportStar(require("./looksLikeURL.js"), exports);
|
|
60
60
|
__exportStar(require("./normalize.js"), exports);
|
|
61
|
+
__exportStar(require("./numbers.js"), exports);
|
|
61
62
|
__exportStar(require("./parseNumber.js"), exports);
|
|
62
63
|
__exportStar(require("./pathParts.js"), exports);
|
|
63
64
|
__exportStar(require("./prefix.js"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uInt32Max = exports.uInt32Min = exports.int32Max = exports.int32Min = void 0;
|
|
4
|
+
exports.int32Min = -0x80000000;
|
|
5
|
+
exports.int32Max = 0x7fffffff;
|
|
6
|
+
exports.uInt32Min = 0;
|
|
7
|
+
exports.uInt32Max = 0xffffffff;
|
|
@@ -42,6 +42,7 @@ __exportStar(require("./isLengthAware.js"), exports);
|
|
|
42
42
|
__exportStar(require("./isNonNullable.js"), exports);
|
|
43
43
|
__exportStar(require("./isNull.js"), exports);
|
|
44
44
|
__exportStar(require("./isNullArray.js"), exports);
|
|
45
|
+
__exportStar(require("./isNullish.js"), exports);
|
|
45
46
|
__exportStar(require("./isNumber.js"), exports);
|
|
46
47
|
__exportStar(require("./isNumberArray.js"), exports);
|
|
47
48
|
__exportStar(require("./isNumericString.js"), exports);
|
|
@@ -67,6 +68,7 @@ __exportStar(require("./isPromiseFulfilledResult.js"), exports);
|
|
|
67
68
|
__exportStar(require("./isPromiseLike.js"), exports);
|
|
68
69
|
__exportStar(require("./isPromiseRejectedResult.js"), exports);
|
|
69
70
|
__exportStar(require("./isPropertyKey.js"), exports);
|
|
71
|
+
__exportStar(require("./isSafeInteger.js"), exports);
|
|
70
72
|
__exportStar(require("./isSizeAware.js"), exports);
|
|
71
73
|
__exportStar(require("./isString.js"), exports);
|
|
72
74
|
__exportStar(require("./isStringArray.js"), exports);
|
|
@@ -74,6 +76,7 @@ __exportStar(require("./isStringRecord.js"), exports);
|
|
|
74
76
|
__exportStar(require("./isStringWithLength.js"), exports);
|
|
75
77
|
__exportStar(require("./isSymbol.js"), exports);
|
|
76
78
|
__exportStar(require("./isSymbolArray.js"), exports);
|
|
79
|
+
__exportStar(require("./isUInt32.js"), exports);
|
|
77
80
|
__exportStar(require("./isUndefined.js"), exports);
|
|
78
81
|
__exportStar(require("./isUndefinedArray.js"), exports);
|
|
79
82
|
__exportStar(require("./isUnknown.js"), exports);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isInt32 = isInt32;
|
|
4
|
+
const numbers_js_1 = require("../numbers.js");
|
|
4
5
|
function isInt32(input) {
|
|
5
|
-
|
|
6
|
-
const int32Max = 2_147_483_647;
|
|
7
|
-
return typeof input === 'number' && Number.isInteger(input) && input >= int32Min && input <= int32Max;
|
|
6
|
+
return typeof input === 'number' && Number.isInteger(input) && input >= numbers_js_1.int32Min && input <= numbers_js_1.int32Max;
|
|
8
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUInt32 = isUInt32;
|
|
4
|
+
const numbers_js_1 = require("../numbers.js");
|
|
5
|
+
function isUInt32(input) {
|
|
6
|
+
return typeof input === 'number' && Number.isInteger(input) && input >= numbers_js_1.uInt32Min && input <= numbers_js_1.uInt32Max;
|
|
7
|
+
}
|
package/dist/cjs/randomInt.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.randomInt = randomInt;
|
|
4
|
-
const
|
|
4
|
+
const assertIsSafeInteger_js_1 = require("./assertion/assertIsSafeInteger.js");
|
|
5
5
|
const isObject_js_1 = require("./predicate/isObject.js");
|
|
6
6
|
function randomInt(arg1, arg2) {
|
|
7
|
-
const { min =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(0, assertIsInteger_js_1.assertIsInteger)(max, 'max must be an integer');
|
|
12
|
-
if (min === max) {
|
|
13
|
-
return min;
|
|
14
|
-
}
|
|
15
|
-
if (min > max) {
|
|
7
|
+
const { min = 0, max = Number.MAX_SAFE_INTEGER } = (0, isObject_js_1.isObject)(arg1) ? arg1 : { min: arg1, max: arg2 };
|
|
8
|
+
(0, assertIsSafeInteger_js_1.assertIsSafeInteger)(min, 'min must be a safe integer');
|
|
9
|
+
(0, assertIsSafeInteger_js_1.assertIsSafeInteger)(max, 'max must be a safe integer');
|
|
10
|
+
if (min >= max) {
|
|
16
11
|
throw new RangeError('min must be less than max');
|
|
17
12
|
}
|
|
18
|
-
|
|
13
|
+
const minBigInt = BigInt(min);
|
|
14
|
+
const range = BigInt(max) - minBigInt;
|
|
15
|
+
const limit = (2n ** 64n / range) * range;
|
|
16
|
+
const data = new BigInt64Array(1);
|
|
17
|
+
let value;
|
|
18
|
+
do {
|
|
19
|
+
crypto.getRandomValues(data);
|
|
20
|
+
value = BigInt.asUintN(64, data[0]);
|
|
21
|
+
} while (value >= limit);
|
|
22
|
+
return Number(minBigInt + (value % range));
|
|
19
23
|
}
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.byRandom = void 0;
|
|
4
4
|
const byRandom = () => {
|
|
5
5
|
let value;
|
|
6
|
+
const data = new Uint8Array(1);
|
|
6
7
|
do {
|
|
7
|
-
value = crypto.getRandomValues(
|
|
8
|
+
value = crypto.getRandomValues(data)[0];
|
|
8
9
|
} while (value >= 252);
|
|
9
10
|
return (value % 3) - 1;
|
|
10
11
|
};
|
|
@@ -33,6 +33,7 @@ export * from './assertIsPrimitive.js';
|
|
|
33
33
|
export * from './assertIsPromiseFulfilledResult.js';
|
|
34
34
|
export * from './assertIsPromiseRejectedResult.js';
|
|
35
35
|
export * from './assertIsPropertyKey.js';
|
|
36
|
+
export * from './assertIsSafeInteger.js';
|
|
36
37
|
export * from './assertIsSizeAware.js';
|
|
37
38
|
export * from './assertIsString.js';
|
|
38
39
|
export * from './assertIsStringArray.js';
|
package/dist/mjs/index.js
CHANGED
|
@@ -42,6 +42,7 @@ export * from './joinStrings.js';
|
|
|
42
42
|
export * from './jsonParse.js';
|
|
43
43
|
export * from './looksLikeURL.js';
|
|
44
44
|
export * from './normalize.js';
|
|
45
|
+
export * from './numbers.js';
|
|
45
46
|
export * from './parseNumber.js';
|
|
46
47
|
export * from './pathParts.js';
|
|
47
48
|
export * from './prefix.js';
|
|
@@ -26,6 +26,7 @@ export * from './isLengthAware.js';
|
|
|
26
26
|
export * from './isNonNullable.js';
|
|
27
27
|
export * from './isNull.js';
|
|
28
28
|
export * from './isNullArray.js';
|
|
29
|
+
export * from './isNullish.js';
|
|
29
30
|
export * from './isNumber.js';
|
|
30
31
|
export * from './isNumberArray.js';
|
|
31
32
|
export * from './isNumericString.js';
|
|
@@ -51,6 +52,7 @@ export * from './isPromiseFulfilledResult.js';
|
|
|
51
52
|
export * from './isPromiseLike.js';
|
|
52
53
|
export * from './isPromiseRejectedResult.js';
|
|
53
54
|
export * from './isPropertyKey.js';
|
|
55
|
+
export * from './isSafeInteger.js';
|
|
54
56
|
export * from './isSizeAware.js';
|
|
55
57
|
export * from './isString.js';
|
|
56
58
|
export * from './isStringArray.js';
|
|
@@ -58,6 +60,7 @@ export * from './isStringRecord.js';
|
|
|
58
60
|
export * from './isStringWithLength.js';
|
|
59
61
|
export * from './isSymbol.js';
|
|
60
62
|
export * from './isSymbolArray.js';
|
|
63
|
+
export * from './isUInt32.js';
|
|
61
64
|
export * from './isUndefined.js';
|
|
62
65
|
export * from './isUndefinedArray.js';
|
|
63
66
|
export * from './isUnknown.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isNullish = (input) => input == null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isSafeInteger = (input) => Number.isSafeInteger(input);
|
package/dist/mjs/randomInt.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertIsSafeInteger } from './assertion/assertIsSafeInteger.js';
|
|
2
2
|
import { isObject } from './predicate/isObject.js';
|
|
3
3
|
export function randomInt(arg1, arg2) {
|
|
4
|
-
const { min =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
assertIsInteger(max, 'max must be an integer');
|
|
9
|
-
if (min === max) {
|
|
10
|
-
return min;
|
|
11
|
-
}
|
|
12
|
-
if (min > max) {
|
|
4
|
+
const { min = 0, max = Number.MAX_SAFE_INTEGER } = isObject(arg1) ? arg1 : { min: arg1, max: arg2 };
|
|
5
|
+
assertIsSafeInteger(min, 'min must be a safe integer');
|
|
6
|
+
assertIsSafeInteger(max, 'max must be a safe integer');
|
|
7
|
+
if (min >= max) {
|
|
13
8
|
throw new RangeError('min must be less than max');
|
|
14
9
|
}
|
|
15
|
-
|
|
10
|
+
const minBigInt = BigInt(min);
|
|
11
|
+
const range = BigInt(max) - minBigInt;
|
|
12
|
+
const limit = (2n ** 64n / range) * range;
|
|
13
|
+
const data = new BigInt64Array(1);
|
|
14
|
+
let value;
|
|
15
|
+
do {
|
|
16
|
+
crypto.getRandomValues(data);
|
|
17
|
+
value = BigInt.asUintN(64, data[0]);
|
|
18
|
+
} while (value >= limit);
|
|
19
|
+
return Number(minBigInt + (value % range));
|
|
16
20
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertIsSafeInteger(input: unknown, error?: string | Error): asserts input is number;
|
|
@@ -33,6 +33,7 @@ export * from './assertIsPrimitive.js';
|
|
|
33
33
|
export * from './assertIsPromiseFulfilledResult.js';
|
|
34
34
|
export * from './assertIsPromiseRejectedResult.js';
|
|
35
35
|
export * from './assertIsPropertyKey.js';
|
|
36
|
+
export * from './assertIsSafeInteger.js';
|
|
36
37
|
export * from './assertIsSizeAware.js';
|
|
37
38
|
export * from './assertIsString.js';
|
|
38
39
|
export * from './assertIsStringArray.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export * from './joinStrings.js';
|
|
|
42
42
|
export * from './jsonParse.js';
|
|
43
43
|
export * from './looksLikeURL.js';
|
|
44
44
|
export * from './normalize.js';
|
|
45
|
+
export * from './numbers.js';
|
|
45
46
|
export * from './parseNumber.js';
|
|
46
47
|
export * from './pathParts.js';
|
|
47
48
|
export * from './prefix.js';
|
|
@@ -26,6 +26,7 @@ export * from './isLengthAware.js';
|
|
|
26
26
|
export * from './isNonNullable.js';
|
|
27
27
|
export * from './isNull.js';
|
|
28
28
|
export * from './isNullArray.js';
|
|
29
|
+
export * from './isNullish.js';
|
|
29
30
|
export * from './isNumber.js';
|
|
30
31
|
export * from './isNumberArray.js';
|
|
31
32
|
export * from './isNumericString.js';
|
|
@@ -51,6 +52,7 @@ export * from './isPromiseFulfilledResult.js';
|
|
|
51
52
|
export * from './isPromiseLike.js';
|
|
52
53
|
export * from './isPromiseRejectedResult.js';
|
|
53
54
|
export * from './isPropertyKey.js';
|
|
55
|
+
export * from './isSafeInteger.js';
|
|
54
56
|
export * from './isSizeAware.js';
|
|
55
57
|
export * from './isString.js';
|
|
56
58
|
export * from './isStringArray.js';
|
|
@@ -58,6 +60,7 @@ export * from './isStringRecord.js';
|
|
|
58
60
|
export * from './isStringWithLength.js';
|
|
59
61
|
export * from './isSymbol.js';
|
|
60
62
|
export * from './isSymbolArray.js';
|
|
63
|
+
export * from './isUInt32.js';
|
|
61
64
|
export * from './isUndefined.js';
|
|
62
65
|
export * from './isUndefinedArray.js';
|
|
63
66
|
export * from './isUnknown.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isNullish: (input: unknown) => input is null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isSafeInteger: (input: unknown) => input is number;
|
|
@@ -6,4 +6,5 @@ export type OctalNumberString = `0${'o' | 'O'}${number}`;
|
|
|
6
6
|
export type BinaryNumberString = `0${'b' | 'B'}${number}`;
|
|
7
7
|
export type ExponentiationString = `${number}${'e' | 'E'}${number}`;
|
|
8
8
|
export type Int32 = Branded<number, 'Int32'>;
|
|
9
|
+
export type UInt32 = Branded<number, 'UInt32'>;
|
|
9
10
|
export type NumberRange = [min: number] | [min: number, max: undefined] | [min: number, max: number] | [min: undefined, max: number];
|
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.77.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.
|
|
69
|
+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -85,34 +85,28 @@
|
|
|
85
85
|
},
|
|
86
86
|
"prettier": "@webdeveric/prettier-config",
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"@commitlint/config-conventional": "^20.
|
|
89
|
-
"@commitlint/types": "^20.
|
|
90
|
-
"@types/node": "^24.12.
|
|
91
|
-
"@vitest/coverage-v8": "^4.
|
|
88
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
89
|
+
"@commitlint/types": "^20.5.0",
|
|
90
|
+
"@types/node": "^24.12.2",
|
|
91
|
+
"@vitest/coverage-v8": "^4.1.4",
|
|
92
92
|
"@webdeveric/eslint-config-ts": "^0.12.0",
|
|
93
|
-
"@webdeveric/prettier-config": "^0.
|
|
94
|
-
"commitlint": "^20.
|
|
95
|
-
"commitlint-plugin-cspell": "^0.
|
|
96
|
-
"conventional-changelog-conventionalcommits": "^9.3.
|
|
97
|
-
"cspell": "^
|
|
93
|
+
"@webdeveric/prettier-config": "^0.4.0",
|
|
94
|
+
"commitlint": "^20.5.0",
|
|
95
|
+
"commitlint-plugin-cspell": "^0.8.0",
|
|
96
|
+
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
97
|
+
"cspell": "^10.0.0",
|
|
98
98
|
"eslint": "^8.57.1",
|
|
99
99
|
"eslint-config-prettier": "^10.1.8",
|
|
100
100
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
101
101
|
"eslint-plugin-import": "^2.32.0",
|
|
102
102
|
"husky": "^9.1.7",
|
|
103
|
-
"jsdom": "^
|
|
104
|
-
"lint-staged": "^16.
|
|
105
|
-
"prettier": "^3.8.
|
|
103
|
+
"jsdom": "^29.0.2",
|
|
104
|
+
"lint-staged": "^16.4.0",
|
|
105
|
+
"prettier": "^3.8.3",
|
|
106
106
|
"rimraf": "^6.1.3",
|
|
107
107
|
"semantic-release": "^25.0.3",
|
|
108
|
-
"typescript": "6.0.
|
|
109
|
-
"validate-package-exports": "^0.
|
|
110
|
-
"vitest": "^4.
|
|
111
|
-
},
|
|
112
|
-
"pnpm": {
|
|
113
|
-
"onlyBuiltDependencies": [
|
|
114
|
-
"esbuild",
|
|
115
|
-
"unrs-resolver"
|
|
116
|
-
]
|
|
108
|
+
"typescript": "^6.0.3",
|
|
109
|
+
"validate-package-exports": "^0.23.0",
|
|
110
|
+
"vitest": "^4.1.4"
|
|
117
111
|
}
|
|
118
112
|
}
|