@kupola/kupola 1.5.2 → 1.5.3
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/kupola.cjs.js +15 -15
- package/dist/kupola.cjs.js.map +1 -1
- package/dist/kupola.esm.js +296 -256
- package/dist/kupola.esm.js.map +1 -1
- package/dist/kupola.umd.js +15 -15
- package/dist/kupola.umd.js.map +1 -1
- package/js/kupola-config.js +13 -0
- package/js/security.js +52 -0
- package/package.json +1 -1
package/js/kupola-config.js
CHANGED
|
@@ -38,6 +38,19 @@ const config = {
|
|
|
38
38
|
'span': ['class', 'style'],
|
|
39
39
|
'div': ['class', 'style']
|
|
40
40
|
}
|
|
41
|
+
},
|
|
42
|
+
maskData: {
|
|
43
|
+
enabled: true,
|
|
44
|
+
patterns: {
|
|
45
|
+
phone: { regex: '^(\\d{3})\\d{4}(\\d{4})$', replace: '$1****$2' },
|
|
46
|
+
email: { regex: '^(.)(.*)(@.*)$', replace: '$1***$3' },
|
|
47
|
+
idCard: { regex: '^(\\d{6})\\d{8}(\\d{4})$', replace: '$1********$2' },
|
|
48
|
+
bankCard: { regex: '^(\\d{4})\\d{8}(\\d{4})$', replace: '$1 **** **** $2' }
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
secureId: {
|
|
52
|
+
length: 16,
|
|
53
|
+
charset: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
41
54
|
}
|
|
42
55
|
},
|
|
43
56
|
dev: {
|
package/js/security.js
CHANGED
|
@@ -58,4 +58,56 @@ export function stripHtml(html) {
|
|
|
58
58
|
const domParser = new DOMParser();
|
|
59
59
|
const doc = domParser.parseFromString(html, 'text/html');
|
|
60
60
|
return doc.body.textContent || '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function maskData(value, type, options = {}) {
|
|
64
|
+
const securityConfig = getSecurityConfig();
|
|
65
|
+
const maskConfig = securityConfig?.maskData || {};
|
|
66
|
+
|
|
67
|
+
if (!maskConfig.enabled && !options.force) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (value === null || value === undefined) {
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const patterns = options.patterns || maskConfig.patterns || {};
|
|
76
|
+
const pattern = patterns[type];
|
|
77
|
+
|
|
78
|
+
if (!pattern) {
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const regex = typeof pattern.regex === 'string'
|
|
83
|
+
? new RegExp(pattern.regex)
|
|
84
|
+
: pattern.regex;
|
|
85
|
+
|
|
86
|
+
return String(value).replace(regex, pattern.replace);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function generateSecureId(length, prefix) {
|
|
90
|
+
const securityConfig = getSecurityConfig();
|
|
91
|
+
const secureIdConfig = securityConfig?.secureId || {};
|
|
92
|
+
|
|
93
|
+
const idLength = length || secureIdConfig.length || 16;
|
|
94
|
+
const charset = secureIdConfig.charset || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
95
|
+
|
|
96
|
+
if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
|
|
97
|
+
let result = '';
|
|
98
|
+
for (let i = 0; i < idLength; i++) {
|
|
99
|
+
result += charset[Math.floor(Math.random() * charset.length)];
|
|
100
|
+
}
|
|
101
|
+
return prefix ? `${prefix}_${result}` : result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const array = new Uint32Array(idLength);
|
|
105
|
+
crypto.getRandomValues(array);
|
|
106
|
+
|
|
107
|
+
let result = '';
|
|
108
|
+
for (let i = 0; i < idLength; i++) {
|
|
109
|
+
result += charset[array[i] % charset.length];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return prefix ? `${prefix}_${result}` : result;
|
|
61
113
|
}
|
package/package.json
CHANGED