RN-specific getRandomValues (no node crypto) (#747)

* RN-specific getRandomValues (no node crypto)

* Use polyfilled as available

* === object
This commit is contained in:
Jaco Greeff
2020-11-07 15:22:42 +01:00
committed by GitHub
parent 94d6a900f7
commit db0559e9c9
7 changed files with 125 additions and 20 deletions
+3 -12
View File
@@ -1,17 +1,8 @@
// Copyright 2017-2020 @polkadot/x-textencoder authors & contributors
// SPDX-License-Identifier: Apache-2.0
export default typeof TextDecoder === 'undefined'
? class {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-useless-constructor
constructor (_: 'utf-8') {
// nothing
}
import Fallback from './fallback';
decode (value: Uint8Array): string {
return value.reduce((str, code): string => {
return str + String.fromCharCode(code);
}, '');
}
}
export default typeof TextDecoder === 'undefined'
? Fallback
: TextDecoder;
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2017-2020 @polkadot/x-textencoder authors & contributors
// SPDX-License-Identifier: Apache-2.0
export default class TextDecoder {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-useless-constructor
constructor (_: 'utf-8') {
// nothing
}
decode (value: Uint8Array): string {
return value.reduce((str, code): string => {
return str + String.fromCharCode(code);
}, '');
}
}