Move @polkadot/x-{fetch,textdecoder,textencoder,ws} (#737)
* Move @polkadot/x-{fetch,textdecoder,textencoder,ws}
* Adjust copyrights
* Fix jest aliassing
* tsconfig resolution
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
}
|
||||
|
||||
decode (value: Uint8Array): string {
|
||||
return value.reduce((str, code): string => {
|
||||
return str + String.fromCharCode(code);
|
||||
}, '');
|
||||
}
|
||||
}
|
||||
: TextDecoder;
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2020 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TextDecoder as NodeTextDecoder } from 'util';
|
||||
|
||||
export default typeof TextDecoder === 'undefined'
|
||||
? NodeTextDecoder as unknown as typeof TextDecoder
|
||||
: TextDecoder;
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2020 @polkadot/x-textdecoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BrowserTD from './browser';
|
||||
import NodeTD from './node';
|
||||
|
||||
console.log(new BrowserTD('utf-8').decode(new Uint8Array([1, 2, 3])));
|
||||
console.log(new NodeTD('utf-8').decode(new Uint8Array([1, 2, 3])));
|
||||
Reference in New Issue
Block a user