a-js-tools 0.2.0 → 0.2.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.
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var aTypeOfJs = require('a-type-of-js');
4
- var crypto$1 = require('crypto');
5
4
 
6
5
  /**
7
6
  * 获取随机字符串
@@ -74,7 +73,9 @@ function getRandomString(length) {
74
73
  interleaveString(templateCharsArr, initOptions.chars3);
75
74
  }
76
75
  // 使用密码学安全的随机数生成器
77
- const bytes = crypto$1.randomBytes(initOptions.length);
76
+ const bytes = !aTypeOfJs.isUndefined(window) && window.crypto
77
+ ? window.crypto.getRandomValues(new Uint8Array(initOptions.length))
78
+ : global.crypto.getRandomValues(new Uint8Array(initOptions.length));
78
79
  let result = '';
79
80
  /** 获取最后的 chars 数据 */
80
81
  const chars = templateCharsArr.join('');
@@ -1,5 +1,4 @@
1
- import { isPlainObject, isNumber, isNaN } from 'a-type-of-js';
2
- import { randomBytes } from 'crypto';
1
+ import { isPlainObject, isNumber, isNaN, isUndefined } from 'a-type-of-js';
3
2
 
4
3
  /**
5
4
  * 获取随机字符串
@@ -72,7 +71,9 @@ function getRandomString(length) {
72
71
  interleaveString(templateCharsArr, initOptions.chars3);
73
72
  }
74
73
  // 使用密码学安全的随机数生成器
75
- const bytes = randomBytes(initOptions.length);
74
+ const bytes = !isUndefined(window) && window.crypto
75
+ ? window.crypto.getRandomValues(new Uint8Array(initOptions.length))
76
+ : global.crypto.getRandomValues(new Uint8Array(initOptions.length));
76
77
  let result = '';
77
78
  /** 获取最后的 chars 数据 */
78
79
  const chars = templateCharsArr.join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "name": "a-js-tools",
5
5
  "description": "一点点 🤏 js 函数",
6
6
  "license": "ISC",