Adjust & dedupe global extraction tests (#1301)

This commit is contained in:
Jaco
2021-12-08 20:23:46 +02:00
committed by GitHub
parent 306e503d23
commit 8a6c8b64df
13 changed files with 40 additions and 57 deletions
+2 -6
View File
@@ -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 -7
View File
@@ -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);
+2 -4
View File
@@ -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);