@livechat/accounts-sdk 2.1.0 → 2.1.2
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/accounts-sdk.js +29 -11
- package/dist/accounts-sdk.js.map +1 -1
- package/dist/accounts-sdk.min.js +2 -2
- package/dist/accounts-sdk.min.js.map +1 -1
- package/dist/index.cjs.js +34 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +34 -12
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +79 -0
package/dist/accounts-sdk.js
CHANGED
|
@@ -3362,23 +3362,41 @@
|
|
|
3362
3362
|
*/
|
|
3363
3363
|
|
|
3364
3364
|
function string(length) {
|
|
3365
|
-
const bytes = new Uint8Array(length);
|
|
3366
|
-
const result = [];
|
|
3367
3365
|
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~';
|
|
3366
|
+
const charsetLength = charset.length;
|
|
3368
3367
|
const cryptoObj = window.crypto || window.msCrypto;
|
|
3369
|
-
|
|
3370
|
-
if (!
|
|
3371
|
-
|
|
3372
|
-
random += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
3373
|
-
}
|
|
3374
|
-
} else {
|
|
3375
|
-
random = cryptoObj.getRandomValues(bytes);
|
|
3368
|
+
const hasCrypto = cryptoObj && typeof cryptoObj.getRandomValues === 'function';
|
|
3369
|
+
if (!hasCrypto) {
|
|
3370
|
+
return generateWithMathRandom(length, charset, charsetLength);
|
|
3376
3371
|
}
|
|
3377
|
-
|
|
3378
|
-
|
|
3372
|
+
const maxByte = Math.floor(256 / charsetLength) * charsetLength;
|
|
3373
|
+
if (maxByte === 0) {
|
|
3374
|
+
return generateWithMathRandom(length, charset, charsetLength);
|
|
3375
|
+
}
|
|
3376
|
+
const result = [];
|
|
3377
|
+
while (result.length < length) {
|
|
3378
|
+
const remaining = length - result.length;
|
|
3379
|
+
const buffer = new Uint8Array(remaining);
|
|
3380
|
+
cryptoObj.getRandomValues(buffer);
|
|
3381
|
+
for (let i = 0; i < buffer.length && result.length < length; i++) {
|
|
3382
|
+
const value = buffer[i];
|
|
3383
|
+
// Skip values that would cause modulo bias.
|
|
3384
|
+
if (value >= maxByte) {
|
|
3385
|
+
continue;
|
|
3386
|
+
}
|
|
3387
|
+
result.push(charset.charAt(value % charsetLength));
|
|
3388
|
+
}
|
|
3379
3389
|
}
|
|
3380
3390
|
return result.join('');
|
|
3381
3391
|
}
|
|
3392
|
+
function generateWithMathRandom(length, charset, charsetLength) {
|
|
3393
|
+
let output = '';
|
|
3394
|
+
for (let i = 0; i < length; i++) {
|
|
3395
|
+
const index = Math.floor(Math.random() * charsetLength);
|
|
3396
|
+
output += charset.charAt(index);
|
|
3397
|
+
}
|
|
3398
|
+
return output;
|
|
3399
|
+
}
|
|
3382
3400
|
var random = {
|
|
3383
3401
|
string: string
|
|
3384
3402
|
};
|