@jiakun-zhao/utils 0.1.8 → 1.0.0-beta.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/index.cjs +16 -44
- package/dist/index.d.cts +3 -13
- package/dist/index.d.mts +3 -13
- package/dist/index.d.ts +3 -13
- package/dist/index.mjs +3 -36
- package/dist/shared.cjs +20 -0
- package/dist/shared.d.cts +10 -0
- package/dist/shared.d.mts +10 -0
- package/dist/shared.d.ts +10 -0
- package/dist/shared.mjs +13 -0
- package/package.json +16 -8
package/dist/index.cjs
CHANGED
|
@@ -1,48 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const fastGlob = require('fast-glob');
|
|
4
|
+
const ohash = require('ohash');
|
|
5
|
+
const localPkg = require('local-pkg');
|
|
4
6
|
|
|
5
|
-
function
|
|
6
|
-
return block(value);
|
|
7
|
-
}
|
|
8
|
-
function use(value, block) {
|
|
9
|
-
block(value);
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
function takeIf(value, predicate) {
|
|
13
|
-
return predicate(value) ? value : null;
|
|
14
|
-
}
|
|
15
|
-
function isNotEmpty(o) {
|
|
16
|
-
if (typeof o !== "object")
|
|
17
|
-
return Boolean(o);
|
|
18
|
-
return Array.isArray(o) ? !!o.length : !!Object.keys(o).length;
|
|
19
|
-
}
|
|
20
|
-
function singleOrNull(arr) {
|
|
21
|
-
return arr.length === 1 ? arr[0] : null;
|
|
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
|
-
}
|
|
30
|
-
function hScreen() {
|
|
31
|
-
document.body.style.setProperty("--h-screen", `${window.innerHeight}px`);
|
|
32
|
-
}
|
|
33
|
-
function fixHeightScreen() {
|
|
34
|
-
hScreen();
|
|
35
|
-
window.addEventListener("resize", hScreen);
|
|
36
|
-
}
|
|
7
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
37
8
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
exports.
|
|
43
|
-
exports.
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
9
|
+
const fastGlob__default = /*#__PURE__*/_interopDefaultCompat(fastGlob);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.glob = fastGlob__default;
|
|
14
|
+
exports.hash = ohash.hash;
|
|
15
|
+
exports.sha256 = ohash.sha256;
|
|
16
|
+
exports.sha256base64 = ohash.sha256base64;
|
|
17
|
+
exports.getPackageInfo = localPkg.getPackageInfo;
|
|
18
|
+
exports.getPackageInfoSync = localPkg.getPackageInfoSync;
|
|
19
|
+
exports.isPackageExists = localPkg.isPackageExists;
|
|
20
|
+
exports.loadPackageJSON = localPkg.loadPackageJSON;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
declare function fixHeightScreen(): void;
|
|
12
|
-
|
|
13
|
-
export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
|
1
|
+
export { default as glob } from 'fast-glob';
|
|
2
|
+
export { hash, sha256, sha256base64 } from 'ohash';
|
|
3
|
+
export { getPackageInfo, getPackageInfoSync, isPackageExists, loadPackageJSON } from 'local-pkg';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
declare function fixHeightScreen(): void;
|
|
12
|
-
|
|
13
|
-
export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
|
1
|
+
export { default as glob } from 'fast-glob';
|
|
2
|
+
export { hash, sha256, sha256base64 } from 'ohash';
|
|
3
|
+
export { getPackageInfo, getPackageInfoSync, isPackageExists, loadPackageJSON } from 'local-pkg';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
declare function fixHeightScreen(): void;
|
|
12
|
-
|
|
13
|
-
export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
|
1
|
+
export { default as glob } from 'fast-glob';
|
|
2
|
+
export { hash, sha256, sha256base64 } from 'ohash';
|
|
3
|
+
export { getPackageInfo, getPackageInfoSync, isPackageExists, loadPackageJSON } from 'local-pkg';
|
package/dist/index.mjs
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return block(value);
|
|
5
|
-
}
|
|
6
|
-
function use(value, block) {
|
|
7
|
-
block(value);
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
function takeIf(value, predicate) {
|
|
11
|
-
return predicate(value) ? value : null;
|
|
12
|
-
}
|
|
13
|
-
function isNotEmpty(o) {
|
|
14
|
-
if (typeof o !== "object")
|
|
15
|
-
return Boolean(o);
|
|
16
|
-
return Array.isArray(o) ? !!o.length : !!Object.keys(o).length;
|
|
17
|
-
}
|
|
18
|
-
function singleOrNull(arr) {
|
|
19
|
-
return arr.length === 1 ? arr[0] : null;
|
|
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
|
-
}
|
|
28
|
-
function hScreen() {
|
|
29
|
-
document.body.style.setProperty("--h-screen", `${window.innerHeight}px`);
|
|
30
|
-
}
|
|
31
|
-
function fixHeightScreen() {
|
|
32
|
-
hScreen();
|
|
33
|
-
window.addEventListener("resize", hScreen);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
|
|
1
|
+
export { default as glob } from 'fast-glob';
|
|
2
|
+
export { hash, sha256, sha256base64 } from 'ohash';
|
|
3
|
+
export { getPackageInfo, getPackageInfoSync, isPackageExists, loadPackageJSON } from 'local-pkg';
|
package/dist/shared.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const utils = require('@antfu/utils');
|
|
4
|
+
|
|
5
|
+
function takeIf(value, predicate) {
|
|
6
|
+
return predicate(value) ? value : null;
|
|
7
|
+
}
|
|
8
|
+
function singleOrNull(arr) {
|
|
9
|
+
return arr.length === 1 ? arr[0] : null;
|
|
10
|
+
}
|
|
11
|
+
function random(max, min = 0) {
|
|
12
|
+
return Math.floor(Math.random() * max) + min;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.random = random;
|
|
16
|
+
exports.singleOrNull = singleOrNull;
|
|
17
|
+
exports.takeIf = takeIf;
|
|
18
|
+
Object.keys(utils).forEach(function (k) {
|
|
19
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
|
|
20
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from '@antfu/utils';
|
|
2
|
+
|
|
3
|
+
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
4
|
+
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
|
+
/**
|
|
6
|
+
* min <= result < max
|
|
7
|
+
*/
|
|
8
|
+
declare function random(max: number, min?: number): number;
|
|
9
|
+
|
|
10
|
+
export { random, singleOrNull, takeIf };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from '@antfu/utils';
|
|
2
|
+
|
|
3
|
+
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
4
|
+
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
|
+
/**
|
|
6
|
+
* min <= result < max
|
|
7
|
+
*/
|
|
8
|
+
declare function random(max: number, min?: number): number;
|
|
9
|
+
|
|
10
|
+
export { random, singleOrNull, takeIf };
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from '@antfu/utils';
|
|
2
|
+
|
|
3
|
+
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
4
|
+
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
|
+
/**
|
|
6
|
+
* min <= result < max
|
|
7
|
+
*/
|
|
8
|
+
declare function random(max: number, min?: number): number;
|
|
9
|
+
|
|
10
|
+
export { random, singleOrNull, takeIf };
|
package/dist/shared.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from '@antfu/utils';
|
|
2
|
+
|
|
3
|
+
function takeIf(value, predicate) {
|
|
4
|
+
return predicate(value) ? value : null;
|
|
5
|
+
}
|
|
6
|
+
function singleOrNull(arr) {
|
|
7
|
+
return arr.length === 1 ? arr[0] : null;
|
|
8
|
+
}
|
|
9
|
+
function random(max, min = 0) {
|
|
10
|
+
return Math.floor(Math.random() * max) + min;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { random, singleOrNull, takeIf };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jiakun-zhao/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0-beta.0",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <jiakun.zhao@outlook.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,8 +16,13 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./shared": {
|
|
23
|
+
"types": "./dist/shared.d.ts",
|
|
24
|
+
"import": "./dist/shared.mjs",
|
|
25
|
+
"require": "./dist/shared.cjs"
|
|
21
26
|
}
|
|
22
27
|
},
|
|
23
28
|
"main": "./dist/index.cjs",
|
|
@@ -27,15 +32,18 @@
|
|
|
27
32
|
"dist"
|
|
28
33
|
],
|
|
29
34
|
"dependencies": {
|
|
30
|
-
"@antfu/utils": "^0.7.6"
|
|
35
|
+
"@antfu/utils": "^0.7.6",
|
|
36
|
+
"fast-glob": "^3.3.2",
|
|
37
|
+
"local-pkg": "^0.5.0",
|
|
38
|
+
"ohash": "^1.1.3"
|
|
31
39
|
},
|
|
32
40
|
"devDependencies": {
|
|
33
41
|
"@jiakun-zhao/eslint-config": "^1.3.1",
|
|
34
|
-
"@types/node": "^20.
|
|
42
|
+
"@types/node": "^20.9.2",
|
|
35
43
|
"bumpp": "^9.2.0",
|
|
36
|
-
"eslint": "^8.
|
|
37
|
-
"esno": "^0.
|
|
38
|
-
"typescript": "^5.
|
|
44
|
+
"eslint": "^8.54.0",
|
|
45
|
+
"esno": "^4.0.0",
|
|
46
|
+
"typescript": "^5.3.2",
|
|
39
47
|
"unbuild": "^2.0.0"
|
|
40
48
|
},
|
|
41
49
|
"eslintConfig": {
|