@jiakun-zhao/utils 1.1.2 → 1.2.0
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/README.md +0 -1
- package/dist/index.cjs +7 -38
- package/dist/index.d.cts +4 -74
- package/dist/index.d.mts +4 -74
- package/dist/index.d.ts +4 -74
- package/dist/index.mjs +4 -23
- package/package.json +9 -20
- package/dist/fs.cjs +0 -45
- package/dist/fs.d.cts +0 -10
- package/dist/fs.d.mts +0 -10
- package/dist/fs.d.ts +0 -10
- package/dist/fs.mjs +0 -33
- package/fs.d.ts +0 -2
- package/index.d.ts +0 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const isBoolean = (val) => typeof val === "boolean";
|
|
5
|
-
const isNumber = (val) => typeof val === "number";
|
|
6
|
-
const isString = (val) => typeof val === "string";
|
|
7
|
-
const toString = (value) => Object.prototype.toString.call(value);
|
|
8
|
-
const isObject = (val) => toString(val) === "[object Object]";
|
|
9
|
-
const isUndefined = (val) => toString(val) === "[object Undefined]";
|
|
10
|
-
const isNull = (val) => toString(val) === "[object Null]";
|
|
11
|
-
const isRegExp = (val) => toString(val) === "[object RegExp]";
|
|
12
|
-
const isDate = (val) => toString(val) === "[object Date]";
|
|
13
|
-
const isArray = Array.isArray;
|
|
14
|
-
const notNullish = (v) => v != null;
|
|
15
|
-
const notNull = (v) => v !== null;
|
|
16
|
-
const notUndefined = (v) => v !== void 0;
|
|
3
|
+
const utils = require('@antfu/utils');
|
|
17
4
|
|
|
18
5
|
function singleOrNull(arr) {
|
|
19
6
|
return arr.length === 1 ? arr[0] : null;
|
|
20
7
|
}
|
|
21
|
-
function toArray(array) {
|
|
22
|
-
array = array ?? [];
|
|
23
|
-
return isArray(array) ? array : [array];
|
|
24
|
-
}
|
|
25
8
|
|
|
26
|
-
function
|
|
9
|
+
function transform(value, fn) {
|
|
27
10
|
return fn(value);
|
|
28
11
|
}
|
|
29
|
-
function takeIf(value, predicate, defaultValue) {
|
|
30
|
-
return predicate(value) ? value : notUndefined(defaultValue) ? defaultValue : null;
|
|
31
|
-
}
|
|
32
12
|
function safe(fn) {
|
|
33
13
|
try {
|
|
34
14
|
return fn();
|
|
@@ -102,26 +82,15 @@ function print(msg, type) {
|
|
|
102
82
|
}
|
|
103
83
|
|
|
104
84
|
const timestamp = () => +Date.now();
|
|
85
|
+
const isArray = Array.isArray;
|
|
105
86
|
|
|
106
|
-
exports.colors = colors;
|
|
107
87
|
exports.isArray = isArray;
|
|
108
|
-
exports.isBoolean = isBoolean;
|
|
109
|
-
exports.isDate = isDate;
|
|
110
|
-
exports.isFunction = isFunction;
|
|
111
|
-
exports.isNull = isNull;
|
|
112
|
-
exports.isNumber = isNumber;
|
|
113
|
-
exports.isObject = isObject;
|
|
114
|
-
exports.isRegExp = isRegExp;
|
|
115
|
-
exports.isString = isString;
|
|
116
|
-
exports.isUndefined = isUndefined;
|
|
117
|
-
exports.notNull = notNull;
|
|
118
|
-
exports.notNullish = notNullish;
|
|
119
|
-
exports.notUndefined = notUndefined;
|
|
120
88
|
exports.print = print;
|
|
121
89
|
exports.random = random;
|
|
122
90
|
exports.safe = safe;
|
|
123
91
|
exports.singleOrNull = singleOrNull;
|
|
124
|
-
exports.take = take;
|
|
125
|
-
exports.takeIf = takeIf;
|
|
126
92
|
exports.timestamp = timestamp;
|
|
127
|
-
exports.
|
|
93
|
+
exports.transform = transform;
|
|
94
|
+
Object.keys(utils).forEach(function (k) {
|
|
95
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
|
|
96
|
+
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,86 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
type NotNullable<T> = Exclude<T, null | undefined>;
|
|
3
|
-
type NotNull<T> = Exclude<T, null>;
|
|
4
|
-
type NotUndefined<T> = Exclude<T, undefined>;
|
|
5
|
-
type Arrayable<T> = T | Array<T>;
|
|
6
|
-
type ElementOf<T> = T extends Array<infer Element> ? Element : never;
|
|
7
|
-
type Fn<R = void> = (...args: any[]) => R;
|
|
1
|
+
export * from '@antfu/utils';
|
|
8
2
|
|
|
9
3
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
10
|
-
declare function toArray<T>(array?: T | Array<T>): Array<T>;
|
|
11
4
|
|
|
12
|
-
declare function
|
|
13
|
-
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
14
|
-
declare function takeIf<T>(value: T, predicate: (it: T) => boolean, defaultValue: T): T;
|
|
5
|
+
declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
|
|
15
6
|
declare function safe<R>(fn: () => R): R | undefined;
|
|
16
7
|
|
|
17
|
-
declare const isFunction: (val: any) => val is Fn;
|
|
18
|
-
declare const isBoolean: (val: any) => val is boolean;
|
|
19
|
-
declare const isNumber: (val: any) => val is number;
|
|
20
|
-
declare const isString: (val: unknown) => val is string;
|
|
21
|
-
declare const isObject: (val: any) => val is object;
|
|
22
|
-
declare const isUndefined: (val: any) => val is undefined;
|
|
23
|
-
declare const isNull: (val: any) => val is null;
|
|
24
|
-
declare const isRegExp: (val: any) => val is RegExp;
|
|
25
|
-
declare const isDate: (val: any) => val is Date;
|
|
26
|
-
declare const isArray: (arg: any) => arg is any[];
|
|
27
|
-
declare const notNullish: <T>(v: T | null | undefined) => v is NonNullable<T>;
|
|
28
|
-
declare const notNull: <T>(v: T | null) => v is Exclude<T, null>;
|
|
29
|
-
declare const notUndefined: <T>(v: T | undefined) => v is Exclude<T, undefined>;
|
|
30
|
-
|
|
31
8
|
/**
|
|
32
9
|
* @description min <= result < max
|
|
33
10
|
*/
|
|
34
11
|
declare function random(max: number, min?: number): number;
|
|
35
12
|
|
|
36
|
-
declare const colors: {
|
|
37
|
-
/** 重置颜色 */
|
|
38
|
-
reset: string;
|
|
39
|
-
/** 亮色(加粗) */
|
|
40
|
-
bright: string;
|
|
41
|
-
/** 斜体 */
|
|
42
|
-
italic: string;
|
|
43
|
-
/** 下划线 */
|
|
44
|
-
underline: string;
|
|
45
|
-
/** 反向 */
|
|
46
|
-
reverse: string;
|
|
47
|
-
/** 隐藏 */
|
|
48
|
-
hidden: string;
|
|
49
|
-
/** 灰色 */
|
|
50
|
-
grey: string;
|
|
51
|
-
/** 黑色 */
|
|
52
|
-
black: string;
|
|
53
|
-
/** 红色 */
|
|
54
|
-
red: string;
|
|
55
|
-
/** 绿色 */
|
|
56
|
-
green: string;
|
|
57
|
-
/** 黄色 */
|
|
58
|
-
yellow: string;
|
|
59
|
-
/** 蓝色 */
|
|
60
|
-
blue: string;
|
|
61
|
-
/** 品红 */
|
|
62
|
-
magenta: string;
|
|
63
|
-
/** 青色 */
|
|
64
|
-
cyan: string;
|
|
65
|
-
/** 白色 */
|
|
66
|
-
white: string;
|
|
67
|
-
/** 背景黑色 */
|
|
68
|
-
bgBlack: string;
|
|
69
|
-
/** 背景红色 */
|
|
70
|
-
bgRed: string;
|
|
71
|
-
/** 背景绿色 */
|
|
72
|
-
bgGreen: string;
|
|
73
|
-
/** 背景黄色 */
|
|
74
|
-
bgYellow: string;
|
|
75
|
-
/** 背景蓝色 */
|
|
76
|
-
bgBlue: string;
|
|
77
|
-
/** 背景品红 */
|
|
78
|
-
bgMagenta: string;
|
|
79
|
-
/** 背景青色 */
|
|
80
|
-
bgCyan: string;
|
|
81
|
-
/** 背景白色 */
|
|
82
|
-
bgWhite: string;
|
|
83
|
-
};
|
|
84
13
|
declare const map: {
|
|
85
14
|
info: {
|
|
86
15
|
color: string;
|
|
@@ -106,5 +35,6 @@ declare const map: {
|
|
|
106
35
|
declare function print(msg: any, type?: keyof typeof map): void;
|
|
107
36
|
|
|
108
37
|
declare const timestamp: () => number;
|
|
38
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
109
39
|
|
|
110
|
-
export {
|
|
40
|
+
export { isArray, print, random, safe, singleOrNull, timestamp, transform };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,86 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
type NotNullable<T> = Exclude<T, null | undefined>;
|
|
3
|
-
type NotNull<T> = Exclude<T, null>;
|
|
4
|
-
type NotUndefined<T> = Exclude<T, undefined>;
|
|
5
|
-
type Arrayable<T> = T | Array<T>;
|
|
6
|
-
type ElementOf<T> = T extends Array<infer Element> ? Element : never;
|
|
7
|
-
type Fn<R = void> = (...args: any[]) => R;
|
|
1
|
+
export * from '@antfu/utils';
|
|
8
2
|
|
|
9
3
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
10
|
-
declare function toArray<T>(array?: T | Array<T>): Array<T>;
|
|
11
4
|
|
|
12
|
-
declare function
|
|
13
|
-
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
14
|
-
declare function takeIf<T>(value: T, predicate: (it: T) => boolean, defaultValue: T): T;
|
|
5
|
+
declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
|
|
15
6
|
declare function safe<R>(fn: () => R): R | undefined;
|
|
16
7
|
|
|
17
|
-
declare const isFunction: (val: any) => val is Fn;
|
|
18
|
-
declare const isBoolean: (val: any) => val is boolean;
|
|
19
|
-
declare const isNumber: (val: any) => val is number;
|
|
20
|
-
declare const isString: (val: unknown) => val is string;
|
|
21
|
-
declare const isObject: (val: any) => val is object;
|
|
22
|
-
declare const isUndefined: (val: any) => val is undefined;
|
|
23
|
-
declare const isNull: (val: any) => val is null;
|
|
24
|
-
declare const isRegExp: (val: any) => val is RegExp;
|
|
25
|
-
declare const isDate: (val: any) => val is Date;
|
|
26
|
-
declare const isArray: (arg: any) => arg is any[];
|
|
27
|
-
declare const notNullish: <T>(v: T | null | undefined) => v is NonNullable<T>;
|
|
28
|
-
declare const notNull: <T>(v: T | null) => v is Exclude<T, null>;
|
|
29
|
-
declare const notUndefined: <T>(v: T | undefined) => v is Exclude<T, undefined>;
|
|
30
|
-
|
|
31
8
|
/**
|
|
32
9
|
* @description min <= result < max
|
|
33
10
|
*/
|
|
34
11
|
declare function random(max: number, min?: number): number;
|
|
35
12
|
|
|
36
|
-
declare const colors: {
|
|
37
|
-
/** 重置颜色 */
|
|
38
|
-
reset: string;
|
|
39
|
-
/** 亮色(加粗) */
|
|
40
|
-
bright: string;
|
|
41
|
-
/** 斜体 */
|
|
42
|
-
italic: string;
|
|
43
|
-
/** 下划线 */
|
|
44
|
-
underline: string;
|
|
45
|
-
/** 反向 */
|
|
46
|
-
reverse: string;
|
|
47
|
-
/** 隐藏 */
|
|
48
|
-
hidden: string;
|
|
49
|
-
/** 灰色 */
|
|
50
|
-
grey: string;
|
|
51
|
-
/** 黑色 */
|
|
52
|
-
black: string;
|
|
53
|
-
/** 红色 */
|
|
54
|
-
red: string;
|
|
55
|
-
/** 绿色 */
|
|
56
|
-
green: string;
|
|
57
|
-
/** 黄色 */
|
|
58
|
-
yellow: string;
|
|
59
|
-
/** 蓝色 */
|
|
60
|
-
blue: string;
|
|
61
|
-
/** 品红 */
|
|
62
|
-
magenta: string;
|
|
63
|
-
/** 青色 */
|
|
64
|
-
cyan: string;
|
|
65
|
-
/** 白色 */
|
|
66
|
-
white: string;
|
|
67
|
-
/** 背景黑色 */
|
|
68
|
-
bgBlack: string;
|
|
69
|
-
/** 背景红色 */
|
|
70
|
-
bgRed: string;
|
|
71
|
-
/** 背景绿色 */
|
|
72
|
-
bgGreen: string;
|
|
73
|
-
/** 背景黄色 */
|
|
74
|
-
bgYellow: string;
|
|
75
|
-
/** 背景蓝色 */
|
|
76
|
-
bgBlue: string;
|
|
77
|
-
/** 背景品红 */
|
|
78
|
-
bgMagenta: string;
|
|
79
|
-
/** 背景青色 */
|
|
80
|
-
bgCyan: string;
|
|
81
|
-
/** 背景白色 */
|
|
82
|
-
bgWhite: string;
|
|
83
|
-
};
|
|
84
13
|
declare const map: {
|
|
85
14
|
info: {
|
|
86
15
|
color: string;
|
|
@@ -106,5 +35,6 @@ declare const map: {
|
|
|
106
35
|
declare function print(msg: any, type?: keyof typeof map): void;
|
|
107
36
|
|
|
108
37
|
declare const timestamp: () => number;
|
|
38
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
109
39
|
|
|
110
|
-
export {
|
|
40
|
+
export { isArray, print, random, safe, singleOrNull, timestamp, transform };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,86 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
type NotNullable<T> = Exclude<T, null | undefined>;
|
|
3
|
-
type NotNull<T> = Exclude<T, null>;
|
|
4
|
-
type NotUndefined<T> = Exclude<T, undefined>;
|
|
5
|
-
type Arrayable<T> = T | Array<T>;
|
|
6
|
-
type ElementOf<T> = T extends Array<infer Element> ? Element : never;
|
|
7
|
-
type Fn<R = void> = (...args: any[]) => R;
|
|
1
|
+
export * from '@antfu/utils';
|
|
8
2
|
|
|
9
3
|
declare function singleOrNull<T>(arr: T[]): T | null;
|
|
10
|
-
declare function toArray<T>(array?: T | Array<T>): Array<T>;
|
|
11
4
|
|
|
12
|
-
declare function
|
|
13
|
-
declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
|
|
14
|
-
declare function takeIf<T>(value: T, predicate: (it: T) => boolean, defaultValue: T): T;
|
|
5
|
+
declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
|
|
15
6
|
declare function safe<R>(fn: () => R): R | undefined;
|
|
16
7
|
|
|
17
|
-
declare const isFunction: (val: any) => val is Fn;
|
|
18
|
-
declare const isBoolean: (val: any) => val is boolean;
|
|
19
|
-
declare const isNumber: (val: any) => val is number;
|
|
20
|
-
declare const isString: (val: unknown) => val is string;
|
|
21
|
-
declare const isObject: (val: any) => val is object;
|
|
22
|
-
declare const isUndefined: (val: any) => val is undefined;
|
|
23
|
-
declare const isNull: (val: any) => val is null;
|
|
24
|
-
declare const isRegExp: (val: any) => val is RegExp;
|
|
25
|
-
declare const isDate: (val: any) => val is Date;
|
|
26
|
-
declare const isArray: (arg: any) => arg is any[];
|
|
27
|
-
declare const notNullish: <T>(v: T | null | undefined) => v is NonNullable<T>;
|
|
28
|
-
declare const notNull: <T>(v: T | null) => v is Exclude<T, null>;
|
|
29
|
-
declare const notUndefined: <T>(v: T | undefined) => v is Exclude<T, undefined>;
|
|
30
|
-
|
|
31
8
|
/**
|
|
32
9
|
* @description min <= result < max
|
|
33
10
|
*/
|
|
34
11
|
declare function random(max: number, min?: number): number;
|
|
35
12
|
|
|
36
|
-
declare const colors: {
|
|
37
|
-
/** 重置颜色 */
|
|
38
|
-
reset: string;
|
|
39
|
-
/** 亮色(加粗) */
|
|
40
|
-
bright: string;
|
|
41
|
-
/** 斜体 */
|
|
42
|
-
italic: string;
|
|
43
|
-
/** 下划线 */
|
|
44
|
-
underline: string;
|
|
45
|
-
/** 反向 */
|
|
46
|
-
reverse: string;
|
|
47
|
-
/** 隐藏 */
|
|
48
|
-
hidden: string;
|
|
49
|
-
/** 灰色 */
|
|
50
|
-
grey: string;
|
|
51
|
-
/** 黑色 */
|
|
52
|
-
black: string;
|
|
53
|
-
/** 红色 */
|
|
54
|
-
red: string;
|
|
55
|
-
/** 绿色 */
|
|
56
|
-
green: string;
|
|
57
|
-
/** 黄色 */
|
|
58
|
-
yellow: string;
|
|
59
|
-
/** 蓝色 */
|
|
60
|
-
blue: string;
|
|
61
|
-
/** 品红 */
|
|
62
|
-
magenta: string;
|
|
63
|
-
/** 青色 */
|
|
64
|
-
cyan: string;
|
|
65
|
-
/** 白色 */
|
|
66
|
-
white: string;
|
|
67
|
-
/** 背景黑色 */
|
|
68
|
-
bgBlack: string;
|
|
69
|
-
/** 背景红色 */
|
|
70
|
-
bgRed: string;
|
|
71
|
-
/** 背景绿色 */
|
|
72
|
-
bgGreen: string;
|
|
73
|
-
/** 背景黄色 */
|
|
74
|
-
bgYellow: string;
|
|
75
|
-
/** 背景蓝色 */
|
|
76
|
-
bgBlue: string;
|
|
77
|
-
/** 背景品红 */
|
|
78
|
-
bgMagenta: string;
|
|
79
|
-
/** 背景青色 */
|
|
80
|
-
bgCyan: string;
|
|
81
|
-
/** 背景白色 */
|
|
82
|
-
bgWhite: string;
|
|
83
|
-
};
|
|
84
13
|
declare const map: {
|
|
85
14
|
info: {
|
|
86
15
|
color: string;
|
|
@@ -106,5 +35,6 @@ declare const map: {
|
|
|
106
35
|
declare function print(msg: any, type?: keyof typeof map): void;
|
|
107
36
|
|
|
108
37
|
declare const timestamp: () => number;
|
|
38
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
109
39
|
|
|
110
|
-
export {
|
|
40
|
+
export { isArray, print, random, safe, singleOrNull, timestamp, transform };
|
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
const isBoolean = (val) => typeof val === "boolean";
|
|
3
|
-
const isNumber = (val) => typeof val === "number";
|
|
4
|
-
const isString = (val) => typeof val === "string";
|
|
5
|
-
const toString = (value) => Object.prototype.toString.call(value);
|
|
6
|
-
const isObject = (val) => toString(val) === "[object Object]";
|
|
7
|
-
const isUndefined = (val) => toString(val) === "[object Undefined]";
|
|
8
|
-
const isNull = (val) => toString(val) === "[object Null]";
|
|
9
|
-
const isRegExp = (val) => toString(val) === "[object RegExp]";
|
|
10
|
-
const isDate = (val) => toString(val) === "[object Date]";
|
|
11
|
-
const isArray = Array.isArray;
|
|
12
|
-
const notNullish = (v) => v != null;
|
|
13
|
-
const notNull = (v) => v !== null;
|
|
14
|
-
const notUndefined = (v) => v !== void 0;
|
|
1
|
+
export * from '@antfu/utils';
|
|
15
2
|
|
|
16
3
|
function singleOrNull(arr) {
|
|
17
4
|
return arr.length === 1 ? arr[0] : null;
|
|
18
5
|
}
|
|
19
|
-
function toArray(array) {
|
|
20
|
-
array = array ?? [];
|
|
21
|
-
return isArray(array) ? array : [array];
|
|
22
|
-
}
|
|
23
6
|
|
|
24
|
-
function
|
|
7
|
+
function transform(value, fn) {
|
|
25
8
|
return fn(value);
|
|
26
9
|
}
|
|
27
|
-
function takeIf(value, predicate, defaultValue) {
|
|
28
|
-
return predicate(value) ? value : notUndefined(defaultValue) ? defaultValue : null;
|
|
29
|
-
}
|
|
30
10
|
function safe(fn) {
|
|
31
11
|
try {
|
|
32
12
|
return fn();
|
|
@@ -100,5 +80,6 @@ function print(msg, type) {
|
|
|
100
80
|
}
|
|
101
81
|
|
|
102
82
|
const timestamp = () => +Date.now();
|
|
83
|
+
const isArray = Array.isArray;
|
|
103
84
|
|
|
104
|
-
export {
|
|
85
|
+
export { isArray, print, random, safe, singleOrNull, timestamp, transform };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jiakun-zhao/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"description": "Utils.",
|
|
6
6
|
"author": "Jiakun Zhao <hi@zhaojiakun.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,36 +18,25 @@
|
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
20
|
"require": "./dist/index.cjs"
|
|
21
|
-
},
|
|
22
|
-
"./fs": {
|
|
23
|
-
"types": "./dist/fs.d.ts",
|
|
24
|
-
"import": "./dist/fs.mjs",
|
|
25
|
-
"require": "./dist/fs.cjs"
|
|
26
21
|
}
|
|
27
22
|
},
|
|
28
23
|
"main": "./dist/index.cjs",
|
|
29
24
|
"module": "./dist/index.mjs",
|
|
30
25
|
"types": "./dist/index.d.ts",
|
|
31
26
|
"files": [
|
|
32
|
-
"dist"
|
|
33
|
-
"index.d.ts",
|
|
34
|
-
"fs.d.ts"
|
|
27
|
+
"dist"
|
|
35
28
|
],
|
|
36
29
|
"dependencies": {
|
|
37
|
-
"
|
|
30
|
+
"@antfu/utils": "^0.7.8"
|
|
38
31
|
},
|
|
39
32
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@types/node": "^20.
|
|
42
|
-
"bumpp": "^9.
|
|
43
|
-
"eslint": "^
|
|
44
|
-
"
|
|
45
|
-
"typescript": "^5.3.2",
|
|
33
|
+
"@antfu/eslint-config": "^2.19.0",
|
|
34
|
+
"@types/node": "^20.12.12",
|
|
35
|
+
"bumpp": "^9.4.1",
|
|
36
|
+
"eslint": "^9.3.0",
|
|
37
|
+
"typescript": "^5.4.5",
|
|
46
38
|
"unbuild": "^2.0.0",
|
|
47
|
-
"vitest": "^
|
|
48
|
-
},
|
|
49
|
-
"eslintConfig": {
|
|
50
|
-
"extends": "@jiakun-zhao"
|
|
39
|
+
"vitest": "^1.6.0"
|
|
51
40
|
},
|
|
52
41
|
"scripts": {
|
|
53
42
|
"build": "unbuild",
|
package/dist/fs.cjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_crypto = require('node:crypto');
|
|
4
|
-
const node_fs = require('node:fs');
|
|
5
|
-
const promises = require('node:fs/promises');
|
|
6
|
-
const node_path = require('node:path');
|
|
7
|
-
const fastGlob = require('fast-glob');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
|
-
|
|
11
|
-
const fastGlob__default = /*#__PURE__*/_interopDefaultCompat(fastGlob);
|
|
12
|
-
|
|
13
|
-
async function exists(...path) {
|
|
14
|
-
return await promises.access(node_path.join(...path), promises.constants.F_OK).then(() => true, () => false);
|
|
15
|
-
}
|
|
16
|
-
async function readText(...path) {
|
|
17
|
-
return await promises.readFile(node_path.join(...path), "utf-8");
|
|
18
|
-
}
|
|
19
|
-
async function readJson(...path) {
|
|
20
|
-
return JSON.parse(await readText(...path));
|
|
21
|
-
}
|
|
22
|
-
async function writeText(content, ...path) {
|
|
23
|
-
await promises.writeFile(node_path.join(...path), content, "utf-8");
|
|
24
|
-
}
|
|
25
|
-
async function writeJson(content, ...path) {
|
|
26
|
-
await writeText(`${JSON.stringify(content, null, 2)}
|
|
27
|
-
`, ...path);
|
|
28
|
-
}
|
|
29
|
-
async function toMD5(...path) {
|
|
30
|
-
const hash = node_crypto.createHash("md5");
|
|
31
|
-
const stream = node_fs.createReadStream(node_path.join(...path));
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
stream.on("data", (chunk) => hash.update(chunk));
|
|
34
|
-
stream.on("end", () => resolve(hash.digest("base64url")));
|
|
35
|
-
stream.on("error", reject);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
exports.glob = fastGlob__default;
|
|
40
|
-
exports.exists = exists;
|
|
41
|
-
exports.readJson = readJson;
|
|
42
|
-
exports.readText = readText;
|
|
43
|
-
exports.toMD5 = toMD5;
|
|
44
|
-
exports.writeJson = writeJson;
|
|
45
|
-
exports.writeText = writeText;
|
package/dist/fs.d.cts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as glob } from 'fast-glob';
|
|
2
|
-
|
|
3
|
-
declare function exists(...path: string[]): Promise<boolean>;
|
|
4
|
-
declare function readText(...path: string[]): Promise<string>;
|
|
5
|
-
declare function readJson<T>(...path: string[]): Promise<T>;
|
|
6
|
-
declare function writeText(content: string, ...path: string[]): Promise<void>;
|
|
7
|
-
declare function writeJson(content: object, ...path: string[]): Promise<void>;
|
|
8
|
-
declare function toMD5(...path: string[]): Promise<string>;
|
|
9
|
-
|
|
10
|
-
export { exists, readJson, readText, toMD5, writeJson, writeText };
|
package/dist/fs.d.mts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as glob } from 'fast-glob';
|
|
2
|
-
|
|
3
|
-
declare function exists(...path: string[]): Promise<boolean>;
|
|
4
|
-
declare function readText(...path: string[]): Promise<string>;
|
|
5
|
-
declare function readJson<T>(...path: string[]): Promise<T>;
|
|
6
|
-
declare function writeText(content: string, ...path: string[]): Promise<void>;
|
|
7
|
-
declare function writeJson(content: object, ...path: string[]): Promise<void>;
|
|
8
|
-
declare function toMD5(...path: string[]): Promise<string>;
|
|
9
|
-
|
|
10
|
-
export { exists, readJson, readText, toMD5, writeJson, writeText };
|
package/dist/fs.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as glob } from 'fast-glob';
|
|
2
|
-
|
|
3
|
-
declare function exists(...path: string[]): Promise<boolean>;
|
|
4
|
-
declare function readText(...path: string[]): Promise<string>;
|
|
5
|
-
declare function readJson<T>(...path: string[]): Promise<T>;
|
|
6
|
-
declare function writeText(content: string, ...path: string[]): Promise<void>;
|
|
7
|
-
declare function writeJson(content: object, ...path: string[]): Promise<void>;
|
|
8
|
-
declare function toMD5(...path: string[]): Promise<string>;
|
|
9
|
-
|
|
10
|
-
export { exists, readJson, readText, toMD5, writeJson, writeText };
|
package/dist/fs.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { createReadStream } from 'node:fs';
|
|
3
|
-
import { access, constants, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
export { default as glob } from 'fast-glob';
|
|
6
|
-
|
|
7
|
-
async function exists(...path) {
|
|
8
|
-
return await access(join(...path), constants.F_OK).then(() => true, () => false);
|
|
9
|
-
}
|
|
10
|
-
async function readText(...path) {
|
|
11
|
-
return await readFile(join(...path), "utf-8");
|
|
12
|
-
}
|
|
13
|
-
async function readJson(...path) {
|
|
14
|
-
return JSON.parse(await readText(...path));
|
|
15
|
-
}
|
|
16
|
-
async function writeText(content, ...path) {
|
|
17
|
-
await writeFile(join(...path), content, "utf-8");
|
|
18
|
-
}
|
|
19
|
-
async function writeJson(content, ...path) {
|
|
20
|
-
await writeText(`${JSON.stringify(content, null, 2)}
|
|
21
|
-
`, ...path);
|
|
22
|
-
}
|
|
23
|
-
async function toMD5(...path) {
|
|
24
|
-
const hash = createHash("md5");
|
|
25
|
-
const stream = createReadStream(join(...path));
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
stream.on("data", (chunk) => hash.update(chunk));
|
|
28
|
-
stream.on("end", () => resolve(hash.digest("base64url")));
|
|
29
|
-
stream.on("error", reject);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { exists, readJson, readText, toMD5, writeJson, writeText };
|
package/fs.d.ts
DELETED
package/index.d.ts
DELETED