@jiakun-zhao/utils 1.3.3 → 1.3.5
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 -32
- package/dist/index.d.ts +1 -32
- package/dist/index.mjs +2 -3
- 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 +8 -5
- package/dist/index.cjs +0 -48
- package/dist/index.d.cts +0 -46
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
|
-
export { default as naturalCompare } from 'natural-compare';
|
|
3
2
|
|
|
4
3
|
declare const isArray: (arg: any) => arg is any[];
|
|
5
4
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
@@ -9,38 +8,8 @@ declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
|
9
8
|
|
|
10
9
|
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
11
10
|
declare function from<T>(value: T): {
|
|
12
|
-
to: <R>(fn: (value: T) => R) => {
|
|
13
|
-
to: <R_1>(fn: (value: R) => R_1) => {
|
|
14
|
-
to: <R_2>(fn: (value: R_1) => R_2) => {
|
|
15
|
-
to: <R_3>(fn: (value: R_2) => R_3) => {
|
|
16
|
-
to: <R_4>(fn: (value: R_3) => R_4) => {
|
|
17
|
-
to: <R_5>(fn: (value: R_4) => R_5) => {
|
|
18
|
-
to: <R_6>(fn: (value: R_5) => R_6) => {
|
|
19
|
-
to: <R_7>(fn: (value: R_6) => R_7) => {
|
|
20
|
-
to: <R_8>(fn: (value: R_7) => R_8) => {
|
|
21
|
-
to: <R_9>(fn: (value: R_8) => R_9) => {
|
|
22
|
-
to: <R_10>(fn: (value: R_9) => R_10) => /*elided*/ any;
|
|
23
|
-
get: () => R_9;
|
|
24
|
-
};
|
|
25
|
-
get: () => R_8;
|
|
26
|
-
};
|
|
27
|
-
get: () => R_7;
|
|
28
|
-
};
|
|
29
|
-
get: () => R_6;
|
|
30
|
-
};
|
|
31
|
-
get: () => R_5;
|
|
32
|
-
};
|
|
33
|
-
get: () => R_4;
|
|
34
|
-
};
|
|
35
|
-
get: () => R_3;
|
|
36
|
-
};
|
|
37
|
-
get: () => R_2;
|
|
38
|
-
};
|
|
39
|
-
get: () => R_1;
|
|
40
|
-
};
|
|
41
|
-
get: () => R;
|
|
42
|
-
};
|
|
43
11
|
get: () => T;
|
|
12
|
+
to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
|
|
44
13
|
};
|
|
45
14
|
|
|
46
15
|
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
|
-
export { default as naturalCompare } from 'natural-compare';
|
|
3
2
|
|
|
4
3
|
declare const isArray: (arg: any) => arg is any[];
|
|
5
4
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
@@ -9,38 +8,8 @@ declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
|
9
8
|
|
|
10
9
|
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
11
10
|
declare function from<T>(value: T): {
|
|
12
|
-
to: <R>(fn: (value: T) => R) => {
|
|
13
|
-
to: <R_1>(fn: (value: R) => R_1) => {
|
|
14
|
-
to: <R_2>(fn: (value: R_1) => R_2) => {
|
|
15
|
-
to: <R_3>(fn: (value: R_2) => R_3) => {
|
|
16
|
-
to: <R_4>(fn: (value: R_3) => R_4) => {
|
|
17
|
-
to: <R_5>(fn: (value: R_4) => R_5) => {
|
|
18
|
-
to: <R_6>(fn: (value: R_5) => R_6) => {
|
|
19
|
-
to: <R_7>(fn: (value: R_6) => R_7) => {
|
|
20
|
-
to: <R_8>(fn: (value: R_7) => R_8) => {
|
|
21
|
-
to: <R_9>(fn: (value: R_8) => R_9) => {
|
|
22
|
-
to: <R_10>(fn: (value: R_9) => R_10) => /*elided*/ any;
|
|
23
|
-
get: () => R_9;
|
|
24
|
-
};
|
|
25
|
-
get: () => R_8;
|
|
26
|
-
};
|
|
27
|
-
get: () => R_7;
|
|
28
|
-
};
|
|
29
|
-
get: () => R_6;
|
|
30
|
-
};
|
|
31
|
-
get: () => R_5;
|
|
32
|
-
};
|
|
33
|
-
get: () => R_4;
|
|
34
|
-
};
|
|
35
|
-
get: () => R_3;
|
|
36
|
-
};
|
|
37
|
-
get: () => R_2;
|
|
38
|
-
};
|
|
39
|
-
get: () => R_1;
|
|
40
|
-
};
|
|
41
|
-
get: () => R;
|
|
42
|
-
};
|
|
43
11
|
get: () => T;
|
|
12
|
+
to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
|
|
44
13
|
};
|
|
45
14
|
|
|
46
15
|
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
|
-
export { default as naturalCompare } from 'natural-compare';
|
|
3
2
|
|
|
4
3
|
const isArray = Array.isArray;
|
|
5
4
|
function singleOrNull(arr) {
|
|
@@ -18,8 +17,8 @@ function getValueOrUndefined(condition, value) {
|
|
|
18
17
|
}
|
|
19
18
|
function from(value) {
|
|
20
19
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
get: () => value,
|
|
21
|
+
to: (fn) => from(fn(value))
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -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.5",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <hi@zhaojiakun.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,19 +16,21 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"import": "./dist/index.mjs",
|
|
19
|
-
"require": "./dist/index.cjs",
|
|
20
19
|
"types": "./dist/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./natural-compare": {
|
|
22
|
+
"import": "./dist/natural-compare.mjs",
|
|
23
|
+
"types": "./dist/natural-compare.d.ts"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
|
-
"main": "./dist/index.
|
|
26
|
+
"main": "./dist/index.mjs",
|
|
24
27
|
"module": "./dist/index.mjs",
|
|
25
28
|
"types": "./dist/index.d.ts",
|
|
26
29
|
"files": [
|
|
27
30
|
"dist"
|
|
28
31
|
],
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@antfu/utils": "^9.2.0"
|
|
31
|
-
"natural-compare": "^1.4.0"
|
|
33
|
+
"@antfu/utils": "^9.2.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"@jiakun-zhao/eslint-config": "^4.1.8",
|
|
@@ -36,6 +38,7 @@
|
|
|
36
38
|
"@types/node": "^24.0.3",
|
|
37
39
|
"bumpp": "^10.2.0",
|
|
38
40
|
"eslint": "^9.29.0",
|
|
41
|
+
"natural-compare": "^1.4.0",
|
|
39
42
|
"typescript": "^5.8.3",
|
|
40
43
|
"unbuild": "^3.5.0",
|
|
41
44
|
"vitest": "^3.2.4"
|
package/dist/index.cjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const utils = require('@antfu/utils');
|
|
4
|
-
const naturalCompare = require('natural-compare');
|
|
5
|
-
|
|
6
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
7
|
-
|
|
8
|
-
const naturalCompare__default = /*#__PURE__*/_interopDefaultCompat(naturalCompare);
|
|
9
|
-
|
|
10
|
-
const isArray = Array.isArray;
|
|
11
|
-
function singleOrNull(arr) {
|
|
12
|
-
return arr.length === 1 ? arr[0] : null;
|
|
13
|
-
}
|
|
14
|
-
function createArray(length, mapFn) {
|
|
15
|
-
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function cleanText(str, searchValue) {
|
|
19
|
-
return str.replace(searchValue, "");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getValueOrUndefined(condition, value) {
|
|
23
|
-
return condition ? value : void 0;
|
|
24
|
-
}
|
|
25
|
-
function from(value) {
|
|
26
|
-
return {
|
|
27
|
-
to: (fn) => from(fn(value)),
|
|
28
|
-
get: () => value
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
exports.naturalCompare = naturalCompare__default;
|
|
33
|
-
exports.cleanText = cleanText;
|
|
34
|
-
exports.createArray = createArray;
|
|
35
|
-
exports.from = from;
|
|
36
|
-
exports.getValueOrUndefined = getValueOrUndefined;
|
|
37
|
-
exports.isArray = isArray;
|
|
38
|
-
exports.singleOrNull = singleOrNull;
|
|
39
|
-
Object.prototype.hasOwnProperty.call(utils, '__proto__') &&
|
|
40
|
-
!Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
|
|
41
|
-
Object.defineProperty(exports, '__proto__', {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
value: utils['__proto__']
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
Object.keys(utils).forEach(function (k) {
|
|
47
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
|
|
48
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export * from '@antfu/utils';
|
|
2
|
-
export { default as naturalCompare } from 'natural-compare';
|
|
3
|
-
|
|
4
|
-
declare const isArray: (arg: any) => arg is any[];
|
|
5
|
-
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
6
|
-
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
7
|
-
|
|
8
|
-
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
9
|
-
|
|
10
|
-
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
11
|
-
declare function from<T>(value: T): {
|
|
12
|
-
to: <R>(fn: (value: T) => R) => {
|
|
13
|
-
to: <R_1>(fn: (value: R) => R_1) => {
|
|
14
|
-
to: <R_2>(fn: (value: R_1) => R_2) => {
|
|
15
|
-
to: <R_3>(fn: (value: R_2) => R_3) => {
|
|
16
|
-
to: <R_4>(fn: (value: R_3) => R_4) => {
|
|
17
|
-
to: <R_5>(fn: (value: R_4) => R_5) => {
|
|
18
|
-
to: <R_6>(fn: (value: R_5) => R_6) => {
|
|
19
|
-
to: <R_7>(fn: (value: R_6) => R_7) => {
|
|
20
|
-
to: <R_8>(fn: (value: R_7) => R_8) => {
|
|
21
|
-
to: <R_9>(fn: (value: R_8) => R_9) => {
|
|
22
|
-
to: <R_10>(fn: (value: R_9) => R_10) => /*elided*/ any;
|
|
23
|
-
get: () => R_9;
|
|
24
|
-
};
|
|
25
|
-
get: () => R_8;
|
|
26
|
-
};
|
|
27
|
-
get: () => R_7;
|
|
28
|
-
};
|
|
29
|
-
get: () => R_6;
|
|
30
|
-
};
|
|
31
|
-
get: () => R_5;
|
|
32
|
-
};
|
|
33
|
-
get: () => R_4;
|
|
34
|
-
};
|
|
35
|
-
get: () => R_3;
|
|
36
|
-
};
|
|
37
|
-
get: () => R_2;
|
|
38
|
-
};
|
|
39
|
-
get: () => R_1;
|
|
40
|
-
};
|
|
41
|
-
get: () => R;
|
|
42
|
-
};
|
|
43
|
-
get: () => T;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|