@jiakun-zhao/utils 1.3.2 → 1.3.4
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.d.mts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.mjs +79 -14
- package/package.json +13 -10
- package/dist/index.cjs +0 -50
- package/dist/index.d.cts +0 -18
package/dist/index.d.mts
CHANGED
|
@@ -4,15 +4,16 @@ declare const isArray: (arg: any) => arg is any[];
|
|
|
4
4
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
5
|
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
6
6
|
|
|
7
|
-
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description min <= result < max
|
|
11
|
-
*/
|
|
12
|
-
declare function random(max: number, min?: number): number;
|
|
13
|
-
|
|
14
7
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
15
8
|
|
|
9
|
+
declare const naturalCompare: {
|
|
10
|
+
(a: string, b: string): -1 | 0 | 1;
|
|
11
|
+
(a: number, b: number): -1 | 0 | 1;
|
|
12
|
+
};
|
|
16
13
|
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
14
|
+
declare function from<T>(value: T): {
|
|
15
|
+
get: () => T;
|
|
16
|
+
to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
|
|
17
|
+
};
|
|
17
18
|
|
|
18
|
-
export { cleanText, createArray, getValueOrUndefined, isArray,
|
|
19
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, naturalCompare, singleOrNull };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,15 +4,16 @@ declare const isArray: (arg: any) => arg is any[];
|
|
|
4
4
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
5
|
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
6
6
|
|
|
7
|
-
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description min <= result < max
|
|
11
|
-
*/
|
|
12
|
-
declare function random(max: number, min?: number): number;
|
|
13
|
-
|
|
14
7
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
15
8
|
|
|
9
|
+
declare const naturalCompare: {
|
|
10
|
+
(a: string, b: string): -1 | 0 | 1;
|
|
11
|
+
(a: number, b: number): -1 | 0 | 1;
|
|
12
|
+
};
|
|
16
13
|
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
14
|
+
declare function from<T>(value: T): {
|
|
15
|
+
get: () => T;
|
|
16
|
+
to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
|
|
17
|
+
};
|
|
17
18
|
|
|
18
|
-
export { cleanText, createArray, getValueOrUndefined, isArray,
|
|
19
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, naturalCompare, singleOrNull };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
2
|
|
|
3
|
+
function getDefaultExportFromCjs (x) {
|
|
4
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
var naturalCompare$1 = {exports: {}};
|
|
8
|
+
|
|
9
|
+
var hasRequiredNaturalCompare;
|
|
10
|
+
|
|
11
|
+
function requireNaturalCompare () {
|
|
12
|
+
if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
|
|
13
|
+
hasRequiredNaturalCompare = 1;
|
|
14
|
+
/*
|
|
15
|
+
* @version 1.4.0
|
|
16
|
+
* @date 2015-10-26
|
|
17
|
+
* @stability 3 - Stable
|
|
18
|
+
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
|
19
|
+
* @license MIT License
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var naturalCompare = function(a, b) {
|
|
24
|
+
var i, codeA
|
|
25
|
+
, codeB = 1
|
|
26
|
+
, posA = 0
|
|
27
|
+
, posB = 0
|
|
28
|
+
, alphabet = String.alphabet;
|
|
29
|
+
|
|
30
|
+
function getCode(str, pos, code) {
|
|
31
|
+
if (code) {
|
|
32
|
+
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
|
|
33
|
+
return +str.slice(pos - 1, i)
|
|
34
|
+
}
|
|
35
|
+
code = alphabet && alphabet.indexOf(str.charAt(pos));
|
|
36
|
+
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
|
|
37
|
+
: code < 46 ? 65 // -
|
|
38
|
+
: code < 48 ? code - 1
|
|
39
|
+
: code < 58 ? code + 18 // 0-9
|
|
40
|
+
: code < 65 ? code - 11
|
|
41
|
+
: code < 91 ? code + 11 // A-Z
|
|
42
|
+
: code < 97 ? code - 37
|
|
43
|
+
: code < 123 ? code + 5 // a-z
|
|
44
|
+
: code - 63
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if ((a+="") != (b+="")) for (;codeB;) {
|
|
49
|
+
codeA = getCode(a, posA++);
|
|
50
|
+
codeB = getCode(b, posB++);
|
|
51
|
+
|
|
52
|
+
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
53
|
+
codeA = getCode(a, posA, posA);
|
|
54
|
+
codeB = getCode(b, posB, posA = i);
|
|
55
|
+
posB = i;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (codeA != codeB) return (codeA < codeB) ? -1 : 1
|
|
59
|
+
}
|
|
60
|
+
return 0
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
naturalCompare$1.exports = naturalCompare;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
String.naturalCompare = naturalCompare;
|
|
67
|
+
}
|
|
68
|
+
return naturalCompare$1.exports;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var naturalCompareExports = requireNaturalCompare();
|
|
72
|
+
const naturalCompareFn = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
|
|
73
|
+
|
|
3
74
|
const isArray = Array.isArray;
|
|
4
75
|
function singleOrNull(arr) {
|
|
5
76
|
return arr.length === 1 ? arr[0] : null;
|
|
@@ -8,25 +79,19 @@ function createArray(length, mapFn) {
|
|
|
8
79
|
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
9
80
|
}
|
|
10
81
|
|
|
11
|
-
function safe(fn) {
|
|
12
|
-
try {
|
|
13
|
-
const res = fn();
|
|
14
|
-
return res instanceof Promise ? res.catch(() => null) : res;
|
|
15
|
-
} catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function random(max, min = 0) {
|
|
21
|
-
return Math.floor(Math.random() * max) + min;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
82
|
function cleanText(str, searchValue) {
|
|
25
83
|
return str.replace(searchValue, "");
|
|
26
84
|
}
|
|
27
85
|
|
|
86
|
+
const naturalCompare = naturalCompareFn;
|
|
28
87
|
function getValueOrUndefined(condition, value) {
|
|
29
88
|
return condition ? value : void 0;
|
|
30
89
|
}
|
|
90
|
+
function from(value) {
|
|
91
|
+
return {
|
|
92
|
+
get: () => value,
|
|
93
|
+
to: (fn) => from(fn(value))
|
|
94
|
+
};
|
|
95
|
+
}
|
|
31
96
|
|
|
32
|
-
export { cleanText, createArray, getValueOrUndefined, isArray,
|
|
97
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, naturalCompare, singleOrNull };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jiakun-zhao/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.4",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <hi@zhaojiakun.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
18
|
"import": "./dist/index.mjs",
|
|
20
|
-
"
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
21
20
|
}
|
|
22
21
|
},
|
|
23
|
-
"main": "./dist/index.
|
|
22
|
+
"main": "./dist/index.mjs",
|
|
24
23
|
"module": "./dist/index.mjs",
|
|
25
24
|
"types": "./dist/index.d.ts",
|
|
26
25
|
"files": [
|
|
@@ -30,16 +29,20 @@
|
|
|
30
29
|
"@antfu/utils": "^9.2.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@types/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
32
|
+
"@jiakun-zhao/eslint-config": "^4.1.8",
|
|
33
|
+
"@types/natural-compare": "^1.4.3",
|
|
34
|
+
"@types/node": "^24.0.3",
|
|
35
|
+
"bumpp": "^10.2.0",
|
|
36
|
+
"eslint": "^9.29.0",
|
|
37
|
+
"natural-compare": "^1.4.0",
|
|
37
38
|
"typescript": "^5.8.3",
|
|
38
|
-
"unbuild": "^3.5.0"
|
|
39
|
+
"unbuild": "^3.5.0",
|
|
40
|
+
"vitest": "^3.2.4"
|
|
39
41
|
},
|
|
40
42
|
"scripts": {
|
|
41
43
|
"build": "unbuild",
|
|
44
|
+
"release": "bumpp && pnpm publish && npx cnpm sync @jiakun-zhao/utils",
|
|
42
45
|
"stub": "unbuild --stub",
|
|
43
|
-
"
|
|
46
|
+
"test": "vitest"
|
|
44
47
|
}
|
|
45
48
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const utils = require('@antfu/utils');
|
|
4
|
-
|
|
5
|
-
const isArray = Array.isArray;
|
|
6
|
-
function singleOrNull(arr) {
|
|
7
|
-
return arr.length === 1 ? arr[0] : null;
|
|
8
|
-
}
|
|
9
|
-
function createArray(length, mapFn) {
|
|
10
|
-
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function safe(fn) {
|
|
14
|
-
try {
|
|
15
|
-
const res = fn();
|
|
16
|
-
return res instanceof Promise ? res.catch(() => null) : res;
|
|
17
|
-
} catch {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function random(max, min = 0) {
|
|
23
|
-
return Math.floor(Math.random() * max) + min;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function cleanText(str, searchValue) {
|
|
27
|
-
return str.replace(searchValue, "");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getValueOrUndefined(condition, value) {
|
|
31
|
-
return condition ? value : void 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
exports.cleanText = cleanText;
|
|
35
|
-
exports.createArray = createArray;
|
|
36
|
-
exports.getValueOrUndefined = getValueOrUndefined;
|
|
37
|
-
exports.isArray = isArray;
|
|
38
|
-
exports.random = random;
|
|
39
|
-
exports.safe = safe;
|
|
40
|
-
exports.singleOrNull = singleOrNull;
|
|
41
|
-
Object.prototype.hasOwnProperty.call(utils, '__proto__') &&
|
|
42
|
-
!Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
|
|
43
|
-
Object.defineProperty(exports, '__proto__', {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
value: utils['__proto__']
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
Object.keys(utils).forEach(function (k) {
|
|
49
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
|
|
50
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export * from '@antfu/utils';
|
|
2
|
-
|
|
3
|
-
declare const isArray: (arg: any) => arg is any[];
|
|
4
|
-
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
|
-
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
6
|
-
|
|
7
|
-
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description min <= result < max
|
|
11
|
-
*/
|
|
12
|
-
declare function random(max: number, min?: number): number;
|
|
13
|
-
|
|
14
|
-
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
15
|
-
|
|
16
|
-
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
17
|
-
|
|
18
|
-
export { cleanText, createArray, getValueOrUndefined, isArray, random, safe, singleOrNull };
|