Adjust base library usage of for vs reduce/map (#1151)
* Adjust base library usage of `for` vs `reduce/map` * Additional * Adjust
This commit is contained in:
@@ -5,10 +5,12 @@ import crypto from 'crypto';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export function getRandomValues <T extends Uint8Array> (arr: T): T {
|
||||
return crypto.randomBytes(arr.length).reduce((arr, value, index) => {
|
||||
arr[index] = value;
|
||||
export function getRandomValues <T extends Uint8Array> (output: T): T {
|
||||
const bytes = crypto.randomBytes(output.length);
|
||||
|
||||
return arr;
|
||||
}, arr);
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
output[i] = bytes[i];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -19,18 +19,18 @@ interface RNExt {
|
||||
}
|
||||
}
|
||||
|
||||
function getRandomValuesNative <T extends Uint8Array> (arr: T): T {
|
||||
return Buffer
|
||||
.from((NativeModules as RNExt).RNGetRandomValues.getRandomBase64(arr.length), 'base64')
|
||||
.reduce((arr, byte, index): T => {
|
||||
arr[index] = byte;
|
||||
function getRandomValuesNative <T extends Uint8Array> (output: T): T {
|
||||
const bytes = Buffer.from((NativeModules as RNExt).RNGetRandomValues.getRandomBase64(output.length), 'base64');
|
||||
|
||||
return arr;
|
||||
}, arr);
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
output[i] = bytes[i];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function getRandomValuesGlobal <T extends Uint8Array> (arr: T): T {
|
||||
return crypto.getRandomValues(arr);
|
||||
function getRandomValuesGlobal <T extends Uint8Array> (output: T): T {
|
||||
return crypto.getRandomValues(output);
|
||||
}
|
||||
|
||||
export const getRandomValues = (
|
||||
|
||||
Reference in New Issue
Block a user