@jiakun-zhao/utils 0.1.6 → 0.1.7
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/index.cjs +10 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +8 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -20,12 +20,21 @@ function isNotEmpty(o) {
|
|
|
20
20
|
function singleOrNull(arr) {
|
|
21
21
|
return arr.length === 1 ? arr[0] : null;
|
|
22
22
|
}
|
|
23
|
+
function createArray(length, fn) {
|
|
24
|
+
const block = fn ? (_, idx) => fn(idx) : (_, idx) => idx;
|
|
25
|
+
return Array.from({ length }, block);
|
|
26
|
+
}
|
|
27
|
+
function random(max, min = 0) {
|
|
28
|
+
return Math.floor(Math.random() * max) + min;
|
|
29
|
+
}
|
|
23
30
|
|
|
31
|
+
exports.createArray = createArray;
|
|
24
32
|
exports.isNotEmpty = isNotEmpty;
|
|
33
|
+
exports.random = random;
|
|
25
34
|
exports.singleOrNull = singleOrNull;
|
|
26
35
|
exports.takeIf = takeIf;
|
|
27
36
|
exports.to = to;
|
|
28
37
|
exports.use = use;
|
|
29
38
|
Object.keys(utils).forEach(function (k) {
|
|
30
|
-
if (k !== 'default' && !
|
|
39
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
|
|
31
40
|
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from '@antfu/utils';
|
|
2
|
+
|
|
3
|
+
declare function to<T, R>(value: T, block: (it: T) => R): R;
|
|
4
|
+
declare function use<T>(value: T, block: (it: T) => void): T;
|
|
5
|
+
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
6
|
+
declare function isNotEmpty(o: any): boolean;
|
|
7
|
+
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
8
|
+
declare function createArray(length: number): number[];
|
|
9
|
+
declare function createArray<R>(length: number, fn: (index: number) => R): R[];
|
|
10
|
+
declare function random(max: number, min?: number): number;
|
|
11
|
+
|
|
12
|
+
export { createArray, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from '@antfu/utils';
|
|
2
|
+
|
|
3
|
+
declare function to<T, R>(value: T, block: (it: T) => R): R;
|
|
4
|
+
declare function use<T>(value: T, block: (it: T) => void): T;
|
|
5
|
+
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
6
|
+
declare function isNotEmpty(o: any): boolean;
|
|
7
|
+
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
8
|
+
declare function createArray(length: number): number[];
|
|
9
|
+
declare function createArray<R>(length: number, fn: (index: number) => R): R[];
|
|
10
|
+
declare function random(max: number, min?: number): number;
|
|
11
|
+
|
|
12
|
+
export { createArray, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,8 @@ declare function use<T>(value: T, block: (it: T) => void): T;
|
|
|
5
5
|
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
6
6
|
declare function isNotEmpty(o: any): boolean;
|
|
7
7
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
8
|
+
declare function createArray(length: number): number[];
|
|
9
|
+
declare function createArray<R>(length: number, fn: (index: number) => R): R[];
|
|
10
|
+
declare function random(max: number, min?: number): number;
|
|
8
11
|
|
|
9
|
-
export { isNotEmpty, singleOrNull, takeIf, to, use };
|
|
12
|
+
export { createArray, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
package/dist/index.mjs
CHANGED
|
@@ -18,5 +18,12 @@ function isNotEmpty(o) {
|
|
|
18
18
|
function singleOrNull(arr) {
|
|
19
19
|
return arr.length === 1 ? arr[0] : null;
|
|
20
20
|
}
|
|
21
|
+
function createArray(length, fn) {
|
|
22
|
+
const block = fn ? (_, idx) => fn(idx) : (_, idx) => idx;
|
|
23
|
+
return Array.from({ length }, block);
|
|
24
|
+
}
|
|
25
|
+
function random(max, min = 0) {
|
|
26
|
+
return Math.floor(Math.random() * max) + min;
|
|
27
|
+
}
|
|
21
28
|
|
|
22
|
-
export { isNotEmpty, singleOrNull, takeIf, to, use };
|
|
29
|
+
export { createArray, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jiakun-zhao/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <jiakun.zhao@outlook.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"@antfu/utils": "^0.7.6"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@jiakun-zhao/eslint-config": "^1.
|
|
34
|
-
"@types/node": "^20.
|
|
33
|
+
"@jiakun-zhao/eslint-config": "^1.3.1",
|
|
34
|
+
"@types/node": "^20.8.10",
|
|
35
35
|
"bumpp": "^9.2.0",
|
|
36
|
-
"eslint": "^8.
|
|
36
|
+
"eslint": "^8.53.0",
|
|
37
37
|
"esno": "^0.17.0",
|
|
38
38
|
"typescript": "^5.2.2",
|
|
39
39
|
"unbuild": "^2.0.0"
|