a-js-tools 1.0.13-beta.3 → 1.0.13-beta.5
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.cjs.js +12 -3
- package/package.json +2 -2
package/index.cjs.js
CHANGED
|
@@ -248,18 +248,22 @@ function getRandomString(options) {
|
|
|
248
248
|
// 添加特殊字符
|
|
249
249
|
if (initOptions.includeSpecial)
|
|
250
250
|
interleaveString(templateCharsArr, initOptions.chars3);
|
|
251
|
+
/** 结果字符串 */
|
|
251
252
|
let result = '';
|
|
252
|
-
|
|
253
|
+
/** 混淆后的字符串 */
|
|
254
|
+
const str = templateCharsArr.join('');
|
|
255
|
+
/** 混淆后字符长度 */
|
|
256
|
+
const strLen = str.length;
|
|
253
257
|
if (globalThis && globalThis.crypto && globalThis.crypto.getRandomValues) {
|
|
254
258
|
// 使用密码学安全的随机数生成器
|
|
255
259
|
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(initOptions.length));
|
|
256
260
|
/** 获取最后的 chars 数据 */
|
|
257
261
|
// 循环遍历
|
|
258
|
-
bytes.forEach(byte => (result +=
|
|
262
|
+
bytes.forEach(byte => (result += str[byte % strLen]));
|
|
259
263
|
}
|
|
260
264
|
else {
|
|
261
265
|
for (let i = 0; i < initOptions.length; i++)
|
|
262
|
-
result +=
|
|
266
|
+
result += str[getRandomInt(strLen - 1)];
|
|
263
267
|
}
|
|
264
268
|
/**
|
|
265
269
|
*
|
|
@@ -285,6 +289,11 @@ function getRandomString(options) {
|
|
|
285
289
|
str1[i] = str2[i];
|
|
286
290
|
}
|
|
287
291
|
}
|
|
292
|
+
/// 结果字符串不包含字符
|
|
293
|
+
if (!/[a-zA-Z]/.test(result))
|
|
294
|
+
return String.fromCharCode(getRandomInt(97, 122)).concat(result.slice(1));
|
|
295
|
+
while (!/^[a-zA-Z]$/.test(result[0]))
|
|
296
|
+
result = result.slice(1) + result[0];
|
|
288
297
|
return result;
|
|
289
298
|
}
|
|
290
299
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "1.0.13-beta.
|
|
3
|
+
"version": "1.0.13-beta.5",
|
|
4
4
|
"name": "a-js-tools",
|
|
5
5
|
"description": "一点点 🤏 js 函数",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"a-type-of-js": "
|
|
8
|
+
"a-type-of-js": "1.0.8-beta.0"
|
|
9
9
|
},
|
|
10
10
|
"main": "index.cjs.js",
|
|
11
11
|
"module": "index.mjs.js",
|