@aiot-toolkit/shared-utils 2.0.2-beta.1 → 2.0.2-beta.10
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/lib/ColorConsole.js
CHANGED
|
@@ -55,7 +55,7 @@ class ColorConsole {
|
|
|
55
55
|
}
|
|
56
56
|
static _log(logLevel, ...message) {
|
|
57
57
|
const style = this.styleDic[logLevel] || this.defaultStyle;
|
|
58
|
-
const time = this.formatWord(`[${(0, dayjs_1.default)().format('
|
|
58
|
+
const time = this.formatWord(`[${(0, dayjs_1.default)().format('MM-DD HH:mm:ss')}] [toolkit]:`, style);
|
|
59
59
|
const icon = style.icon ? style.icon : '';
|
|
60
60
|
console.log(icon, time, this.createMessage(message.map((item) => {
|
|
61
61
|
if (typeof item === 'object') {
|
package/lib/utils/CommonUtil.js
CHANGED
|
@@ -25,6 +25,11 @@ class CommonUtil {
|
|
|
25
25
|
hash.update(buffer);
|
|
26
26
|
return hash.digest();
|
|
27
27
|
}
|
|
28
|
+
static calcImageDigest(filePath) {
|
|
29
|
+
const data = fs_1.default.readFileSync(filePath);
|
|
30
|
+
const hash = crypto_1.default.createHash('md5').update(data);
|
|
31
|
+
return hash.digest('hex').substring(0, 8);
|
|
32
|
+
}
|
|
28
33
|
/**
|
|
29
34
|
* 从开发者项目的 node_module 中加载指定依赖;
|
|
30
35
|
* 如果不存在,提示下载;存在则返回加载的依赖
|
package/lib/utils/FileUtil.js
CHANGED
|
@@ -116,10 +116,7 @@ class FileUtil {
|
|
|
116
116
|
* @returns
|
|
117
117
|
*/
|
|
118
118
|
static updatePath(path, fullName) {
|
|
119
|
-
|
|
120
|
-
return path_1.default.join(path_1.default.dirname(path), fullName);
|
|
121
|
-
}
|
|
122
|
-
return path;
|
|
119
|
+
return path_1.default.join(path_1.default.dirname(path), fullName);
|
|
123
120
|
}
|
|
124
121
|
/**
|
|
125
122
|
* 复制文件
|
|
@@ -22,7 +22,7 @@ declare class StringUtil {
|
|
|
22
22
|
* @param styleTransform 是否为style解析树的数组转换
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
static
|
|
25
|
+
static arrayToString(arr: any[], styleTransform?: boolean): string;
|
|
26
26
|
/**
|
|
27
27
|
* 对象转字符串
|
|
28
28
|
* @param obj
|
package/lib/utils/StringUtil.js
CHANGED
|
@@ -34,7 +34,7 @@ class StringUtil {
|
|
|
34
34
|
* @param styleTransform 是否为style解析树的数组转换
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
|
-
static
|
|
37
|
+
static arrayToString(arr, styleTransform = false) {
|
|
38
38
|
if (Array.isArray(arr)) {
|
|
39
39
|
if (arr.length <= 0) {
|
|
40
40
|
return '[]';
|
|
@@ -48,7 +48,7 @@ class StringUtil {
|
|
|
48
48
|
switch (typeof item) {
|
|
49
49
|
case 'object':
|
|
50
50
|
if (Array.isArray(item)) {
|
|
51
|
-
valueStr = StringUtil.
|
|
51
|
+
valueStr = StringUtil.arrayToString(item, styleTransform);
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
valueStr = StringUtil.objectToString(item, styleTransform);
|
|
@@ -83,7 +83,7 @@ class StringUtil {
|
|
|
83
83
|
switch (typeof value) {
|
|
84
84
|
case 'object':
|
|
85
85
|
if (Array.isArray(value)) {
|
|
86
|
-
valueStr = StringUtil.
|
|
86
|
+
valueStr = StringUtil.arrayToString(value, styleTransform);
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
valueStr = StringUtil.objectToString(value, styleTransform);
|
|
@@ -108,7 +108,7 @@ class StringUtil {
|
|
|
108
108
|
valueStr = value;
|
|
109
109
|
break;
|
|
110
110
|
}
|
|
111
|
-
return
|
|
111
|
+
return `"${StringUtil.hyphenedToCamel(key)}":${valueStr}`;
|
|
112
112
|
})
|
|
113
113
|
.filter((item) => Boolean(item))
|
|
114
114
|
.join(',')}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/shared-utils",
|
|
3
|
-
"version": "2.0.2-beta.
|
|
3
|
+
"version": "2.0.2-beta.10",
|
|
4
4
|
"description": "The common method functions of the aiot-toolkit.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"qrcode-terminal": "^0.12.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/fs-extra": "^11.0.4",
|
|
26
27
|
"@types/qrcode-terminal": "^0.12.0"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "00d23c1ad1306a6c72bb007685de9fd4a6ee61af"
|
|
29
30
|
}
|