globables 1.0.0
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/LICENSE +21 -0
- package/README.md +98 -0
- package/dist/index.cjs +56 -0
- package/dist/index.cjs.map +10 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +10 -0
- package/dist/index.min.cjs +1 -0
- package/dist/index.min.js +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 te <legal@fetchTe.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# GlobAbles
|
|
2
|
+
|
|
3
|
+
CLI/ENV constants for Node.js-like runtimes, supports: [Node.js](https://nodejs.org/), [Deno](https://deno.com/), [Bun](https://bun.sh/), [QuickJS](https://bellard.org/quickjs/), and [QuickJS-NG](https://quickjs-ng.github.io/quickjs/)
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import {
|
|
7
|
+
ARGV,
|
|
8
|
+
ENV,
|
|
9
|
+
GLOBAL_THIS,
|
|
10
|
+
} from 'globables';
|
|
11
|
+
|
|
12
|
+
GLOBAL_THIS.console.log(`Shellin with ${ENV['SHELL']} and commandin ${ARGV.join(', ')}`);
|
|
13
|
+
```
|
|
14
|
+
> ╸`ARGV` - [command-line arguments](https://nodejs.org/api/process.html#processargv)<br/>
|
|
15
|
+
> ╸`ENV` - [process environment](https://nodejs.org/api/process.html#processenv) <br/>
|
|
16
|
+
> ╸`GLOBAL_THIS` - [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) object; pollyfill'ed if missing, such as prehistoric node <12 versions<br/>
|
|
17
|
+
> ╸ All Runtimes/Globals Tested -> [./src/index.test.ts](https://github.com/fetchTe/globables/blob/master/src/index.test.ts)<br/>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
<br/>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#### ▎INSTALL
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
# pick your poison
|
|
27
|
+
npm install globables
|
|
28
|
+
bun add globables
|
|
29
|
+
pnpm add globables
|
|
30
|
+
yarn add globables
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Development/Contributing
|
|
36
|
+
|
|
37
|
+
Contributions, pull requests, and suggestions are appreciated. The following runtimes must be installed for you to test any changes and/or add additional tests: [Node.js](https://nodejs.org/), [Bun](https://bun.sh), [Deno](https://deno.com), [QuickJS-NG](https://quickjs-ng.github.io/quickjs/) and [Make](https://www.gnu.org/software/make/manual/make.html)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### ▎PULL REQUEST STEPS
|
|
41
|
+
|
|
42
|
+
1. Clone repository
|
|
43
|
+
2. Create and switch to a new branch for your work
|
|
44
|
+
3. Make and commit changes
|
|
45
|
+
4. Run `make release` to clean, setup, build, lint, and test
|
|
46
|
+
5. If everything checks out, push branch to repository and submit pull request
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#### ▎MAKEFILE REFERENCE
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
# USAGE
|
|
53
|
+
make [flags...] <target>
|
|
54
|
+
|
|
55
|
+
# TARGET
|
|
56
|
+
-------------------
|
|
57
|
+
run executes entry-point (./src/index.ts) via 'bun run'
|
|
58
|
+
release clean, setup, build, lint, test, aok (everything but the kitchen sink)
|
|
59
|
+
-------------------
|
|
60
|
+
build builds the .{js,d.ts} (skips: lint, test, and .min.* build)
|
|
61
|
+
build_cjs builds the .cjs export
|
|
62
|
+
build_esm builds the .js (esm) export
|
|
63
|
+
build_declarations builds typescript .d.{ts,mts,cts} declarations
|
|
64
|
+
-------------------
|
|
65
|
+
install installs dependencies via bun
|
|
66
|
+
update updates dependencies
|
|
67
|
+
update_dry lists dependencies that would be updated via 'make update'
|
|
68
|
+
-------------------
|
|
69
|
+
lint lints via tsc & eslint
|
|
70
|
+
lint_eslint lints via eslint
|
|
71
|
+
lint_eslint_fix lints and auto-fixes via eslint --fix
|
|
72
|
+
lint_tsc lints via tsc
|
|
73
|
+
lint_watch lints via eslint & tsc with fs.watch to continuously lint on change
|
|
74
|
+
-------------------
|
|
75
|
+
test runs bun test(s)
|
|
76
|
+
test_watch runs bun test(s) in watch mode
|
|
77
|
+
test_update runs bun test --update-snapshots
|
|
78
|
+
-------------------
|
|
79
|
+
help displays (this) help screen
|
|
80
|
+
|
|
81
|
+
# FLAGS
|
|
82
|
+
-------------------
|
|
83
|
+
BUN [? ] bun build flag(s) (e.g: make BUN="--banner='// bake until golden brown'")
|
|
84
|
+
-------------------
|
|
85
|
+
CJS [?1] builds the cjs (CommonJS) target on 'make release'
|
|
86
|
+
EXE [?js|mjs] default esm build extension
|
|
87
|
+
TAR [?0] build target env (-1=bun, 0=node, 1=dom, 2=dom+iife, 3=dom+iife+userscript)
|
|
88
|
+
MIN [?1] builds minified (*.min.{mjs,cjs,js}) targets on 'make release'
|
|
89
|
+
-------------------
|
|
90
|
+
BAIL [?1] fail fast (bail) on the first test or lint error
|
|
91
|
+
ENV [?DEV|PROD|TEST] sets the 'ENV' & 'IS_*' static build variables (else auto-set)
|
|
92
|
+
TEST [?0] sets the 'IS_TEST' static build variable (always 1 if test target)
|
|
93
|
+
WATCH [?0] sets the '--watch' flag for bun/tsc (e.g: WATCH=1 make test)
|
|
94
|
+
-------------------
|
|
95
|
+
DEBUG [?0] enables verbose logging and sets the 'IS_DEBUG' static build variable
|
|
96
|
+
QUIET [?0] disables pretty-printed/log target (INIT/DONE) info
|
|
97
|
+
NO_COLOR [?0] disables color logging/ANSI codes
|
|
98
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var exports_src = {};
|
|
31
|
+
__export(exports_src, {
|
|
32
|
+
GLOBAL_THIS: () => GLOBAL_THIS,
|
|
33
|
+
ENV: () => ENV,
|
|
34
|
+
ARGV: () => ARGV
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(exports_src);
|
|
37
|
+
var GLOBAL_THIS = /* @__PURE__ */ (() => typeof globalThis === "object" ? globalThis : (() => {
|
|
38
|
+
(function(Object2) {
|
|
39
|
+
function get() {
|
|
40
|
+
const e = this || self;
|
|
41
|
+
e.globalThis = e, delete Object2.prototype._T_;
|
|
42
|
+
}
|
|
43
|
+
typeof globalThis != "object" && (this ? get() : (Object2.defineProperty(Object2.prototype, "_T_", { configurable: true, get }), _T_));
|
|
44
|
+
})(Object);
|
|
45
|
+
return typeof globalThis === "object" ? globalThis : {};
|
|
46
|
+
})())();
|
|
47
|
+
var ARGV = /* @__PURE__ */ (() => typeof process === "undefined" ? typeof scriptArgs !== "undefined" ? scriptArgs : [] : (GLOBAL_THIS?.["Deno"] ? GLOBAL_THIS?.["Deno"]?.args ?? (process["args"]?.length ? process["args"] : process["argv"]) : process["argv"]) ?? [])();
|
|
48
|
+
var ENV = /* @__PURE__ */ (() => typeof process === "undefined" ? typeof GLOBAL_THIS?.["std"]?.getenviron === "function" ? GLOBAL_THIS["std"].getenviron?.() ?? {} : {} : !GLOBAL_THIS?.["Deno"] ? process["env"] : (() => {
|
|
49
|
+
try {
|
|
50
|
+
return GLOBAL_THIS?.["Deno"]?.env?.toObject?.() ?? (process["env"]?.toObject ? process["env"]?.toObject() : process["env"]);
|
|
51
|
+
} catch (_err) {}
|
|
52
|
+
return {};
|
|
53
|
+
})())();
|
|
54
|
+
|
|
55
|
+
//# debugId=595C4701BDF3FE0964756E2164756E21
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export type GlobalThis = typeof globalThis;\nexport type ProcessArgv = NodeJS.Process['argv'];\nexport type ProcessEnv = NodeJS.ProcessEnv;\n\n\n/**\n * globalThis object - with pollyfil in case of prehistoric node <12\n * @see {@link https://tc39.es/ecma262/multipage/global-object.html#sec-globalthis|globalThis spec - ECMAScript }\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis|globalThis docs - MDN}\n */\nexport const GLOBAL_THIS = /* @__PURE__ */ (() =>\n typeof globalThis === 'object'\n ? globalThis\n /**\n * globalThis pollyfill\n * @see {@link https://mathiasbynens.be/notes/globalthis}\n * @see {@link https://github.com/ungap/global-this}\n */\n : (() => {\n // @ts-expect-error - globalThis pollyfill for prehistoric node envs\n // eslint-disable-next-line\n !(function (Object) {function get() {const e = this || self; e.globalThis = e, delete Object.prototype._T_;}'object' != typeof globalThis && (this ? get() : (Object.defineProperty(Object.prototype, '_T_', {configurable:!0, get:get}), _T_));}(Object));\n // just in case\n return typeof globalThis === 'object' ? globalThis : {};\n })()\n)() as GlobalThis;\n\n\n/**\n * command-line arguments (pure/iffe wrapped so we can shake the tree)\n * @see {@link https://nodejs.org/api/process.html#processargv|process.argv - Node.js}\n * @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|scriptArgs - QuickJS}\n * @see {@link https://quickjs-ng.github.io/quickjs/stdlib#scriptargs|scriptArgs - QuickJS-NG}\n * @see {@link https://docs.deno.com/api/node/process/~/Process#property_argv|process.argv - Deno}\n * @see {@link https://docs.deno.com/api/deno/~/Deno.CommandOptions#property_args|Deno.args - Deno}\n */\nexport const ARGV: NodeJS.Process['argv'] = /* @__PURE__ */ (() =>\n typeof process === 'undefined'\n /** quickJs {@link https://bellard.org/quickjs/quickjs.html#Global-objects} */\n ? typeof scriptArgs !== 'undefined'\n ? scriptArgs\n : []\n : ((GLOBAL_THIS as never)?.['Deno']\n // @NOTE: DENO.args does not require any perm requests\n // @NOTE: if --allow-all is used, no args (like --allow-env), use default\n // @ts-expect-error deno uses 'args' rather than 'argv'\n ? (GLOBAL_THIS as never)?.['Deno']?.args\n // @ts-expect-error deno uses 'args' rather than 'argv'\n ?? (process['args']?.length ? process['args'] : process['argv'])\n : process['argv']\n ) ?? []\n)();\n\n\n/**\n * process environment (ENV) variables\n * @see {@link https://nodejs.org/api/process.html#processenv|process.env - Node.js}\n * @see {@link https://docs.deno.com/runtime/reference/env_variables/#built-in-deno.env|env - Deno}\n * @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|getenviron - QuickJS}\n * @see {@link https://quickjs-ng.github.io/quickjs/stdlib#getenviron|getenviron - QuickJS-NG}\n */\nexport const ENV = /* @__PURE__ */ (() => typeof process === 'undefined'\n // @ts-expect-error quickjs std\n ? typeof (GLOBAL_THIS as never)?.['std']?.getenviron === 'function'\n // @ts-expect-error quickjs std\n ? ((GLOBAL_THIS as never)['std'].getenviron?.() ?? {})\n : {}\n : (!(GLOBAL_THIS as never)?.['Deno']\n ? process['env']\n : (() => {\n try {\n // @NOTE: if --allow-all is used, no toObject (like --allow-env), use default\n // @NOTE: DENO.env.toObject only requires one perm request while process requires many\n // @ts-expect-error deno perms\n // eslint-disable-next-line @stylistic/max-len\n return (GLOBAL_THIS as never)?.['Deno']?.env?.toObject?.() ?? (process['env']?.toObject ? process['env']?.toObject() : process['env']);\n } catch (_err) { /* ignore */ }\n return {};\n })())\n)() as ProcessEnv;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAM,+BAA+B,MAC1C,OAAO,eAAe,WAClB,cAMC,MAAM;AAAA,GAGL,QAAS,CAAC,SAAQ;AAAA,IAAC,SAAS,GAAG,GAAG;AAAA,MAAC,MAAM,IAAI,QAAQ;AAAA,MAAM,EAAE,aAAa,GAAG,OAAO,QAAO,UAAU;AAAA;AAAA,IAAiB,OAAO,cAAnB,aAAkC,OAAO,IAAI,KAAK,QAAO,eAAe,QAAO,WAAW,OAAO,EAAC,cAAa,MAAI,IAAO,CAAC,GAAG;AAAA,KAAQ,MAAM;AAAA,EAExP,OAAO,OAAO,eAAe,WAAW,aAAa,CAAC;AAAA,GACrD,GACL;AAWK,IAAM,wBAAgD,MAC3D,OAAO,YAAY,cAEf,OAAO,eAAe,cACpB,aACA,CAAC,KACD,cAAwB,UAIvB,cAAwB,SAAS,SAE9B,QAAQ,SAAS,SAAS,QAAQ,UAAU,QAAQ,WACxD,QAAQ,YACP,CAAC,GACR;AAUK,IAAM,uBAAuB,MAAM,OAAO,YAAY,cAEzD,OAAQ,cAAwB,QAAQ,eAAe,aAEnD,YAAsB,OAAO,aAAa,KAAK,CAAC,IAClD,CAAC,KACA,cAAwB,UACzB,QAAQ,UACP,MAAM;AAAA,EACP,IAAI;AAAA,IAKF,OAAQ,cAAwB,SAAS,KAAK,WAAW,MAAM,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,SAAS,IAAI,QAAQ;AAAA,IAC/H,OAAO,MAAM;AAAA,EACf,OAAO,CAAC;AAAA,GACP,GACL;",
|
|
8
|
+
"debugId": "595C4701BDF3FE0964756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type GlobalThis = typeof globalThis;
|
|
2
|
+
export type ProcessArgv = NodeJS.Process['argv'];
|
|
3
|
+
export type ProcessEnv = NodeJS.ProcessEnv;
|
|
4
|
+
/**
|
|
5
|
+
* globalThis object - with pollyfil in case of prehistoric node <12
|
|
6
|
+
* @see {@link https://tc39.es/ecma262/multipage/global-object.html#sec-globalthis|globalThis spec - ECMAScript }
|
|
7
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis|globalThis docs - MDN}
|
|
8
|
+
*/
|
|
9
|
+
export declare const GLOBAL_THIS: GlobalThis;
|
|
10
|
+
/**
|
|
11
|
+
* command-line arguments (pure/iffe wrapped so we can shake the tree)
|
|
12
|
+
* @see {@link https://nodejs.org/api/process.html#processargv|process.argv - Node.js}
|
|
13
|
+
* @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|scriptArgs - QuickJS}
|
|
14
|
+
* @see {@link https://quickjs-ng.github.io/quickjs/stdlib#scriptargs|scriptArgs - QuickJS-NG}
|
|
15
|
+
* @see {@link https://docs.deno.com/api/node/process/~/Process#property_argv|process.argv - Deno}
|
|
16
|
+
* @see {@link https://docs.deno.com/api/deno/~/Deno.CommandOptions#property_args|Deno.args - Deno}
|
|
17
|
+
*/
|
|
18
|
+
export declare const ARGV: NodeJS.Process['argv'];
|
|
19
|
+
/**
|
|
20
|
+
* process environment (ENV) variables
|
|
21
|
+
* @see {@link https://nodejs.org/api/process.html#processenv|process.env - Node.js}
|
|
22
|
+
* @see {@link https://docs.deno.com/runtime/reference/env_variables/#built-in-deno.env|env - Deno}
|
|
23
|
+
* @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|getenviron - QuickJS}
|
|
24
|
+
* @see {@link https://quickjs-ng.github.io/quickjs/stdlib#getenviron|getenviron - QuickJS-NG}
|
|
25
|
+
*/
|
|
26
|
+
export declare const ENV: ProcessEnv;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type GlobalThis = typeof globalThis;
|
|
2
|
+
export type ProcessArgv = NodeJS.Process['argv'];
|
|
3
|
+
export type ProcessEnv = NodeJS.ProcessEnv;
|
|
4
|
+
/**
|
|
5
|
+
* globalThis object - with pollyfil in case of prehistoric node <12
|
|
6
|
+
* @see {@link https://tc39.es/ecma262/multipage/global-object.html#sec-globalthis|globalThis spec - ECMAScript }
|
|
7
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis|globalThis docs - MDN}
|
|
8
|
+
*/
|
|
9
|
+
export declare const GLOBAL_THIS: GlobalThis;
|
|
10
|
+
/**
|
|
11
|
+
* command-line arguments (pure/iffe wrapped so we can shake the tree)
|
|
12
|
+
* @see {@link https://nodejs.org/api/process.html#processargv|process.argv - Node.js}
|
|
13
|
+
* @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|scriptArgs - QuickJS}
|
|
14
|
+
* @see {@link https://quickjs-ng.github.io/quickjs/stdlib#scriptargs|scriptArgs - QuickJS-NG}
|
|
15
|
+
* @see {@link https://docs.deno.com/api/node/process/~/Process#property_argv|process.argv - Deno}
|
|
16
|
+
* @see {@link https://docs.deno.com/api/deno/~/Deno.CommandOptions#property_args|Deno.args - Deno}
|
|
17
|
+
*/
|
|
18
|
+
export declare const ARGV: NodeJS.Process['argv'];
|
|
19
|
+
/**
|
|
20
|
+
* process environment (ENV) variables
|
|
21
|
+
* @see {@link https://nodejs.org/api/process.html#processenv|process.env - Node.js}
|
|
22
|
+
* @see {@link https://docs.deno.com/runtime/reference/env_variables/#built-in-deno.env|env - Deno}
|
|
23
|
+
* @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|getenviron - QuickJS}
|
|
24
|
+
* @see {@link https://quickjs-ng.github.io/quickjs/stdlib#getenviron|getenviron - QuickJS-NG}
|
|
25
|
+
*/
|
|
26
|
+
export declare const ENV: ProcessEnv;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type GlobalThis = typeof globalThis;
|
|
2
|
+
export type ProcessArgv = NodeJS.Process['argv'];
|
|
3
|
+
export type ProcessEnv = NodeJS.ProcessEnv;
|
|
4
|
+
/**
|
|
5
|
+
* globalThis object - with pollyfil in case of prehistoric node <12
|
|
6
|
+
* @see {@link https://tc39.es/ecma262/multipage/global-object.html#sec-globalthis|globalThis spec - ECMAScript }
|
|
7
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis|globalThis docs - MDN}
|
|
8
|
+
*/
|
|
9
|
+
export declare const GLOBAL_THIS: GlobalThis;
|
|
10
|
+
/**
|
|
11
|
+
* command-line arguments (pure/iffe wrapped so we can shake the tree)
|
|
12
|
+
* @see {@link https://nodejs.org/api/process.html#processargv|process.argv - Node.js}
|
|
13
|
+
* @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|scriptArgs - QuickJS}
|
|
14
|
+
* @see {@link https://quickjs-ng.github.io/quickjs/stdlib#scriptargs|scriptArgs - QuickJS-NG}
|
|
15
|
+
* @see {@link https://docs.deno.com/api/node/process/~/Process#property_argv|process.argv - Deno}
|
|
16
|
+
* @see {@link https://docs.deno.com/api/deno/~/Deno.CommandOptions#property_args|Deno.args - Deno}
|
|
17
|
+
*/
|
|
18
|
+
export declare const ARGV: NodeJS.Process['argv'];
|
|
19
|
+
/**
|
|
20
|
+
* process environment (ENV) variables
|
|
21
|
+
* @see {@link https://nodejs.org/api/process.html#processenv|process.env - Node.js}
|
|
22
|
+
* @see {@link https://docs.deno.com/runtime/reference/env_variables/#built-in-deno.env|env - Deno}
|
|
23
|
+
* @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|getenviron - QuickJS}
|
|
24
|
+
* @see {@link https://quickjs-ng.github.io/quickjs/stdlib#getenviron|getenviron - QuickJS-NG}
|
|
25
|
+
*/
|
|
26
|
+
export declare const ENV: ProcessEnv;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC;AAC3C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;AAG3C;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAejB,UAAU,CAAC;AAGlB;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAerC,CAAC;AAGJ;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,EAkBT,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var GLOBAL_THIS = /* @__PURE__ */ (() => typeof globalThis === "object" ? globalThis : (() => {
|
|
3
|
+
(function(Object2) {
|
|
4
|
+
function get() {
|
|
5
|
+
const e = this || self;
|
|
6
|
+
e.globalThis = e, delete Object2.prototype._T_;
|
|
7
|
+
}
|
|
8
|
+
typeof globalThis != "object" && (this ? get() : (Object2.defineProperty(Object2.prototype, "_T_", { configurable: true, get }), _T_));
|
|
9
|
+
})(Object);
|
|
10
|
+
return typeof globalThis === "object" ? globalThis : {};
|
|
11
|
+
})())();
|
|
12
|
+
var ARGV = /* @__PURE__ */ (() => typeof process === "undefined" ? typeof scriptArgs !== "undefined" ? scriptArgs : [] : (GLOBAL_THIS?.["Deno"] ? GLOBAL_THIS?.["Deno"]?.args ?? (process["args"]?.length ? process["args"] : process["argv"]) : process["argv"]) ?? [])();
|
|
13
|
+
var ENV = /* @__PURE__ */ (() => typeof process === "undefined" ? typeof GLOBAL_THIS?.["std"]?.getenviron === "function" ? GLOBAL_THIS["std"].getenviron?.() ?? {} : {} : !GLOBAL_THIS?.["Deno"] ? process["env"] : (() => {
|
|
14
|
+
try {
|
|
15
|
+
return GLOBAL_THIS?.["Deno"]?.env?.toObject?.() ?? (process["env"]?.toObject ? process["env"]?.toObject() : process["env"]);
|
|
16
|
+
} catch (_err) {}
|
|
17
|
+
return {};
|
|
18
|
+
})())();
|
|
19
|
+
export {
|
|
20
|
+
GLOBAL_THIS,
|
|
21
|
+
ENV,
|
|
22
|
+
ARGV
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# debugId=3025BAE9C191ECCF64756E2164756E21
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export type GlobalThis = typeof globalThis;\nexport type ProcessArgv = NodeJS.Process['argv'];\nexport type ProcessEnv = NodeJS.ProcessEnv;\n\n\n/**\n * globalThis object - with pollyfil in case of prehistoric node <12\n * @see {@link https://tc39.es/ecma262/multipage/global-object.html#sec-globalthis|globalThis spec - ECMAScript }\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis|globalThis docs - MDN}\n */\nexport const GLOBAL_THIS = /* @__PURE__ */ (() =>\n typeof globalThis === 'object'\n ? globalThis\n /**\n * globalThis pollyfill\n * @see {@link https://mathiasbynens.be/notes/globalthis}\n * @see {@link https://github.com/ungap/global-this}\n */\n : (() => {\n // @ts-expect-error - globalThis pollyfill for prehistoric node envs\n // eslint-disable-next-line\n !(function (Object) {function get() {const e = this || self; e.globalThis = e, delete Object.prototype._T_;}'object' != typeof globalThis && (this ? get() : (Object.defineProperty(Object.prototype, '_T_', {configurable:!0, get:get}), _T_));}(Object));\n // just in case\n return typeof globalThis === 'object' ? globalThis : {};\n })()\n)() as GlobalThis;\n\n\n/**\n * command-line arguments (pure/iffe wrapped so we can shake the tree)\n * @see {@link https://nodejs.org/api/process.html#processargv|process.argv - Node.js}\n * @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|scriptArgs - QuickJS}\n * @see {@link https://quickjs-ng.github.io/quickjs/stdlib#scriptargs|scriptArgs - QuickJS-NG}\n * @see {@link https://docs.deno.com/api/node/process/~/Process#property_argv|process.argv - Deno}\n * @see {@link https://docs.deno.com/api/deno/~/Deno.CommandOptions#property_args|Deno.args - Deno}\n */\nexport const ARGV: NodeJS.Process['argv'] = /* @__PURE__ */ (() =>\n typeof process === 'undefined'\n /** quickJs {@link https://bellard.org/quickjs/quickjs.html#Global-objects} */\n ? typeof scriptArgs !== 'undefined'\n ? scriptArgs\n : []\n : ((GLOBAL_THIS as never)?.['Deno']\n // @NOTE: DENO.args does not require any perm requests\n // @NOTE: if --allow-all is used, no args (like --allow-env), use default\n // @ts-expect-error deno uses 'args' rather than 'argv'\n ? (GLOBAL_THIS as never)?.['Deno']?.args\n // @ts-expect-error deno uses 'args' rather than 'argv'\n ?? (process['args']?.length ? process['args'] : process['argv'])\n : process['argv']\n ) ?? []\n)();\n\n\n/**\n * process environment (ENV) variables\n * @see {@link https://nodejs.org/api/process.html#processenv|process.env - Node.js}\n * @see {@link https://docs.deno.com/runtime/reference/env_variables/#built-in-deno.env|env - Deno}\n * @see {@link https://bellard.org/quickjs/quickjs.html#Global-objects|getenviron - QuickJS}\n * @see {@link https://quickjs-ng.github.io/quickjs/stdlib#getenviron|getenviron - QuickJS-NG}\n */\nexport const ENV = /* @__PURE__ */ (() => typeof process === 'undefined'\n // @ts-expect-error quickjs std\n ? typeof (GLOBAL_THIS as never)?.['std']?.getenviron === 'function'\n // @ts-expect-error quickjs std\n ? ((GLOBAL_THIS as never)['std'].getenviron?.() ?? {})\n : {}\n : (!(GLOBAL_THIS as never)?.['Deno']\n ? process['env']\n : (() => {\n try {\n // @NOTE: if --allow-all is used, no toObject (like --allow-env), use default\n // @NOTE: DENO.env.toObject only requires one perm request while process requires many\n // @ts-expect-error deno perms\n // eslint-disable-next-line @stylistic/max-len\n return (GLOBAL_THIS as never)?.['Deno']?.env?.toObject?.() ?? (process['env']?.toObject ? process['env']?.toObject() : process['env']);\n } catch (_err) { /* ignore */ }\n return {};\n })())\n)() as ProcessEnv;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAUO,IAAM,+BAA+B,MAC1C,OAAO,eAAe,WAClB,cAMC,MAAM;AAAA,GAGL,QAAS,CAAC,SAAQ;AAAA,IAAC,SAAS,GAAG,GAAG;AAAA,MAAC,MAAM,IAAI,QAAQ;AAAA,MAAM,EAAE,aAAa,GAAG,OAAO,QAAO,UAAU;AAAA;AAAA,IAAiB,OAAO,cAAnB,aAAkC,OAAO,IAAI,KAAK,QAAO,eAAe,QAAO,WAAW,OAAO,EAAC,cAAa,MAAI,IAAO,CAAC,GAAG;AAAA,KAAQ,MAAM;AAAA,EAExP,OAAO,OAAO,eAAe,WAAW,aAAa,CAAC;AAAA,GACrD,GACL;AAWK,IAAM,wBAAgD,MAC3D,OAAO,YAAY,cAEf,OAAO,eAAe,cACpB,aACA,CAAC,KACD,cAAwB,UAIvB,cAAwB,SAAS,SAE9B,QAAQ,SAAS,SAAS,QAAQ,UAAU,QAAQ,WACxD,QAAQ,YACP,CAAC,GACR;AAUK,IAAM,uBAAuB,MAAM,OAAO,YAAY,cAEzD,OAAQ,cAAwB,QAAQ,eAAe,aAEnD,YAAsB,OAAO,aAAa,KAAK,CAAC,IAClD,CAAC,KACA,cAAwB,UACzB,QAAQ,UACP,MAAM;AAAA,EACP,IAAI;AAAA,IAKF,OAAQ,cAAwB,SAAS,KAAK,WAAW,MAAM,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,SAAS,IAAI,QAAQ;AAAA,IAC/H,OAAO,MAAM;AAAA,EACf,OAAO,CAAC;AAAA,GACP,GACL;",
|
|
8
|
+
"debugId": "3025BAE9C191ECCF64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{defineProperty:u,getOwnPropertyNames:w,getOwnPropertyDescriptor:z}=Object,C=Object.prototype.hasOwnProperty;var v=new WeakMap,D=(f)=>{var h=v.get(f),k;if(h)return h;if(h=u({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")w(f).map((q)=>!C.call(h,q)&&u(h,q,{get:()=>f[q],enumerable:!(k=z(f,q))||k.enumerable}));return v.set(f,h),h};var E=(f,h)=>{for(var k in h)u(f,k,{get:h[k],enumerable:!0,configurable:!0,set:(q)=>h[k]=()=>q})};var K={};E(K,{GLOBAL_THIS:()=>p,ENV:()=>J,ARGV:()=>F});module.exports=D(K);var p=(()=>typeof globalThis==="object"?globalThis:(()=>{return function(f){function h(){let k=this||self;k.globalThis=k,delete f.prototype._T_}typeof globalThis!="object"&&(this?h():(f.defineProperty(f.prototype,"_T_",{configurable:!0,get:h}),_T_))}(Object),typeof globalThis==="object"?globalThis:{}})())(),F=(()=>typeof process==="undefined"?typeof scriptArgs!=="undefined"?scriptArgs:[]:(p?.Deno?p?.Deno?.args??(process.args?.length?process.args:process.argv):process.argv)??[])(),J=(()=>typeof process==="undefined"?typeof p?.std?.getenviron==="function"?p.std.getenviron?.()??{}:{}:!p?.Deno?process.env:(()=>{try{return p?.Deno?.env?.toObject?.()??(process.env?.toObject?process.env?.toObject():process.env)}catch(f){}return{}})())();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var f=(()=>typeof globalThis==="object"?globalThis:(()=>{return function(h){function k(){let p=this||self;p.globalThis=p,delete h.prototype._T_}typeof globalThis!="object"&&(this?k():(h.defineProperty(h.prototype,"_T_",{configurable:!0,get:k}),_T_))}(Object),typeof globalThis==="object"?globalThis:{}})())(),q=(()=>typeof process==="undefined"?typeof scriptArgs!=="undefined"?scriptArgs:[]:(f?.Deno?f?.Deno?.args??(process.args?.length?process.args:process.argv):process.argv)??[])(),u=(()=>typeof process==="undefined"?typeof f?.std?.getenviron==="function"?f.std.getenviron?.()??{}:{}:!f?.Deno?process.env:(()=>{try{return f?.Deno?.env?.toObject?.()??(process.env?.toObject?process.env?.toObject():process.env)}catch(h){}return{}})())();export{f as GLOBAL_THIS,u as ENV,q as ARGV};
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "globables",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI/ENV constants for Node.js-like runtimes, supports: Node.js, Deno, Bun, QuickJS, and QuickJS-NG",
|
|
5
|
+
"homepage": "https://github.com/fetchTe/globables",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": ["cli", "env", "argv", "globalThis", "Node.js", "Deno", "Bun", "QuickJS", "QuickJS-NG"],
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "make release",
|
|
15
|
+
"test": "make test"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@eslint/js": "9.35.0",
|
|
20
|
+
"@stylistic/eslint-plugin": "5.3.1",
|
|
21
|
+
"@types/bun": "1.2.21",
|
|
22
|
+
"@types/eslint": "9.6.1",
|
|
23
|
+
"@types/node": "24.3.3",
|
|
24
|
+
"@typescript-eslint/parser": "8.43.0",
|
|
25
|
+
"eslint": "9.35.0",
|
|
26
|
+
"typescript": "5.9.2",
|
|
27
|
+
"typescript-eslint": "8.43.0"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
33
|
+
"default": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./index": {
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/index.d.cts",
|
|
43
|
+
"default": "./dist/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/index.d.mts",
|
|
47
|
+
"default": "./dist/index.js"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"author": {
|
|
52
|
+
"email": "git@fetchte.com",
|
|
53
|
+
"name": "fetchTe",
|
|
54
|
+
"url": "https://github.com/fetchTe/globables"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"email": "git@fetchte.com",
|
|
58
|
+
"url": "https://github.com/fetchTe/globables/issues"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=14.15.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/fetchTe/globables.git"
|
|
69
|
+
}
|
|
70
|
+
}
|