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:
Jaco
2021-10-31 08:27:14 +02:00
committed by GitHub
parent 7ef169585f
commit a4cefa4bfc
20 changed files with 130 additions and 87 deletions
+7 -5
View File
@@ -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;
}
+9 -9
View File
@@ -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 = (