@10xly/global 1.0.0 → 1.1.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 +17 -17
- package/_polyfill.js +14 -0
- package/globalThis.js +69 -67
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,18 +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
|
-
|
|
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
18
|
## 10x engineered
|
package/_polyfill.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = function () {
|
|
2
|
+
const defineProperty = require("es-define-property")
|
|
3
|
+
const ObjectPrototype = require("object.prototype-intrinsic-ai")
|
|
4
|
+
|
|
5
|
+
defineProperty(ObjectPrototype, "__magic__", {
|
|
6
|
+
get: function () {
|
|
7
|
+
return this
|
|
8
|
+
},
|
|
9
|
+
configurable: require("true-value")(),
|
|
10
|
+
})
|
|
11
|
+
const magic = __magic__
|
|
12
|
+
delete ObjectPrototype.__magic__
|
|
13
|
+
return magic
|
|
14
|
+
}
|
package/globalThis.js
CHANGED
|
@@ -1,68 +1,70 @@
|
|
|
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
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return result
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 globalPolyfill = require("./_polyfill")
|
|
12
|
+
|
|
13
|
+
const tryGlobalThis = () => isUndefined(globalThis)
|
|
14
|
+
const trySelf = () => isUndefined(self)
|
|
15
|
+
const tryWindow = () => isUndefined(window)
|
|
16
|
+
const tryGlobal = () => isUndefined(global)
|
|
17
|
+
|
|
18
|
+
const True = require("true-value")(), False = require("false-value")()
|
|
19
|
+
|
|
20
|
+
const DEFAULT = $Symbol("default try")
|
|
21
|
+
|
|
22
|
+
const TRIES = construct($Map, [
|
|
23
|
+
[
|
|
24
|
+
[tryGlobalThis, "globalThis"],
|
|
25
|
+
[trySelf, "self"],
|
|
26
|
+
[tryWindow, "window"],
|
|
27
|
+
[tryGlobal, "global"],
|
|
28
|
+
[DEFAULT, globalPolyfill()],
|
|
29
|
+
],
|
|
30
|
+
])
|
|
31
|
+
|
|
32
|
+
function doTry(trie) {
|
|
33
|
+
const tryResult = attempt(trie)
|
|
34
|
+
|
|
35
|
+
if (tryResult.threw) {
|
|
36
|
+
return False
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (tryResult.value) {
|
|
40
|
+
return True
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return False
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function handleTries(tries) {
|
|
47
|
+
let result
|
|
48
|
+
tries.forEach((value, key) => {
|
|
49
|
+
if (isNotNullOrUndefined(result)) continuee()
|
|
50
|
+
else {
|
|
51
|
+
if (isCallable(key)) {
|
|
52
|
+
const someResult = doTry(key)
|
|
53
|
+
if (someResult) {
|
|
54
|
+
result = value
|
|
55
|
+
} else {
|
|
56
|
+
continuee()
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
continuee()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
if (isNotNullOrUndefined(result)) return exec(result)
|
|
64
|
+
else result = tries.get(DEFAULT)
|
|
65
|
+
return result
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const globalObject = handleTries(TRIES)
|
|
69
|
+
|
|
68
70
|
module.exports = globalObject
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@10xly/global",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "global object",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"me"
|
|
@@ -22,16 +22,18 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@is-(unknown)/is-undefined": "^1.3.0",
|
|
25
|
-
"array-get-member": "^1.0.3",
|
|
26
25
|
"attempt-x": "^1.1.3",
|
|
27
26
|
"construct-new-second": "^1.0.0",
|
|
27
|
+
"es-define-property": "1.0.1",
|
|
28
28
|
"es6-map": "^0.1.5",
|
|
29
29
|
"eval-intrinsic-ai": "^1.0.0",
|
|
30
|
-
"
|
|
30
|
+
"false-value": "2.0.6",
|
|
31
31
|
"global": "^4.4.0",
|
|
32
32
|
"is-": "^1.0.0",
|
|
33
33
|
"is-callable": "^1.2.7",
|
|
34
34
|
"noop-enterprise": "^1.0.0",
|
|
35
|
-
"
|
|
35
|
+
"object.prototype-intrinsic-ai": "1.0.1",
|
|
36
|
+
"symbol": "^0.3.1",
|
|
37
|
+
"true-value": "3.0.0"
|
|
36
38
|
}
|
|
37
39
|
}
|