ph-utils 0.2.7 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/date.js +4 -4
- package/lib/file.d.ts +6 -0
- package/lib/file.js +12 -1
- package/lib/index.d.ts +8 -1
- package/lib/index.js +18 -1
- package/lib/index_m.d.ts +8 -1
- package/lib/index_m.js +16 -0
- package/lib/server.js +1 -1
- package/lib/validator_m.js +1 -0
- package/package.json +2 -2
package/lib/date.js
CHANGED
@@ -100,10 +100,10 @@ function startOf(date, unit, isEnd = false) {
|
|
100
100
|
exports.startOf = startOf;
|
101
101
|
/**
|
102
102
|
* 日期加上指定时间后的日期
|
103
|
-
* @param date
|
104
|
-
* @param num
|
105
|
-
* @param unit
|
106
|
-
* @param fmt
|
103
|
+
* @param date 指定的日期
|
104
|
+
* @param num 需要添加的数字, 如果这个参数传递一个小于0的数字,则就是日期减去相应的数字
|
105
|
+
* @param unit 需要添加的单位,date - 加减天数
|
106
|
+
* @param fmt 可选参数,如果传递了格式化的单位,则返回格式化后的日期, 格式化字符串 yyyy - 年, mm - 月, dd - 日, HH - 小时, MM - 分钟, ss - 秒
|
107
107
|
* @returns {Date | string} 如果传递了 fmt 参数,则返回 string,否则返回 Date
|
108
108
|
*/
|
109
109
|
function add(date, num, unit, fmt) {
|
package/lib/file.d.ts
CHANGED
@@ -24,5 +24,11 @@ declare const _default: {
|
|
24
24
|
* @param done 遍历完成后的回调
|
25
25
|
*/
|
26
26
|
traverseDir(dir: string, callback?: (filename: string) => void, done?: () => void): void;
|
27
|
+
/**
|
28
|
+
* 根据文件的 stat 获取文件的 etag
|
29
|
+
* @param filePath 文件地址
|
30
|
+
* @returns file stat etag
|
31
|
+
*/
|
32
|
+
statTag(filePath: string): Promise<string>;
|
27
33
|
};
|
28
34
|
export = _default;
|
package/lib/file.js
CHANGED
@@ -71,7 +71,9 @@ module.exports = {
|
|
71
71
|
clearTimeout(t);
|
72
72
|
t = setTimeout(() => {
|
73
73
|
setImmediate(() => {
|
74
|
-
done
|
74
|
+
if (typeof done === 'function') {
|
75
|
+
done();
|
76
|
+
}
|
75
77
|
});
|
76
78
|
}, 10);
|
77
79
|
}
|
@@ -85,4 +87,13 @@ module.exports = {
|
|
85
87
|
}
|
86
88
|
list(dir, callback, done);
|
87
89
|
},
|
90
|
+
/**
|
91
|
+
* 根据文件的 stat 获取文件的 etag
|
92
|
+
* @param filePath 文件地址
|
93
|
+
* @returns file stat etag
|
94
|
+
*/
|
95
|
+
async statTag(filePath) {
|
96
|
+
let stat = await fs.promises.stat(filePath);
|
97
|
+
return `${stat.size.toString(16)}-${stat.mtimeMs.toString(16)}`;
|
98
|
+
},
|
88
99
|
};
|
package/lib/index.d.ts
CHANGED
@@ -50,5 +50,12 @@ export declare class BaseError extends Error {
|
|
50
50
|
* @param name 错误名称
|
51
51
|
* @param message 错误描述
|
52
52
|
*/
|
53
|
-
constructor(name:
|
53
|
+
constructor(name: string, message: string);
|
54
54
|
}
|
55
|
+
/**
|
56
|
+
* 创建一个节流函数,在 wait 秒内最多执行 func 一次的函数。
|
57
|
+
* @param func 要节流的函数
|
58
|
+
* @param wait 需要节流的毫秒
|
59
|
+
* @returns
|
60
|
+
*/
|
61
|
+
export declare function throttle<T extends (...args: any) => any>(func: T, wait: number): (...args: any[]) => void;
|
package/lib/index.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* node 和 web 通用的工具类
|
4
4
|
*/
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.BaseError = exports.isBoolean = exports.isNumeric = exports.shieldMobile = exports.isBlank = void 0;
|
6
|
+
exports.throttle = exports.BaseError = exports.isBoolean = exports.isNumeric = exports.shieldMobile = exports.isBlank = void 0;
|
7
7
|
/**
|
8
8
|
* 验证字符串是否为空
|
9
9
|
* @param str 待验证的字符串
|
@@ -77,3 +77,20 @@ class BaseError extends Error {
|
|
77
77
|
}
|
78
78
|
}
|
79
79
|
exports.BaseError = BaseError;
|
80
|
+
/**
|
81
|
+
* 创建一个节流函数,在 wait 秒内最多执行 func 一次的函数。
|
82
|
+
* @param func 要节流的函数
|
83
|
+
* @param wait 需要节流的毫秒
|
84
|
+
* @returns
|
85
|
+
*/
|
86
|
+
function throttle(func, wait) {
|
87
|
+
let lastTime = 0;
|
88
|
+
return function (...args) {
|
89
|
+
let now = Date.now();
|
90
|
+
if (now - lastTime >= wait) {
|
91
|
+
func(...args);
|
92
|
+
lastTime = now;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
}
|
96
|
+
exports.throttle = throttle;
|
package/lib/index_m.d.ts
CHANGED
@@ -50,5 +50,12 @@ export declare class BaseError extends Error {
|
|
50
50
|
* @param name 错误名称
|
51
51
|
* @param message 错误描述
|
52
52
|
*/
|
53
|
-
constructor(name:
|
53
|
+
constructor(name: string, message: string);
|
54
54
|
}
|
55
|
+
/**
|
56
|
+
* 创建一个节流函数,在 wait 秒内最多执行 func 一次的函数。
|
57
|
+
* @param func 要节流的函数
|
58
|
+
* @param wait 需要节流的毫秒
|
59
|
+
* @returns
|
60
|
+
*/
|
61
|
+
export declare function throttle<T extends (...args: any) => any>(func: T, wait: number): (...args: any[]) => void;
|
package/lib/index_m.js
CHANGED
@@ -64,3 +64,19 @@ export class BaseError extends Error {
|
|
64
64
|
}
|
65
65
|
}
|
66
66
|
}
|
67
|
+
/**
|
68
|
+
* 创建一个节流函数,在 wait 秒内最多执行 func 一次的函数。
|
69
|
+
* @param func 要节流的函数
|
70
|
+
* @param wait 需要节流的毫秒
|
71
|
+
* @returns
|
72
|
+
*/
|
73
|
+
export function throttle(func, wait) {
|
74
|
+
let lastTime = 0;
|
75
|
+
return function (...args) {
|
76
|
+
let now = Date.now();
|
77
|
+
if (now - lastTime >= wait) {
|
78
|
+
func(...args);
|
79
|
+
lastTime = now;
|
80
|
+
}
|
81
|
+
};
|
82
|
+
}
|
package/lib/server.js
CHANGED
@@ -59,7 +59,7 @@ module.exports = {
|
|
59
59
|
options = { ...(options || {}) };
|
60
60
|
const errorName = options.errorName || 'ExecError';
|
61
61
|
delete options.errorName;
|
62
|
-
child_process_1.exec(cmd, options, (error, stdout, stderr) => {
|
62
|
+
(0, child_process_1.exec)(cmd, options, (error, stdout, stderr) => {
|
63
63
|
let err = null;
|
64
64
|
let rs = null;
|
65
65
|
if (error) {
|
package/lib/validator_m.js
CHANGED
package/package.json
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
"module": "lib/index_m.js",
|
6
6
|
"types": "lib/index.d.ts",
|
7
7
|
"browser": "lib/index_m.js",
|
8
|
-
"version": "0.2.
|
8
|
+
"version": "0.2.11",
|
9
9
|
"repository": {
|
10
10
|
"type": "git",
|
11
11
|
"url": "git+https//gitee.com/towardly/ph.git",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"homepage": "https://gitee.com/towardly/ph/tree/master/packages/utils",
|
20
20
|
"devDependencies": {
|
21
21
|
"@types/node": "^17.0.21",
|
22
|
-
"typescript": "
|
22
|
+
"typescript": "4.5.5"
|
23
23
|
},
|
24
24
|
"scripts": {
|
25
25
|
"build": "node scripts/build.js"
|