@jiakun-zhao/utils 1.3.1 → 1.3.3
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 +12 -93
- package/dist/index.d.cts +36 -90
- package/dist/index.d.mts +36 -90
- package/dist/index.d.ts +36 -90
- package/dist/index.mjs +7 -89
- package/package.json +15 -11
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
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);
|
|
4
9
|
|
|
5
10
|
const isArray = Array.isArray;
|
|
6
11
|
function singleOrNull(arr) {
|
|
@@ -10,87 +15,6 @@ function createArray(length, mapFn) {
|
|
|
10
15
|
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
function transform(value, fn) {
|
|
14
|
-
return fn(value);
|
|
15
|
-
}
|
|
16
|
-
function safe(fn) {
|
|
17
|
-
try {
|
|
18
|
-
const res = fn();
|
|
19
|
-
return res instanceof Promise ? res.catch(() => null) : res;
|
|
20
|
-
} catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function random(max, min = 0) {
|
|
26
|
-
return Math.floor(Math.random() * max) + min;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const colors = {
|
|
30
|
-
/** 重置颜色 */
|
|
31
|
-
reset: "\x1B[0m",
|
|
32
|
-
/** 亮色(加粗) */
|
|
33
|
-
bright: "\x1B[1m",
|
|
34
|
-
/** 斜体 */
|
|
35
|
-
italic: "\x1B[3m",
|
|
36
|
-
/** 下划线 */
|
|
37
|
-
underline: "\x1B[4m",
|
|
38
|
-
/** 反向 */
|
|
39
|
-
reverse: "\x1B[7m",
|
|
40
|
-
/** 隐藏 */
|
|
41
|
-
hidden: "\x1B[8m",
|
|
42
|
-
/** 灰色 */
|
|
43
|
-
grey: "\x1B[2m",
|
|
44
|
-
/** 黑色 */
|
|
45
|
-
black: "\x1B[30m",
|
|
46
|
-
/** 红色 */
|
|
47
|
-
red: "\x1B[31m",
|
|
48
|
-
/** 绿色 */
|
|
49
|
-
green: "\x1B[32m",
|
|
50
|
-
/** 黄色 */
|
|
51
|
-
yellow: "\x1B[33m",
|
|
52
|
-
/** 蓝色 */
|
|
53
|
-
blue: "\x1B[34m",
|
|
54
|
-
/** 品红 */
|
|
55
|
-
magenta: "\x1B[35m",
|
|
56
|
-
/** 青色 */
|
|
57
|
-
cyan: "\x1B[36m",
|
|
58
|
-
/** 白色 */
|
|
59
|
-
white: "\x1B[37m",
|
|
60
|
-
/** 背景黑色 */
|
|
61
|
-
bgBlack: "\x1B[40m",
|
|
62
|
-
/** 背景红色 */
|
|
63
|
-
bgRed: "\x1B[41m",
|
|
64
|
-
/** 背景绿色 */
|
|
65
|
-
bgGreen: "\x1B[42m",
|
|
66
|
-
/** 背景黄色 */
|
|
67
|
-
bgYellow: "\x1B[43m",
|
|
68
|
-
/** 背景蓝色 */
|
|
69
|
-
bgBlue: "\x1B[44m",
|
|
70
|
-
/** 背景品红 */
|
|
71
|
-
bgMagenta: "\x1B[45m",
|
|
72
|
-
/** 背景青色 */
|
|
73
|
-
bgCyan: "\x1B[46m",
|
|
74
|
-
/** 背景白色 */
|
|
75
|
-
bgWhite: "\x1B[47m"
|
|
76
|
-
};
|
|
77
|
-
const messages = {
|
|
78
|
-
info: { color: colors.blue, symbol: "\u{1D4F2}" },
|
|
79
|
-
warn: { color: colors.yellow, symbol: "\u{1D4F2}" },
|
|
80
|
-
success: { color: colors.green, symbol: "\u2714\uFE0E" },
|
|
81
|
-
error: { color: colors.red, symbol: "\u2718" }
|
|
82
|
-
};
|
|
83
|
-
function print(...args) {
|
|
84
|
-
if (!args.length)
|
|
85
|
-
return;
|
|
86
|
-
if (utils.isString(args[0])) {
|
|
87
|
-
const [msg, type = "info"] = args;
|
|
88
|
-
console.log(`${messages[type].color}${messages[type].symbol} ${colors.grey}${msg}${colors.reset}`);
|
|
89
|
-
}
|
|
90
|
-
let text = args.map((it) => `${it.color ? colors[it.color] : ""}${it.value}`).join("");
|
|
91
|
-
console.log(`${text}${colors.reset}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
18
|
function cleanText(str, searchValue) {
|
|
95
19
|
return str.replace(searchValue, "");
|
|
96
20
|
}
|
|
@@ -98,25 +22,20 @@ function cleanText(str, searchValue) {
|
|
|
98
22
|
function getValueOrUndefined(condition, value) {
|
|
99
23
|
return condition ? value : void 0;
|
|
100
24
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
return entry;
|
|
25
|
+
function from(value) {
|
|
26
|
+
return {
|
|
27
|
+
to: (fn) => from(fn(value)),
|
|
28
|
+
get: () => value
|
|
29
|
+
};
|
|
107
30
|
}
|
|
108
31
|
|
|
32
|
+
exports.naturalCompare = naturalCompare__default;
|
|
109
33
|
exports.cleanText = cleanText;
|
|
110
|
-
exports.colors = colors;
|
|
111
34
|
exports.createArray = createArray;
|
|
35
|
+
exports.from = from;
|
|
112
36
|
exports.getValueOrUndefined = getValueOrUndefined;
|
|
113
37
|
exports.isArray = isArray;
|
|
114
|
-
exports.print = print;
|
|
115
|
-
exports.random = random;
|
|
116
|
-
exports.safe = safe;
|
|
117
|
-
exports.setFromObject = setFromObject;
|
|
118
38
|
exports.singleOrNull = singleOrNull;
|
|
119
|
-
exports.transform = transform;
|
|
120
39
|
Object.prototype.hasOwnProperty.call(utils, '__proto__') &&
|
|
121
40
|
!Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
|
|
122
41
|
Object.defineProperty(exports, '__proto__', {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,100 +1,46 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
|
+
export { default as naturalCompare } from 'natural-compare';
|
|
2
3
|
|
|
3
4
|
declare const isArray: (arg: any) => arg is any[];
|
|
4
5
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
6
|
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
6
7
|
|
|
7
|
-
declare function
|
|
8
|
-
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @description min <= result < max
|
|
12
|
-
*/
|
|
13
|
-
declare function random(max: number, min?: number): number;
|
|
8
|
+
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
14
9
|
|
|
15
|
-
declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly bgBlack: "\u001B[40m";
|
|
48
|
-
/** 背景红色 */
|
|
49
|
-
readonly bgRed: "\u001B[41m";
|
|
50
|
-
/** 背景绿色 */
|
|
51
|
-
readonly bgGreen: "\u001B[42m";
|
|
52
|
-
/** 背景黄色 */
|
|
53
|
-
readonly bgYellow: "\u001B[43m";
|
|
54
|
-
/** 背景蓝色 */
|
|
55
|
-
readonly bgBlue: "\u001B[44m";
|
|
56
|
-
/** 背景品红 */
|
|
57
|
-
readonly bgMagenta: "\u001B[45m";
|
|
58
|
-
/** 背景青色 */
|
|
59
|
-
readonly bgCyan: "\u001B[46m";
|
|
60
|
-
/** 背景白色 */
|
|
61
|
-
readonly bgWhite: "\u001B[47m";
|
|
62
|
-
};
|
|
63
|
-
declare const messages: {
|
|
64
|
-
readonly info: {
|
|
65
|
-
readonly color: "\u001B[34m";
|
|
66
|
-
readonly symbol: "𝓲";
|
|
67
|
-
};
|
|
68
|
-
readonly warn: {
|
|
69
|
-
readonly color: "\u001B[33m";
|
|
70
|
-
readonly symbol: "𝓲";
|
|
71
|
-
};
|
|
72
|
-
readonly success: {
|
|
73
|
-
readonly color: "\u001B[32m";
|
|
74
|
-
readonly symbol: "✔︎";
|
|
75
|
-
};
|
|
76
|
-
readonly error: {
|
|
77
|
-
readonly color: "\u001B[31m";
|
|
78
|
-
readonly symbol: "✘";
|
|
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;
|
|
79
42
|
};
|
|
43
|
+
get: () => T;
|
|
80
44
|
};
|
|
81
|
-
/**
|
|
82
|
-
* process.stdout.write('msg')
|
|
83
|
-
* process.stdout.clearLine(0)
|
|
84
|
-
*/
|
|
85
|
-
type ColorType = keyof typeof colors;
|
|
86
|
-
type MessageType = keyof typeof messages;
|
|
87
|
-
declare function print(msg: string, type?: MessageType): void;
|
|
88
|
-
declare function print(...msg: {
|
|
89
|
-
color?: ColorType;
|
|
90
|
-
value: string;
|
|
91
|
-
}[]): void;
|
|
92
|
-
|
|
93
|
-
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
94
|
-
|
|
95
|
-
declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
|
|
96
|
-
declare function setFromObject<Value, Entry extends {
|
|
97
|
-
set: (name: string, value: Value) => any;
|
|
98
|
-
}>(entry: Entry, obj: Record<string, Value>, format?: (name: string, value: Value, index: number) => [string, Value]): Entry;
|
|
99
45
|
|
|
100
|
-
export { cleanText,
|
|
46
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,100 +1,46 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
|
+
export { default as naturalCompare } from 'natural-compare';
|
|
2
3
|
|
|
3
4
|
declare const isArray: (arg: any) => arg is any[];
|
|
4
5
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
6
|
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
6
7
|
|
|
7
|
-
declare function
|
|
8
|
-
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @description min <= result < max
|
|
12
|
-
*/
|
|
13
|
-
declare function random(max: number, min?: number): number;
|
|
8
|
+
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
14
9
|
|
|
15
|
-
declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly bgBlack: "\u001B[40m";
|
|
48
|
-
/** 背景红色 */
|
|
49
|
-
readonly bgRed: "\u001B[41m";
|
|
50
|
-
/** 背景绿色 */
|
|
51
|
-
readonly bgGreen: "\u001B[42m";
|
|
52
|
-
/** 背景黄色 */
|
|
53
|
-
readonly bgYellow: "\u001B[43m";
|
|
54
|
-
/** 背景蓝色 */
|
|
55
|
-
readonly bgBlue: "\u001B[44m";
|
|
56
|
-
/** 背景品红 */
|
|
57
|
-
readonly bgMagenta: "\u001B[45m";
|
|
58
|
-
/** 背景青色 */
|
|
59
|
-
readonly bgCyan: "\u001B[46m";
|
|
60
|
-
/** 背景白色 */
|
|
61
|
-
readonly bgWhite: "\u001B[47m";
|
|
62
|
-
};
|
|
63
|
-
declare const messages: {
|
|
64
|
-
readonly info: {
|
|
65
|
-
readonly color: "\u001B[34m";
|
|
66
|
-
readonly symbol: "𝓲";
|
|
67
|
-
};
|
|
68
|
-
readonly warn: {
|
|
69
|
-
readonly color: "\u001B[33m";
|
|
70
|
-
readonly symbol: "𝓲";
|
|
71
|
-
};
|
|
72
|
-
readonly success: {
|
|
73
|
-
readonly color: "\u001B[32m";
|
|
74
|
-
readonly symbol: "✔︎";
|
|
75
|
-
};
|
|
76
|
-
readonly error: {
|
|
77
|
-
readonly color: "\u001B[31m";
|
|
78
|
-
readonly symbol: "✘";
|
|
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;
|
|
79
42
|
};
|
|
43
|
+
get: () => T;
|
|
80
44
|
};
|
|
81
|
-
/**
|
|
82
|
-
* process.stdout.write('msg')
|
|
83
|
-
* process.stdout.clearLine(0)
|
|
84
|
-
*/
|
|
85
|
-
type ColorType = keyof typeof colors;
|
|
86
|
-
type MessageType = keyof typeof messages;
|
|
87
|
-
declare function print(msg: string, type?: MessageType): void;
|
|
88
|
-
declare function print(...msg: {
|
|
89
|
-
color?: ColorType;
|
|
90
|
-
value: string;
|
|
91
|
-
}[]): void;
|
|
92
|
-
|
|
93
|
-
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
94
|
-
|
|
95
|
-
declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
|
|
96
|
-
declare function setFromObject<Value, Entry extends {
|
|
97
|
-
set: (name: string, value: Value) => any;
|
|
98
|
-
}>(entry: Entry, obj: Record<string, Value>, format?: (name: string, value: Value, index: number) => [string, Value]): Entry;
|
|
99
45
|
|
|
100
|
-
export { cleanText,
|
|
46
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,100 +1,46 @@
|
|
|
1
1
|
export * from '@antfu/utils';
|
|
2
|
+
export { default as naturalCompare } from 'natural-compare';
|
|
2
3
|
|
|
3
4
|
declare const isArray: (arg: any) => arg is any[];
|
|
4
5
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
5
6
|
declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
|
|
6
7
|
|
|
7
|
-
declare function
|
|
8
|
-
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @description min <= result < max
|
|
12
|
-
*/
|
|
13
|
-
declare function random(max: number, min?: number): number;
|
|
8
|
+
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
14
9
|
|
|
15
|
-
declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly bgBlack: "\u001B[40m";
|
|
48
|
-
/** 背景红色 */
|
|
49
|
-
readonly bgRed: "\u001B[41m";
|
|
50
|
-
/** 背景绿色 */
|
|
51
|
-
readonly bgGreen: "\u001B[42m";
|
|
52
|
-
/** 背景黄色 */
|
|
53
|
-
readonly bgYellow: "\u001B[43m";
|
|
54
|
-
/** 背景蓝色 */
|
|
55
|
-
readonly bgBlue: "\u001B[44m";
|
|
56
|
-
/** 背景品红 */
|
|
57
|
-
readonly bgMagenta: "\u001B[45m";
|
|
58
|
-
/** 背景青色 */
|
|
59
|
-
readonly bgCyan: "\u001B[46m";
|
|
60
|
-
/** 背景白色 */
|
|
61
|
-
readonly bgWhite: "\u001B[47m";
|
|
62
|
-
};
|
|
63
|
-
declare const messages: {
|
|
64
|
-
readonly info: {
|
|
65
|
-
readonly color: "\u001B[34m";
|
|
66
|
-
readonly symbol: "𝓲";
|
|
67
|
-
};
|
|
68
|
-
readonly warn: {
|
|
69
|
-
readonly color: "\u001B[33m";
|
|
70
|
-
readonly symbol: "𝓲";
|
|
71
|
-
};
|
|
72
|
-
readonly success: {
|
|
73
|
-
readonly color: "\u001B[32m";
|
|
74
|
-
readonly symbol: "✔︎";
|
|
75
|
-
};
|
|
76
|
-
readonly error: {
|
|
77
|
-
readonly color: "\u001B[31m";
|
|
78
|
-
readonly symbol: "✘";
|
|
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;
|
|
79
42
|
};
|
|
43
|
+
get: () => T;
|
|
80
44
|
};
|
|
81
|
-
/**
|
|
82
|
-
* process.stdout.write('msg')
|
|
83
|
-
* process.stdout.clearLine(0)
|
|
84
|
-
*/
|
|
85
|
-
type ColorType = keyof typeof colors;
|
|
86
|
-
type MessageType = keyof typeof messages;
|
|
87
|
-
declare function print(msg: string, type?: MessageType): void;
|
|
88
|
-
declare function print(...msg: {
|
|
89
|
-
color?: ColorType;
|
|
90
|
-
value: string;
|
|
91
|
-
}[]): void;
|
|
92
|
-
|
|
93
|
-
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
94
|
-
|
|
95
|
-
declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
|
|
96
|
-
declare function setFromObject<Value, Entry extends {
|
|
97
|
-
set: (name: string, value: Value) => any;
|
|
98
|
-
}>(entry: Entry, obj: Record<string, Value>, format?: (name: string, value: Value, index: number) => [string, Value]): Entry;
|
|
99
45
|
|
|
100
|
-
export { cleanText,
|
|
46
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isString } from '@antfu/utils';
|
|
2
1
|
export * from '@antfu/utils';
|
|
2
|
+
export { default as naturalCompare } from 'natural-compare';
|
|
3
3
|
|
|
4
4
|
const isArray = Array.isArray;
|
|
5
5
|
function singleOrNull(arr) {
|
|
@@ -9,87 +9,6 @@ function createArray(length, mapFn) {
|
|
|
9
9
|
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function transform(value, fn) {
|
|
13
|
-
return fn(value);
|
|
14
|
-
}
|
|
15
|
-
function safe(fn) {
|
|
16
|
-
try {
|
|
17
|
-
const res = fn();
|
|
18
|
-
return res instanceof Promise ? res.catch(() => null) : res;
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function random(max, min = 0) {
|
|
25
|
-
return Math.floor(Math.random() * max) + min;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const colors = {
|
|
29
|
-
/** 重置颜色 */
|
|
30
|
-
reset: "\x1B[0m",
|
|
31
|
-
/** 亮色(加粗) */
|
|
32
|
-
bright: "\x1B[1m",
|
|
33
|
-
/** 斜体 */
|
|
34
|
-
italic: "\x1B[3m",
|
|
35
|
-
/** 下划线 */
|
|
36
|
-
underline: "\x1B[4m",
|
|
37
|
-
/** 反向 */
|
|
38
|
-
reverse: "\x1B[7m",
|
|
39
|
-
/** 隐藏 */
|
|
40
|
-
hidden: "\x1B[8m",
|
|
41
|
-
/** 灰色 */
|
|
42
|
-
grey: "\x1B[2m",
|
|
43
|
-
/** 黑色 */
|
|
44
|
-
black: "\x1B[30m",
|
|
45
|
-
/** 红色 */
|
|
46
|
-
red: "\x1B[31m",
|
|
47
|
-
/** 绿色 */
|
|
48
|
-
green: "\x1B[32m",
|
|
49
|
-
/** 黄色 */
|
|
50
|
-
yellow: "\x1B[33m",
|
|
51
|
-
/** 蓝色 */
|
|
52
|
-
blue: "\x1B[34m",
|
|
53
|
-
/** 品红 */
|
|
54
|
-
magenta: "\x1B[35m",
|
|
55
|
-
/** 青色 */
|
|
56
|
-
cyan: "\x1B[36m",
|
|
57
|
-
/** 白色 */
|
|
58
|
-
white: "\x1B[37m",
|
|
59
|
-
/** 背景黑色 */
|
|
60
|
-
bgBlack: "\x1B[40m",
|
|
61
|
-
/** 背景红色 */
|
|
62
|
-
bgRed: "\x1B[41m",
|
|
63
|
-
/** 背景绿色 */
|
|
64
|
-
bgGreen: "\x1B[42m",
|
|
65
|
-
/** 背景黄色 */
|
|
66
|
-
bgYellow: "\x1B[43m",
|
|
67
|
-
/** 背景蓝色 */
|
|
68
|
-
bgBlue: "\x1B[44m",
|
|
69
|
-
/** 背景品红 */
|
|
70
|
-
bgMagenta: "\x1B[45m",
|
|
71
|
-
/** 背景青色 */
|
|
72
|
-
bgCyan: "\x1B[46m",
|
|
73
|
-
/** 背景白色 */
|
|
74
|
-
bgWhite: "\x1B[47m"
|
|
75
|
-
};
|
|
76
|
-
const messages = {
|
|
77
|
-
info: { color: colors.blue, symbol: "\u{1D4F2}" },
|
|
78
|
-
warn: { color: colors.yellow, symbol: "\u{1D4F2}" },
|
|
79
|
-
success: { color: colors.green, symbol: "\u2714\uFE0E" },
|
|
80
|
-
error: { color: colors.red, symbol: "\u2718" }
|
|
81
|
-
};
|
|
82
|
-
function print(...args) {
|
|
83
|
-
if (!args.length)
|
|
84
|
-
return;
|
|
85
|
-
if (isString(args[0])) {
|
|
86
|
-
const [msg, type = "info"] = args;
|
|
87
|
-
console.log(`${messages[type].color}${messages[type].symbol} ${colors.grey}${msg}${colors.reset}`);
|
|
88
|
-
}
|
|
89
|
-
let text = args.map((it) => `${it.color ? colors[it.color] : ""}${it.value}`).join("");
|
|
90
|
-
console.log(`${text}${colors.reset}`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
12
|
function cleanText(str, searchValue) {
|
|
94
13
|
return str.replace(searchValue, "");
|
|
95
14
|
}
|
|
@@ -97,12 +16,11 @@ function cleanText(str, searchValue) {
|
|
|
97
16
|
function getValueOrUndefined(condition, value) {
|
|
98
17
|
return condition ? value : void 0;
|
|
99
18
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
return entry;
|
|
19
|
+
function from(value) {
|
|
20
|
+
return {
|
|
21
|
+
to: (fn) => from(fn(value)),
|
|
22
|
+
get: () => value
|
|
23
|
+
};
|
|
106
24
|
}
|
|
107
25
|
|
|
108
|
-
export { cleanText,
|
|
26
|
+
export { cleanText, createArray, from, getValueOrUndefined, isArray, 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.3",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <hi@zhaojiakun.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
18
|
"import": "./dist/index.mjs",
|
|
20
|
-
"require": "./dist/index.cjs"
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"main": "./dist/index.cjs",
|
|
@@ -27,19 +27,23 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@antfu/utils": "^9.
|
|
30
|
+
"@antfu/utils": "^9.2.0",
|
|
31
|
+
"natural-compare": "^1.4.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@types/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
34
|
+
"@jiakun-zhao/eslint-config": "^4.1.8",
|
|
35
|
+
"@types/natural-compare": "^1.4.3",
|
|
36
|
+
"@types/node": "^24.0.3",
|
|
37
|
+
"bumpp": "^10.2.0",
|
|
38
|
+
"eslint": "^9.29.0",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"unbuild": "^3.5.0",
|
|
41
|
+
"vitest": "^3.2.4"
|
|
39
42
|
},
|
|
40
43
|
"scripts": {
|
|
41
44
|
"build": "unbuild",
|
|
45
|
+
"release": "bumpp && pnpm publish && npx cnpm sync @jiakun-zhao/utils",
|
|
42
46
|
"stub": "unbuild --stub",
|
|
43
|
-
"
|
|
47
|
+
"test": "vitest"
|
|
44
48
|
}
|
|
45
49
|
}
|