mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
fix(utils): move generateString to platform utils to avoid importing crypto module into client builds; (#6789)
* chore(ci): Add release-it script; * fix(utils): move generateString util to platform utils to avoid importing crypto module into client build; --------- Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
import bind from './helpers/bind.js';
|
||||
import crypto from 'crypto';
|
||||
|
||||
// utils is a library of generic helper functions non-specific to axios
|
||||
|
||||
@@ -603,28 +602,6 @@ const toFiniteNumber = (value, defaultValue) => {
|
||||
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
|
||||
|
||||
const DIGIT = '0123456789';
|
||||
|
||||
const ALPHABET = {
|
||||
DIGIT,
|
||||
ALPHA,
|
||||
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
||||
}
|
||||
|
||||
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
||||
let str = '';
|
||||
const {length} = alphabet;
|
||||
const randomValues = new Uint32Array(size);
|
||||
crypto.randomFillSync(randomValues);
|
||||
for (let i = 0; i < size; i++) {
|
||||
str += alphabet[randomValues[i] % length];
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the thing is a FormData object, return true, otherwise return false.
|
||||
*
|
||||
@@ -752,8 +729,6 @@ export default {
|
||||
findKey,
|
||||
global: _global,
|
||||
isContextDefined,
|
||||
ALPHABET,
|
||||
generateString,
|
||||
isSpecCompliantForm,
|
||||
toJSONObject,
|
||||
isAsyncFn,
|
||||
|
||||
Reference in New Issue
Block a user