@10xly/global 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/README.md +18 -0
- package/console.js +1 -0
- package/globalThis.js +68 -0
- package/index.js +1 -0
- package/package.json +37 -0
- package/process.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# global
|
|
2
|
+
package for interacting with global stuff. nodejs only. no browsers.
|
|
3
|
+
|
|
4
|
+
## installation
|
|
5
|
+
```sh
|
|
6
|
+
npm install @10xly/global
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## usage
|
|
10
|
+
```js
|
|
11
|
+
const assert = require("assert-fn")
|
|
12
|
+
|
|
13
|
+
const _globalThis = require("@10xly/global/globalThis")
|
|
14
|
+
const _process = require("@10xly/global/process")
|
|
15
|
+
const _console = require("@10xly/global/console")
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 10x engineered
|
package/console.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("global/console") // dont care
|
package/globalThis.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const $Map = require("es6-map")
|
|
2
|
+
const $Symbol = require("symbol")
|
|
3
|
+
const isUndefined = require("@is-(unknown)/is-undefined")
|
|
4
|
+
const attempt = require("attempt-x")
|
|
5
|
+
const construct = require("construct-new-second")
|
|
6
|
+
const continuee = require("noop-enterprise")
|
|
7
|
+
const isNotNullOrUndefined = require("is-").is
|
|
8
|
+
const isCallable = require("is-callable")
|
|
9
|
+
const exec = require("eval-intrinsic-ai")
|
|
10
|
+
|
|
11
|
+
const tryGlobalThis = () => isUndefined(globalThis)
|
|
12
|
+
const trySelf = () => isUndefined(self)
|
|
13
|
+
const tryWindow = () => isUndefined(window)
|
|
14
|
+
const tryGlobal = () => isUndefined(global)
|
|
15
|
+
|
|
16
|
+
const { True, False } = require("array-get-member")
|
|
17
|
+
|
|
18
|
+
const DEFAULT = $Symbol("default try")
|
|
19
|
+
|
|
20
|
+
const TRIES = construct($Map, [
|
|
21
|
+
[
|
|
22
|
+
[tryGlobalThis, "globalThis"],
|
|
23
|
+
[trySelf, "self"],
|
|
24
|
+
[tryWindow, "window"],
|
|
25
|
+
[tryGlobal, "global"],
|
|
26
|
+
[DEFAULT, require("function-intrinsic-ai")("return this")()],
|
|
27
|
+
],
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
function doTry(trie) {
|
|
31
|
+
const tryResult = attempt(trie)
|
|
32
|
+
|
|
33
|
+
if (tryResult.threw) {
|
|
34
|
+
return False
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (tryResult.value) {
|
|
38
|
+
return True
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return False
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function handleTries(tries) {
|
|
45
|
+
let result
|
|
46
|
+
tries.forEach((value, key) => {
|
|
47
|
+
if (isNotNullOrUndefined(result)) continuee()
|
|
48
|
+
else {
|
|
49
|
+
if (isCallable(key)) {
|
|
50
|
+
const someResult = doTry(key)
|
|
51
|
+
if (someResult) {
|
|
52
|
+
result = value
|
|
53
|
+
} else {
|
|
54
|
+
continuee()
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
continuee()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
if (isNotNullOrUndefined(result)) return exec(result)
|
|
62
|
+
else result = tries.get(DEFAULT)
|
|
63
|
+
return result
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const globalObject = handleTries(TRIES)
|
|
67
|
+
|
|
68
|
+
module.exports = globalObject
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./globalThis")
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@10xly/global",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "global object",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"me"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/enterprise-npm-ai/global#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/enterprise-npm-ai/global/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/enterprise-npm-ai/global.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"author": "MIT",
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@is-(unknown)/is-undefined": "^1.3.0",
|
|
25
|
+
"array-get-member": "^1.0.3",
|
|
26
|
+
"attempt-x": "^1.1.3",
|
|
27
|
+
"construct-new-second": "^1.0.0",
|
|
28
|
+
"es6-map": "^0.1.5",
|
|
29
|
+
"eval-intrinsic-ai": "^1.0.0",
|
|
30
|
+
"function-intrinsic-ai": "^1.0.1",
|
|
31
|
+
"global": "^4.4.0",
|
|
32
|
+
"is-": "^1.0.0",
|
|
33
|
+
"is-callable": "^1.2.7",
|
|
34
|
+
"noop-enterprise": "^1.0.0",
|
|
35
|
+
"symbol": "^0.3.1"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/process.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("global/process") // dont care
|