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