@jiakun-zhao/utils 1.3.4 → 1.3.6
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 +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.mjs +1 -73
- package/dist/natural-compare.d.mts +6 -0
- package/dist/natural-compare.d.ts +6 -0
- package/dist/natural-compare.mjs +74 -0
- package/package.json +5 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,14 +6,10 @@ declare function createArray<T = number>(length: number, mapFn?: (index: number)
|
|
|
6
6
|
|
|
7
7
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
8
8
|
|
|
9
|
-
declare const naturalCompare: {
|
|
10
|
-
(a: string, b: string): -1 | 0 | 1;
|
|
11
|
-
(a: number, b: number): -1 | 0 | 1;
|
|
12
|
-
};
|
|
13
9
|
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
14
10
|
declare function from<T>(value: T): {
|
|
15
11
|
get: () => T;
|
|
16
12
|
to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
|
|
17
13
|
};
|
|
18
14
|
|
|
19
|
-
export { cleanText, createArray, from, getValueOrUndefined, isArray,
|
|
15
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,10 @@ declare function createArray<T = number>(length: number, mapFn?: (index: number)
|
|
|
6
6
|
|
|
7
7
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
8
8
|
|
|
9
|
-
declare const naturalCompare: {
|
|
10
|
-
(a: string, b: string): -1 | 0 | 1;
|
|
11
|
-
(a: number, b: number): -1 | 0 | 1;
|
|
12
|
-
};
|
|
13
9
|
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
14
10
|
declare function from<T>(value: T): {
|
|
15
11
|
get: () => T;
|
|
16
12
|
to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
|
|
17
13
|
};
|
|
18
14
|
|
|
19
|
-
export { cleanText, createArray, from, getValueOrUndefined, isArray,
|
|
15
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.mjs
CHANGED
|
@@ -1,76 +1,5 @@
|
|
|
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
|
-
|
|
74
3
|
const isArray = Array.isArray;
|
|
75
4
|
function singleOrNull(arr) {
|
|
76
5
|
return arr.length === 1 ? arr[0] : null;
|
|
@@ -83,7 +12,6 @@ function cleanText(str, searchValue) {
|
|
|
83
12
|
return str.replace(searchValue, "");
|
|
84
13
|
}
|
|
85
14
|
|
|
86
|
-
const naturalCompare = naturalCompareFn;
|
|
87
15
|
function getValueOrUndefined(condition, value) {
|
|
88
16
|
return condition ? value : void 0;
|
|
89
17
|
}
|
|
@@ -94,4 +22,4 @@ function from(value) {
|
|
|
94
22
|
};
|
|
95
23
|
}
|
|
96
24
|
|
|
97
|
-
export { cleanText, createArray, from, getValueOrUndefined, isArray,
|
|
25
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function getDefaultExportFromCjs (x) {
|
|
2
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
var naturalCompare$1 = {exports: {}};
|
|
6
|
+
|
|
7
|
+
var hasRequiredNaturalCompare;
|
|
8
|
+
|
|
9
|
+
function requireNaturalCompare () {
|
|
10
|
+
if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
|
|
11
|
+
hasRequiredNaturalCompare = 1;
|
|
12
|
+
/*
|
|
13
|
+
* @version 1.4.0
|
|
14
|
+
* @date 2015-10-26
|
|
15
|
+
* @stability 3 - Stable
|
|
16
|
+
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
|
17
|
+
* @license MIT License
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var naturalCompare = function(a, b) {
|
|
22
|
+
var i, codeA
|
|
23
|
+
, codeB = 1
|
|
24
|
+
, posA = 0
|
|
25
|
+
, posB = 0
|
|
26
|
+
, alphabet = String.alphabet;
|
|
27
|
+
|
|
28
|
+
function getCode(str, pos, code) {
|
|
29
|
+
if (code) {
|
|
30
|
+
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
|
|
31
|
+
return +str.slice(pos - 1, i)
|
|
32
|
+
}
|
|
33
|
+
code = alphabet && alphabet.indexOf(str.charAt(pos));
|
|
34
|
+
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
|
|
35
|
+
: code < 46 ? 65 // -
|
|
36
|
+
: code < 48 ? code - 1
|
|
37
|
+
: code < 58 ? code + 18 // 0-9
|
|
38
|
+
: code < 65 ? code - 11
|
|
39
|
+
: code < 91 ? code + 11 // A-Z
|
|
40
|
+
: code < 97 ? code - 37
|
|
41
|
+
: code < 123 ? code + 5 // a-z
|
|
42
|
+
: code - 63
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if ((a+="") != (b+="")) for (;codeB;) {
|
|
47
|
+
codeA = getCode(a, posA++);
|
|
48
|
+
codeB = getCode(b, posB++);
|
|
49
|
+
|
|
50
|
+
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
51
|
+
codeA = getCode(a, posA, posA);
|
|
52
|
+
codeB = getCode(b, posB, posA = i);
|
|
53
|
+
posB = i;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (codeA != codeB) return (codeA < codeB) ? -1 : 1
|
|
57
|
+
}
|
|
58
|
+
return 0
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
naturalCompare$1.exports = naturalCompare;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
String.naturalCompare = naturalCompare;
|
|
65
|
+
}
|
|
66
|
+
return naturalCompare$1.exports;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var naturalCompareExports = requireNaturalCompare();
|
|
70
|
+
const defaultNaturalCompare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
|
|
71
|
+
|
|
72
|
+
const naturalCompare = defaultNaturalCompare;
|
|
73
|
+
|
|
74
|
+
export { naturalCompare as default, naturalCompare };
|
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.6",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <hi@zhaojiakun.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
".": {
|
|
18
18
|
"import": "./dist/index.mjs",
|
|
19
19
|
"types": "./dist/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./natural-compare": {
|
|
22
|
+
"import": "./dist/natural-compare.mjs",
|
|
23
|
+
"types": "./dist/natural-compare.d.ts"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
"main": "./dist/index.mjs",
|