Adjust & dedupe global extraction tests (#1301)
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
import { extractGlobal } from '@polkadot/x-global';
|
||||
|
||||
import { TextEncoder as Fallback } from './fallback';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const TextEncoder = (
|
||||
typeof xglobal.TextEncoder === 'undefined'
|
||||
? Fallback as unknown as typeof xglobal.TextEncoder
|
||||
: xglobal.TextEncoder
|
||||
);
|
||||
export const TextEncoder = extractGlobal('TextEncoder', Fallback);
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
import util from 'util';
|
||||
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
import { extractGlobal } from '@polkadot/x-global';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
class NodeFallback {
|
||||
class Fallback {
|
||||
#encoder: util.TextEncoder;
|
||||
|
||||
constructor () {
|
||||
@@ -20,8 +20,4 @@ class NodeFallback {
|
||||
}
|
||||
}
|
||||
|
||||
export const TextEncoder = (
|
||||
typeof xglobal.TextEncoder === 'undefined'
|
||||
? NodeFallback as unknown as typeof xglobal.TextEncoder
|
||||
: xglobal.TextEncoder
|
||||
);
|
||||
export const TextEncoder = extractGlobal('TextEncoder', Fallback);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/x-textencoder authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
import { exposeGlobal } from '@polkadot/x-global';
|
||||
import { TextEncoder } from '@polkadot/x-textencoder';
|
||||
|
||||
if (typeof xglobal.TextEncoder !== 'function') {
|
||||
(xglobal as Record<string, unknown>).TextEncoder = TextEncoder;
|
||||
}
|
||||
exposeGlobal('TextEncoder', TextEncoder);
|
||||
|
||||
Reference in New Issue
Block a user