@jiakun-zhao/utils 1.3.1 → 1.3.2
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 +0 -79
- package/dist/index.d.cts +2 -84
- package/dist/index.d.mts +2 -84
- package/dist/index.d.ts +2 -84
- package/dist/index.mjs +1 -77
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -10,9 +10,6 @@ function createArray(length, mapFn) {
|
|
|
10
10
|
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function transform(value, fn) {
|
|
14
|
-
return fn(value);
|
|
15
|
-
}
|
|
16
13
|
function safe(fn) {
|
|
17
14
|
try {
|
|
18
15
|
const res = fn();
|
|
@@ -26,71 +23,6 @@ function random(max, min = 0) {
|
|
|
26
23
|
return Math.floor(Math.random() * max) + min;
|
|
27
24
|
}
|
|
28
25
|
|
|
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
26
|
function cleanText(str, searchValue) {
|
|
95
27
|
return str.replace(searchValue, "");
|
|
96
28
|
}
|
|
@@ -98,25 +30,14 @@ function cleanText(str, searchValue) {
|
|
|
98
30
|
function getValueOrUndefined(condition, value) {
|
|
99
31
|
return condition ? value : void 0;
|
|
100
32
|
}
|
|
101
|
-
function setFromObject(entry, obj, format) {
|
|
102
|
-
Object.entries(obj).forEach(([name, value], index) => {
|
|
103
|
-
const [_name, _value] = format?.(name, value, index) ?? [name, value];
|
|
104
|
-
entry.set(_name, _value);
|
|
105
|
-
});
|
|
106
|
-
return entry;
|
|
107
|
-
}
|
|
108
33
|
|
|
109
34
|
exports.cleanText = cleanText;
|
|
110
|
-
exports.colors = colors;
|
|
111
35
|
exports.createArray = createArray;
|
|
112
36
|
exports.getValueOrUndefined = getValueOrUndefined;
|
|
113
37
|
exports.isArray = isArray;
|
|
114
|
-
exports.print = print;
|
|
115
38
|
exports.random = random;
|
|
116
39
|
exports.safe = safe;
|
|
117
|
-
exports.setFromObject = setFromObject;
|
|
118
40
|
exports.singleOrNull = singleOrNull;
|
|
119
|
-
exports.transform = transform;
|
|
120
41
|
Object.prototype.hasOwnProperty.call(utils, '__proto__') &&
|
|
121
42
|
!Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
|
|
122
43
|
Object.defineProperty(exports, '__proto__', {
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,6 @@ 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 transform<T, R = void>(value: T, fn: (it: T) => R): R;
|
|
8
7
|
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -12,89 +11,8 @@ declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T>
|
|
|
12
11
|
*/
|
|
13
12
|
declare function random(max: number, min?: number): number;
|
|
14
13
|
|
|
15
|
-
declare const colors: {
|
|
16
|
-
/** 重置颜色 */
|
|
17
|
-
readonly reset: "\u001B[0m";
|
|
18
|
-
/** 亮色(加粗) */
|
|
19
|
-
readonly bright: "\u001B[1m";
|
|
20
|
-
/** 斜体 */
|
|
21
|
-
readonly italic: "\u001B[3m";
|
|
22
|
-
/** 下划线 */
|
|
23
|
-
readonly underline: "\u001B[4m";
|
|
24
|
-
/** 反向 */
|
|
25
|
-
readonly reverse: "\u001B[7m";
|
|
26
|
-
/** 隐藏 */
|
|
27
|
-
readonly hidden: "\u001B[8m";
|
|
28
|
-
/** 灰色 */
|
|
29
|
-
readonly grey: "\u001B[2m";
|
|
30
|
-
/** 黑色 */
|
|
31
|
-
readonly black: "\u001B[30m";
|
|
32
|
-
/** 红色 */
|
|
33
|
-
readonly red: "\u001B[31m";
|
|
34
|
-
/** 绿色 */
|
|
35
|
-
readonly green: "\u001B[32m";
|
|
36
|
-
/** 黄色 */
|
|
37
|
-
readonly yellow: "\u001B[33m";
|
|
38
|
-
/** 蓝色 */
|
|
39
|
-
readonly blue: "\u001B[34m";
|
|
40
|
-
/** 品红 */
|
|
41
|
-
readonly magenta: "\u001B[35m";
|
|
42
|
-
/** 青色 */
|
|
43
|
-
readonly cyan: "\u001B[36m";
|
|
44
|
-
/** 白色 */
|
|
45
|
-
readonly white: "\u001B[37m";
|
|
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: "✘";
|
|
79
|
-
};
|
|
80
|
-
};
|
|
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
14
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
94
15
|
|
|
95
|
-
declare function getValueOrUndefined<T>(condition:
|
|
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;
|
|
16
|
+
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
99
17
|
|
|
100
|
-
export { cleanText,
|
|
18
|
+
export { cleanText, createArray, getValueOrUndefined, isArray, random, safe, singleOrNull };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,6 @@ 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 transform<T, R = void>(value: T, fn: (it: T) => R): R;
|
|
8
7
|
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -12,89 +11,8 @@ declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T>
|
|
|
12
11
|
*/
|
|
13
12
|
declare function random(max: number, min?: number): number;
|
|
14
13
|
|
|
15
|
-
declare const colors: {
|
|
16
|
-
/** 重置颜色 */
|
|
17
|
-
readonly reset: "\u001B[0m";
|
|
18
|
-
/** 亮色(加粗) */
|
|
19
|
-
readonly bright: "\u001B[1m";
|
|
20
|
-
/** 斜体 */
|
|
21
|
-
readonly italic: "\u001B[3m";
|
|
22
|
-
/** 下划线 */
|
|
23
|
-
readonly underline: "\u001B[4m";
|
|
24
|
-
/** 反向 */
|
|
25
|
-
readonly reverse: "\u001B[7m";
|
|
26
|
-
/** 隐藏 */
|
|
27
|
-
readonly hidden: "\u001B[8m";
|
|
28
|
-
/** 灰色 */
|
|
29
|
-
readonly grey: "\u001B[2m";
|
|
30
|
-
/** 黑色 */
|
|
31
|
-
readonly black: "\u001B[30m";
|
|
32
|
-
/** 红色 */
|
|
33
|
-
readonly red: "\u001B[31m";
|
|
34
|
-
/** 绿色 */
|
|
35
|
-
readonly green: "\u001B[32m";
|
|
36
|
-
/** 黄色 */
|
|
37
|
-
readonly yellow: "\u001B[33m";
|
|
38
|
-
/** 蓝色 */
|
|
39
|
-
readonly blue: "\u001B[34m";
|
|
40
|
-
/** 品红 */
|
|
41
|
-
readonly magenta: "\u001B[35m";
|
|
42
|
-
/** 青色 */
|
|
43
|
-
readonly cyan: "\u001B[36m";
|
|
44
|
-
/** 白色 */
|
|
45
|
-
readonly white: "\u001B[37m";
|
|
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: "✘";
|
|
79
|
-
};
|
|
80
|
-
};
|
|
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
14
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
94
15
|
|
|
95
|
-
declare function getValueOrUndefined<T>(condition:
|
|
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;
|
|
16
|
+
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
99
17
|
|
|
100
|
-
export { cleanText,
|
|
18
|
+
export { cleanText, createArray, getValueOrUndefined, isArray, random, safe, singleOrNull };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ 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 transform<T, R = void>(value: T, fn: (it: T) => R): R;
|
|
8
7
|
declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T> ? Promise<T | null> : (R | null);
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -12,89 +11,8 @@ declare function safe<R>(fn: () => R): typeof fn extends () => Promise<infer T>
|
|
|
12
11
|
*/
|
|
13
12
|
declare function random(max: number, min?: number): number;
|
|
14
13
|
|
|
15
|
-
declare const colors: {
|
|
16
|
-
/** 重置颜色 */
|
|
17
|
-
readonly reset: "\u001B[0m";
|
|
18
|
-
/** 亮色(加粗) */
|
|
19
|
-
readonly bright: "\u001B[1m";
|
|
20
|
-
/** 斜体 */
|
|
21
|
-
readonly italic: "\u001B[3m";
|
|
22
|
-
/** 下划线 */
|
|
23
|
-
readonly underline: "\u001B[4m";
|
|
24
|
-
/** 反向 */
|
|
25
|
-
readonly reverse: "\u001B[7m";
|
|
26
|
-
/** 隐藏 */
|
|
27
|
-
readonly hidden: "\u001B[8m";
|
|
28
|
-
/** 灰色 */
|
|
29
|
-
readonly grey: "\u001B[2m";
|
|
30
|
-
/** 黑色 */
|
|
31
|
-
readonly black: "\u001B[30m";
|
|
32
|
-
/** 红色 */
|
|
33
|
-
readonly red: "\u001B[31m";
|
|
34
|
-
/** 绿色 */
|
|
35
|
-
readonly green: "\u001B[32m";
|
|
36
|
-
/** 黄色 */
|
|
37
|
-
readonly yellow: "\u001B[33m";
|
|
38
|
-
/** 蓝色 */
|
|
39
|
-
readonly blue: "\u001B[34m";
|
|
40
|
-
/** 品红 */
|
|
41
|
-
readonly magenta: "\u001B[35m";
|
|
42
|
-
/** 青色 */
|
|
43
|
-
readonly cyan: "\u001B[36m";
|
|
44
|
-
/** 白色 */
|
|
45
|
-
readonly white: "\u001B[37m";
|
|
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: "✘";
|
|
79
|
-
};
|
|
80
|
-
};
|
|
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
14
|
declare function cleanText(str: string, searchValue: RegExp | string): string;
|
|
94
15
|
|
|
95
|
-
declare function getValueOrUndefined<T>(condition:
|
|
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;
|
|
16
|
+
declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
|
|
99
17
|
|
|
100
|
-
export { cleanText,
|
|
18
|
+
export { cleanText, createArray, getValueOrUndefined, isArray, random, safe, singleOrNull };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isString } from '@antfu/utils';
|
|
2
1
|
export * from '@antfu/utils';
|
|
3
2
|
|
|
4
3
|
const isArray = Array.isArray;
|
|
@@ -9,9 +8,6 @@ function createArray(length, mapFn) {
|
|
|
9
8
|
return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
function transform(value, fn) {
|
|
13
|
-
return fn(value);
|
|
14
|
-
}
|
|
15
11
|
function safe(fn) {
|
|
16
12
|
try {
|
|
17
13
|
const res = fn();
|
|
@@ -25,71 +21,6 @@ function random(max, min = 0) {
|
|
|
25
21
|
return Math.floor(Math.random() * max) + min;
|
|
26
22
|
}
|
|
27
23
|
|
|
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
24
|
function cleanText(str, searchValue) {
|
|
94
25
|
return str.replace(searchValue, "");
|
|
95
26
|
}
|
|
@@ -97,12 +28,5 @@ function cleanText(str, searchValue) {
|
|
|
97
28
|
function getValueOrUndefined(condition, value) {
|
|
98
29
|
return condition ? value : void 0;
|
|
99
30
|
}
|
|
100
|
-
function setFromObject(entry, obj, format) {
|
|
101
|
-
Object.entries(obj).forEach(([name, value], index) => {
|
|
102
|
-
const [_name, _value] = format?.(name, value, index) ?? [name, value];
|
|
103
|
-
entry.set(_name, _value);
|
|
104
|
-
});
|
|
105
|
-
return entry;
|
|
106
|
-
}
|
|
107
31
|
|
|
108
|
-
export { cleanText,
|
|
32
|
+
export { cleanText, createArray, getValueOrUndefined, isArray, random, safe, 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.2",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <hi@zhaojiakun.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@antfu/utils": "^9.
|
|
30
|
+
"@antfu/utils": "^9.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@antfu/eslint-config": "^4.
|
|
34
|
-
"@types/node": "^22.
|
|
35
|
-
"bumpp": "^10.0
|
|
36
|
-
"eslint": "^9.
|
|
37
|
-
"typescript": "^5.8.
|
|
33
|
+
"@antfu/eslint-config": "^4.12.0",
|
|
34
|
+
"@types/node": "^22.15.3",
|
|
35
|
+
"bumpp": "^10.1.0",
|
|
36
|
+
"eslint": "^9.25.1",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
38
|
"unbuild": "^3.5.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|