a-js-tools 1.0.13-beta.2 → 1.0.13-beta.4
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 -6
- package/package.json +2 -2
package/index.cjs.js
CHANGED
|
@@ -248,13 +248,19 @@ function getRandomString(options) {
|
|
|
248
248
|
// 添加特殊字符
|
|
249
249
|
if (initOptions.includeSpecial)
|
|
250
250
|
interleaveString(templateCharsArr, initOptions.chars3);
|
|
251
|
-
// 使用密码学安全的随机数生成器
|
|
252
|
-
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(initOptions.length));
|
|
253
251
|
let result = '';
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
const templateCharsArrLength = templateCharsArr.length;
|
|
253
|
+
if (globalThis && globalThis.crypto && globalThis.crypto.getRandomValues) {
|
|
254
|
+
// 使用密码学安全的随机数生成器
|
|
255
|
+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(initOptions.length));
|
|
256
|
+
/** 获取最后的 chars 数据 */
|
|
257
|
+
// 循环遍历
|
|
258
|
+
bytes.forEach(byte => (result += templateCharsArr[byte % templateCharsArrLength]));
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
for (let i = 0; i < initOptions.length; i++)
|
|
262
|
+
result += templateCharsArr[getRandomInt(templateCharsArrLength - 1)];
|
|
263
|
+
}
|
|
258
264
|
/**
|
|
259
265
|
*
|
|
260
266
|
* 字符串交叉函数
|
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.4",
|
|
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",
|