TextEncoder/TextDecoder from polkadot-js (#686)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user