@webdeveric/utils 0.59.1 → 0.61.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/counter.js +1 -0
- package/dist/cjs/getRandomItem.js +14 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/randomInt.js +19 -0
- package/dist/mjs/counter.js +1 -0
- package/dist/mjs/getRandomItem.js +11 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/randomInt.js +16 -0
- package/dist/types/counter.d.ts +1 -1
- package/dist/types/getRandomItem.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/predicate/factory/allOf.d.ts +2 -1
- package/dist/types/predicate/factory/anyOf.d.ts +2 -1
- package/dist/types/randomInt.d.ts +8 -0
- package/dist/types/types/arrays.d.ts +1 -0
- package/package.json +10 -10
package/dist/cjs/counter.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandomItem = getRandomItem;
|
|
4
|
+
const randomInt_js_1 = require("./randomInt.js");
|
|
5
|
+
function getRandomItem(input) {
|
|
6
|
+
switch (input.length) {
|
|
7
|
+
case 0:
|
|
8
|
+
return;
|
|
9
|
+
case 1:
|
|
10
|
+
return input[0];
|
|
11
|
+
default:
|
|
12
|
+
return input[(0, randomInt_js_1.randomInt)(0, input.length)];
|
|
13
|
+
}
|
|
14
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -43,7 +43,9 @@ __exportStar(require("./getMinValue.js"), exports);
|
|
|
43
43
|
__exportStar(require("./getOwnKeys.js"), exports);
|
|
44
44
|
__exportStar(require("./getOwnPaths.js"), exports);
|
|
45
45
|
__exportStar(require("./getOwnProperties.js"), exports);
|
|
46
|
+
__exportStar(require("./getPackageName.js"), exports);
|
|
46
47
|
__exportStar(require("./getPaths.js"), exports);
|
|
48
|
+
__exportStar(require("./getRandomItem.js"), exports);
|
|
47
49
|
__exportStar(require("./getType.js"), exports);
|
|
48
50
|
__exportStar(require("./inRange.js"), exports);
|
|
49
51
|
__exportStar(require("./isEmpty.js"), exports);
|
|
@@ -54,6 +56,7 @@ __exportStar(require("./looksLikeURL.js"), exports);
|
|
|
54
56
|
__exportStar(require("./normalize.js"), exports);
|
|
55
57
|
__exportStar(require("./parseNumber.js"), exports);
|
|
56
58
|
__exportStar(require("./prefix.js"), exports);
|
|
59
|
+
__exportStar(require("./randomInt.js"), exports);
|
|
57
60
|
__exportStar(require("./redactCredentialsInURL.js"), exports);
|
|
58
61
|
__exportStar(require("./resultify.js"), exports);
|
|
59
62
|
__exportStar(require("./secToString.js"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomInt = randomInt;
|
|
4
|
+
const assertIsInteger_js_1 = require("./assertion/assertIsInteger.js");
|
|
5
|
+
const isObject_js_1 = require("./predicate/isObject.js");
|
|
6
|
+
function randomInt(arg1, arg2) {
|
|
7
|
+
const { min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER } = (0, isObject_js_1.isObject)(arg1)
|
|
8
|
+
? arg1
|
|
9
|
+
: { min: arg1, max: arg2 };
|
|
10
|
+
(0, assertIsInteger_js_1.assertIsInteger)(min, 'min must be an integer');
|
|
11
|
+
(0, assertIsInteger_js_1.assertIsInteger)(max, 'max must be an integer');
|
|
12
|
+
if (min === max) {
|
|
13
|
+
return min;
|
|
14
|
+
}
|
|
15
|
+
if (min > max) {
|
|
16
|
+
throw new RangeError('min must be less than max');
|
|
17
|
+
}
|
|
18
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
19
|
+
}
|
package/dist/mjs/counter.js
CHANGED
package/dist/mjs/index.js
CHANGED
|
@@ -27,7 +27,9 @@ export * from './getMinValue.js';
|
|
|
27
27
|
export * from './getOwnKeys.js';
|
|
28
28
|
export * from './getOwnPaths.js';
|
|
29
29
|
export * from './getOwnProperties.js';
|
|
30
|
+
export * from './getPackageName.js';
|
|
30
31
|
export * from './getPaths.js';
|
|
32
|
+
export * from './getRandomItem.js';
|
|
31
33
|
export * from './getType.js';
|
|
32
34
|
export * from './inRange.js';
|
|
33
35
|
export * from './isEmpty.js';
|
|
@@ -38,6 +40,7 @@ export * from './looksLikeURL.js';
|
|
|
38
40
|
export * from './normalize.js';
|
|
39
41
|
export * from './parseNumber.js';
|
|
40
42
|
export * from './prefix.js';
|
|
43
|
+
export * from './randomInt.js';
|
|
41
44
|
export * from './redactCredentialsInURL.js';
|
|
42
45
|
export * from './resultify.js';
|
|
43
46
|
export * from './secToString.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assertIsInteger } from './assertion/assertIsInteger.js';
|
|
2
|
+
import { isObject } from './predicate/isObject.js';
|
|
3
|
+
export function randomInt(arg1, arg2) {
|
|
4
|
+
const { min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER } = isObject(arg1)
|
|
5
|
+
? arg1
|
|
6
|
+
: { min: arg1, max: arg2 };
|
|
7
|
+
assertIsInteger(min, 'min must be an integer');
|
|
8
|
+
assertIsInteger(max, 'max must be an integer');
|
|
9
|
+
if (min === max) {
|
|
10
|
+
return min;
|
|
11
|
+
}
|
|
12
|
+
if (min > max) {
|
|
13
|
+
throw new RangeError('min must be less than max');
|
|
14
|
+
}
|
|
15
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
16
|
+
}
|
package/dist/types/counter.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function counter(start?: number, end?: number, step?: number): Generator<number>;
|
|
1
|
+
export declare function counter(start?: number, end?: number, step?: number): Generator<number, number, number | undefined>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,7 +27,9 @@ export * from './getMinValue.js';
|
|
|
27
27
|
export * from './getOwnKeys.js';
|
|
28
28
|
export * from './getOwnPaths.js';
|
|
29
29
|
export * from './getOwnProperties.js';
|
|
30
|
+
export * from './getPackageName.js';
|
|
30
31
|
export * from './getPaths.js';
|
|
32
|
+
export * from './getRandomItem.js';
|
|
31
33
|
export * from './getType.js';
|
|
32
34
|
export * from './inRange.js';
|
|
33
35
|
export * from './isEmpty.js';
|
|
@@ -38,6 +40,7 @@ export * from './looksLikeURL.js';
|
|
|
38
40
|
export * from './normalize.js';
|
|
39
41
|
export * from './parseNumber.js';
|
|
40
42
|
export * from './prefix.js';
|
|
43
|
+
export * from './randomInt.js';
|
|
41
44
|
export * from './redactCredentialsInURL.js';
|
|
42
45
|
export * from './resultify.js';
|
|
43
46
|
export * from './secToString.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NonEmptyArray } from '../../types/arrays.js';
|
|
1
2
|
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
3
|
import type { IntersectionOf } from '../../types/utils.js';
|
|
3
|
-
export declare const allOf: <Predicates extends TypePredicateFn<unknown
|
|
4
|
+
export declare const allOf: <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(...predicates: Predicates) => TypePredicateFn<IntersectionOf<InferPredicatesReturnType<Predicates>>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NonEmptyArray } from '../../types/arrays.js';
|
|
1
2
|
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
3
|
import type { UnionOf } from '../../types/utils.js';
|
|
3
|
-
export declare const anyOf: <Predicates extends TypePredicateFn<unknown
|
|
4
|
+
export declare const anyOf: <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(...predicates: Predicates) => TypePredicateFn<UnionOf<InferPredicatesReturnType<Predicates>>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RequireAtLeastOne } from './types/records.js';
|
|
2
|
+
import type { Pretty } from './types/utils.js';
|
|
3
|
+
export type RandomIntOptions = Pretty<RequireAtLeastOne<{
|
|
4
|
+
min: number;
|
|
5
|
+
max: number;
|
|
6
|
+
}>>;
|
|
7
|
+
export declare function randomInt(options?: RandomIntOptions): number;
|
|
8
|
+
export declare function randomInt(min: number, max?: number): number;
|
|
@@ -8,3 +8,4 @@ export type GetLength<A extends any[]> = A extends {
|
|
|
8
8
|
export type IfLength<A extends any[], L extends number, T, F> = GetLength<A> extends L ? T : F;
|
|
9
9
|
export type IfEmpty<A extends any[], T, F> = GetLength<A> extends 0 ? T : F;
|
|
10
10
|
export type IfArray<Type, T, F> = Type extends unknown[] ? T : F;
|
|
11
|
+
export type NonEmptyArray<Type> = [Type, ...Type[]];
|
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.61.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.11.
|
|
69
|
+
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -87,27 +87,27 @@
|
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@commitlint/config-conventional": "^19.8.1",
|
|
89
89
|
"@commitlint/types": "^19.8.1",
|
|
90
|
-
"@types/node": "^22.15.
|
|
91
|
-
"@vitest/coverage-v8": "^3.
|
|
90
|
+
"@types/node": "^22.15.30",
|
|
91
|
+
"@vitest/coverage-v8": "^3.2.2",
|
|
92
92
|
"@webdeveric/eslint-config-ts": "^0.11.0",
|
|
93
93
|
"@webdeveric/prettier-config": "^0.3.0",
|
|
94
94
|
"commitlint": "^19.8.1",
|
|
95
95
|
"commitlint-plugin-cspell": "^0.2.0",
|
|
96
|
-
"conventional-changelog-conventionalcommits": "^
|
|
97
|
-
"cspell": "^9.0.
|
|
96
|
+
"conventional-changelog-conventionalcommits": "^9.0.0",
|
|
97
|
+
"cspell": "^9.0.2",
|
|
98
98
|
"eslint": "^8.57.1",
|
|
99
99
|
"eslint-config-prettier": "^10.1.5",
|
|
100
|
-
"eslint-import-resolver-typescript": "^4.3
|
|
100
|
+
"eslint-import-resolver-typescript": "^4.4.3",
|
|
101
101
|
"eslint-plugin-import": "^2.31.0",
|
|
102
102
|
"husky": "^9.1.7",
|
|
103
103
|
"jsdom": "^26.1.0",
|
|
104
|
-
"lint-staged": "^16.
|
|
104
|
+
"lint-staged": "^16.1.0",
|
|
105
105
|
"prettier": "^3.5.3",
|
|
106
106
|
"rimraf": "^6.0.1",
|
|
107
|
-
"semantic-release": "^24.2.
|
|
107
|
+
"semantic-release": "^24.2.5",
|
|
108
108
|
"typescript": "^5.8.3",
|
|
109
109
|
"validate-package-exports": "^0.9.0",
|
|
110
|
-
"vitest": "^3.
|
|
110
|
+
"vitest": "^3.2.2"
|
|
111
111
|
},
|
|
112
112
|
"pnpm": {
|
|
113
113
|
"onlyBuiltDependencies": [
|