@pezkuwi/x-global 14.0.10 → 14.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export { packageInfo } from './packageInfo.js';
2
+ type GlobalThis = typeof globalThis & {
3
+ process?: {
4
+ env?: Record<string, string>;
5
+ };
6
+ [key: string]: unknown;
7
+ };
8
+ type GlobalNames = keyof typeof globalThis;
9
+ type GlobalType<N extends GlobalNames> = typeof globalThis[N];
10
+ /**
11
+ * A cross-environment implementation for globalThis
12
+ */
13
+ export declare const xglobal: GlobalThis;
14
+ /**
15
+ * Extracts a known global from the environment, applying a fallback if not found
16
+ */
17
+ export declare function extractGlobal<N extends GlobalNames, T extends GlobalType<N>>(name: N, fallback: unknown): T;
18
+ /**
19
+ * Expose a value as a known global, if not already defined
20
+ */
21
+ export declare function exposeGlobal<N extends GlobalNames, T extends GlobalType<N>>(name: N, fallback: unknown): void;
package/cjs/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.xglobal = exports.packageInfo = void 0;
4
+ exports.extractGlobal = extractGlobal;
5
+ exports.exposeGlobal = exposeGlobal;
6
+ var packageInfo_js_1 = require("./packageInfo.js");
7
+ Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
8
+ /** @internal Last-resort "this", if it gets here it probably would fail anyway */
9
+ function evaluateThis(fn) {
10
+ return fn('return this');
11
+ }
12
+ /**
13
+ * A cross-environment implementation for globalThis
14
+ */
15
+ exports.xglobal = (typeof globalThis !== 'undefined'
16
+ ? globalThis
17
+ : typeof global !== 'undefined'
18
+ ? global
19
+ : typeof self !== 'undefined'
20
+ ? self
21
+ : typeof window !== 'undefined'
22
+ ? window
23
+ : evaluateThis(Function));
24
+ /**
25
+ * Extracts a known global from the environment, applying a fallback if not found
26
+ */
27
+ function extractGlobal(name, fallback) {
28
+ // Not quite sure why this is here - snuck in with TS 4.7.2 with no real idea
29
+ // (as of now) as to why this looks like an "any" when we do cast it to a T
30
+ //
31
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
32
+ return typeof exports.xglobal[name] === 'undefined'
33
+ ? fallback
34
+ : exports.xglobal[name];
35
+ }
36
+ /**
37
+ * Expose a value as a known global, if not already defined
38
+ */
39
+ function exposeGlobal(name, fallback) {
40
+ if (typeof exports.xglobal[name] === 'undefined') {
41
+ exports.xglobal[name] = fallback;
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageInfo = void 0;
4
+ exports.packageInfo = { name: '@pezkuwi/x-global', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.0.10' };
package/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export { packageInfo } from './packageInfo.js';
2
+ type GlobalThis = typeof globalThis & {
3
+ process?: {
4
+ env?: Record<string, string>;
5
+ };
6
+ [key: string]: unknown;
7
+ };
8
+ type GlobalNames = keyof typeof globalThis;
9
+ type GlobalType<N extends GlobalNames> = typeof globalThis[N];
10
+ /**
11
+ * A cross-environment implementation for globalThis
12
+ */
13
+ export declare const xglobal: GlobalThis;
14
+ /**
15
+ * Extracts a known global from the environment, applying a fallback if not found
16
+ */
17
+ export declare function extractGlobal<N extends GlobalNames, T extends GlobalType<N>>(name: N, fallback: unknown): T;
18
+ /**
19
+ * Expose a value as a known global, if not already defined
20
+ */
21
+ export declare function exposeGlobal<N extends GlobalNames, T extends GlobalType<N>>(name: N, fallback: unknown): void;
package/index.js ADDED
@@ -0,0 +1,37 @@
1
+ export { packageInfo } from './packageInfo.js';
2
+ /** @internal Last-resort "this", if it gets here it probably would fail anyway */
3
+ function evaluateThis(fn) {
4
+ return fn('return this');
5
+ }
6
+ /**
7
+ * A cross-environment implementation for globalThis
8
+ */
9
+ export const xglobal = /*#__PURE__*/ (typeof globalThis !== 'undefined'
10
+ ? globalThis
11
+ : typeof global !== 'undefined'
12
+ ? global
13
+ : typeof self !== 'undefined'
14
+ ? self
15
+ : typeof window !== 'undefined'
16
+ ? window
17
+ : evaluateThis(Function));
18
+ /**
19
+ * Extracts a known global from the environment, applying a fallback if not found
20
+ */
21
+ export function extractGlobal(name, fallback) {
22
+ // Not quite sure why this is here - snuck in with TS 4.7.2 with no real idea
23
+ // (as of now) as to why this looks like an "any" when we do cast it to a T
24
+ //
25
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
26
+ return typeof xglobal[name] === 'undefined'
27
+ ? fallback
28
+ : xglobal[name];
29
+ }
30
+ /**
31
+ * Expose a value as a known global, if not already defined
32
+ */
33
+ export function exposeGlobal(name, fallback) {
34
+ if (typeof xglobal[name] === 'undefined') {
35
+ xglobal[name] = fallback;
36
+ }
37
+ }
package/package.json CHANGED
@@ -15,9 +15,61 @@
15
15
  },
16
16
  "sideEffects": false,
17
17
  "type": "module",
18
- "version": "14.0.10",
19
- "main": "index.js",
18
+ "version": "14.0.11",
19
+ "main": "./cjs/index.js",
20
+ "module": "./index.js",
21
+ "types": "./index.d.ts",
22
+ "exports": {
23
+ "./cjs/package.json": "./cjs/package.json",
24
+ "./cjs/*": "./cjs/*.js",
25
+ ".": {
26
+ "module": {
27
+ "types": "./index.d.ts",
28
+ "default": "./index.js"
29
+ },
30
+ "require": {
31
+ "types": "./cjs/index.d.ts",
32
+ "default": "./cjs/index.js"
33
+ },
34
+ "default": {
35
+ "types": "./index.d.ts",
36
+ "default": "./index.js"
37
+ }
38
+ },
39
+ "./package.json": {
40
+ "require": "./cjs/package.json",
41
+ "default": "./package.json"
42
+ },
43
+ "./packageInfo.js": {
44
+ "module": {
45
+ "types": "./packageInfo.d.ts",
46
+ "default": "./packageInfo.js"
47
+ },
48
+ "require": {
49
+ "types": "./cjs/packageInfo.d.ts",
50
+ "default": "./cjs/packageInfo.js"
51
+ },
52
+ "default": {
53
+ "types": "./packageInfo.d.ts",
54
+ "default": "./packageInfo.js"
55
+ }
56
+ },
57
+ "./packageInfo": {
58
+ "module": {
59
+ "types": "./packageInfo.d.ts",
60
+ "default": "./packageInfo.js"
61
+ },
62
+ "require": {
63
+ "types": "./cjs/packageInfo.d.ts",
64
+ "default": "./cjs/packageInfo.js"
65
+ },
66
+ "default": {
67
+ "types": "./packageInfo.d.ts",
68
+ "default": "./packageInfo.js"
69
+ }
70
+ }
71
+ },
20
72
  "dependencies": {
21
73
  "tslib": "^2.8.0"
22
74
  }
23
- }
75
+ }
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
package/packageInfo.js ADDED
@@ -0,0 +1 @@
1
+ export const packageInfo = { name: '@pezkuwi/x-global', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.10' };