mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 03:17:58 +00:00
Initial rebrand: @polkadot -> @pezkuwi (14 packages)
- Package namespace: @polkadot/* -> @pezkuwi/* - Repository: polkadot-js/common -> pezkuwichain/pezkuwi-common - Author: Pezkuwi Team <team@pezkuwichain.io> Core packages: - @pezkuwi/util (utilities) - @pezkuwi/util-crypto (crypto primitives) - @pezkuwi/keyring (account management) - @pezkuwi/networks (chain metadata) - @pezkuwi/hw-ledger (Ledger hardware wallet) - @pezkuwi/x-* (10 polyfill packages) Total: 14 packages Upstream: polkadot-js/common v14.0.1
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# @pezkuwi/x-global
|
||||
|
||||
A cross-environment global object. checks for global > self > window > this.
|
||||
|
||||
Install it via `yarn add @pezkuwi/x-global`
|
||||
|
||||
```js
|
||||
import { xglobal } from '@pezkuwi/x-global';
|
||||
|
||||
console.log(typeof xglobal.TextEncoder);
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
|
||||
"description": "A cross-environment global replacement",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/x-global#readme",
|
||||
"license": "Apache-2.0",
|
||||
"name": "@pezkuwi/x-global",
|
||||
"repository": {
|
||||
"directory": "packages/x-global",
|
||||
"type": "git",
|
||||
"url": "https://github.com/pezkuwichain/pezkuwi-common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "14.0.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"tslib": "^2.8.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2017-2025 @polkadot/x-global authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
|
||||
// Ensure that we are able to run this without any @types/node definitions
|
||||
// and without having lib: ['dom'] in our TypeScript configuration
|
||||
// (may not be available in all environments, e.g. Deno springs to mind)
|
||||
declare const global: unknown;
|
||||
declare const self: unknown;
|
||||
declare const window: unknown;
|
||||
|
||||
// The [key: string]: unknown part here is for not-everywhere globals
|
||||
// such as `Buffer` (that won't exist is deno/window global environments)
|
||||
type GlobalThis = typeof globalThis & {
|
||||
process?: {
|
||||
env?: Record<string, string>;
|
||||
};
|
||||
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
type GlobalNames = keyof typeof globalThis;
|
||||
|
||||
type GlobalType<N extends GlobalNames> = typeof globalThis[N];
|
||||
|
||||
/** @internal Last-resort "this", if it gets here it probably would fail anyway */
|
||||
function evaluateThis (fn: (code: string) => unknown): unknown {
|
||||
return fn('return this');
|
||||
}
|
||||
|
||||
/**
|
||||
* A cross-environment implementation for globalThis
|
||||
*/
|
||||
export const xglobal = /*#__PURE__*/ (
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: evaluateThis(Function)
|
||||
) as GlobalThis;
|
||||
|
||||
/**
|
||||
* Extracts a known global from the environment, applying a fallback if not found
|
||||
*/
|
||||
export function extractGlobal <N extends GlobalNames, T extends GlobalType<N>> (name: N, fallback: unknown): T {
|
||||
// Not quite sure why this is here - snuck in with TS 4.7.2 with no real idea
|
||||
// (as of now) as to why this looks like an "any" when we do cast it to a T
|
||||
//
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return typeof xglobal[name] === 'undefined'
|
||||
? fallback as T
|
||||
: xglobal[name] as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose a value as a known global, if not already defined
|
||||
*/
|
||||
export function exposeGlobal <N extends GlobalNames, T extends GlobalType<N>> (name: N, fallback: unknown): void {
|
||||
if (typeof xglobal[name] === 'undefined') {
|
||||
(xglobal as Record<string, unknown>)[name] = fallback as T;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2025 @polkadot/x-global authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './index.js';
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2025 @polkadot/x-global authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-global', path: 'auto', type: 'auto', version: '14.0.1' };
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/mod.ts"
|
||||
],
|
||||
"references": []
|
||||
}
|
||||
Reference in New Issue
Block a user