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 -18
View File
@@ -1,25 +1,9 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
let encoder: { encode: (value: string) => Uint8Array };
import TextEncoder from '@polkadot/x-textencoder';
function polyfilledEncode (value: string): Uint8Array {
const u8a = new Uint8Array(value.length);
for (let i = 0; i < value.length; i++) {
u8a[i] = value.charCodeAt(i);
}
return u8a;
}
try {
encoder = new TextEncoder();
} catch (error) {
encoder = {
encode: polyfilledEncode
};
}
const encoder = new TextEncoder();
/**
* @name stringToU8a