TextEncoder/TextDecoder from polkadot-js (#686)

This commit is contained in:
Jaco Greeff
2020-09-18 15:09:25 +02:00
committed by GitHub
parent 56a79924a0
commit 5c886b0f81
11 changed files with 55 additions and 164 deletions
+2 -14
View File
@@ -1,21 +1,9 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
let decoder: { decode: (value: Uint8Array) => string };
import TextDecoder from '@polkadot/x-textdecoder';
function polyfilledDecode (value: Uint8Array): string {
return value.reduce((str, code): string => {
return str + String.fromCharCode(code);
}, '');
}
try {
decoder = new TextDecoder('utf-8');
} catch (error) {
decoder = {
decode: polyfilledDecode
};
}
const decoder = new TextDecoder('utf-8');
/**
* @name u8aToString