@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 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
@@ -0,0 +1,5 @@
1
+ import { GlobalObject } from "./globalThis"
2
+
3
+ declare function globalPolyfill(): GlobalObject
4
+
5
+ export = globalPolyfill
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
@@ -0,0 +1,5 @@
1
+ export type GlobalObject = typeof globalThis
2
+
3
+ declare const globalObject: GlobalObject
4
+
5
+ export = globalObject
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 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
-
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.0.0",
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
- "function-intrinsic-ai": "^1.0.1",
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
- "symbol": "^0.3.1"
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
@@ -0,0 +1,3 @@
1
+ declare const process: NodeJS.Process
2
+
3
+ export = process