a-js-tools 1.0.13-beta.4 → 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.
Files changed (2) hide show
  1. package/index.cjs.js +12 -3
  2. package/package.json +1 -1
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
- const templateCharsArrLength = templateCharsArr.length;
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 += templateCharsArr[byte % templateCharsArrLength]));
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 += templateCharsArr[getRandomInt(templateCharsArrLength - 1)];
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,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.13-beta.4",
3
+ "version": "1.0.13-beta.5",
4
4
  "name": "a-js-tools",
5
5
  "description": "一点点 🤏 js 函数",
6
6
  "license": "MIT",