@lumjs/core 1.37.1 → 1.37.2

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/lib/types/def.js CHANGED
@@ -1,7 +1,7 @@
1
- // Thanks to CJS `require()` rules, recursive dependencies are possible.
2
- const unbound = require('./root').unbound;
3
- const {F, B} = require('./js');
4
- const {isObj, isNil, isProperty, doesDescriptor} = require('./basics');
1
+ "use strict";
2
+
3
+ const {F,B} = require('./js');
4
+ const {isObj,isNil,isProperty,doesDescriptor} = require('./basics');
5
5
  const clone = (...args) => Object.assign({}, ...args);
6
6
 
7
7
  /**
@@ -95,9 +95,10 @@ const clone = (...args) => Object.assign({}, ...args);
95
95
  */
96
96
  function def(obj, name, value, opts)
97
97
  {
98
- const isBound // Is this a 'bound' def function?
99
- = !unbound(this, true, true)
100
- && typeof this.bound === F;
98
+ const isBound
99
+ = isObj(this)
100
+ && typeof this.bound === F
101
+ && this.bound.$this === this;
101
102
 
102
103
  if (isNil(name) || typeof name === B)
103
104
  { // Binding of Isaac?
package/lib/types/root.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const {U} = require('./js');
2
- const {isNil,isArray} = require('./basics');
2
+ const {isNil,isObj,isArray} = require('./basics');
3
3
 
4
4
  // «private»
5
5
  function no_root()
@@ -11,40 +11,81 @@ function no_root()
11
11
  * The global root object. Usually `globalThis` these days.
12
12
  * @alias module:@lumjs/core/types.root
13
13
  */
14
- const root = typeof globalThis !== U ? globalThis
15
- : typeof global !== U ? global
16
- : typeof self !== U ? self
17
- : typeof window !== U ? window
14
+ const root
15
+ = typeof globalThis !== U ? globalThis
16
+ : typeof global !== U ? global
17
+ : typeof self !== U ? self
18
+ : typeof window !== U ? window
18
19
  : no_root(); // Unlike the old way, we'll die if the environment is undetermined.
19
20
 
20
21
  exports.root = root;
21
22
 
22
- // A list of objects to be considered unbound globally.
23
+ // A Set of objects to be considered unbound globally.
23
24
  const unboundObjects = require('./unbound/objects');
24
25
 
26
+ // Default options for unbound()
27
+ const UBDO =
28
+ {
29
+ nil: true,
30
+ root: true,
31
+ }
32
+
25
33
  /**
26
34
  * Pass `this` here to see if it is bound to an object.
27
35
  *
28
- * Always considers `null` and `undefined` as unbound.
36
+ * @param {*} whatIsThis - The `this` from any context
37
+ *
38
+ * @param {(boolean|object)} [opts] Options for advanced behaviours.
39
+ *
40
+ * If this is boolean then it'll be used as `opts.root`;
41
+ * If it is an `Array` or `Set` it will be used as `opts.list`;
42
+ * Use just a plain object literal for specifying named options.
43
+ *
44
+ * TODO: as of v2.0 this will no longer accept a boolean value
45
+ * as a shortcut to `opts.root`. That must be explicitly set.
46
+ *
47
+ * @param {boolean} [opts.root=true] The global root is unbound?
48
+ * @param {boolean} [opts.nil=true] `null` and `undefined` are unbound?
49
+ * @param {(Array|Set)} [opts.list] A list of additional values that
50
+ * for the purposes of this test will be considered unbound.
51
+ *
52
+ * @param {(Array|Set|boolean)} [list] A positional version of `opts.list`;
53
+ * ONLY used when the `opts` argument is boolean.
54
+ *
55
+ * TODO: remove this argument as of v2.0
29
56
  *
30
- * @param {*} whatIsThis - The `this` from any context.
31
- * @param {boolean} [rootIsUnbound=true] The global root is unbound.
32
- * @param {(boolean|Array)} [areUnbound=false] A list of unbound objects.
33
- * If the is `true` we use an global list that can register special
34
- * internal objects. Otherwise an `Array` of unbound objects may be used.
35
57
  * @returns {boolean}
36
58
  * @alias module:@lumjs/core/types.unbound
37
59
  */
38
- function unbound(whatIsThis, rootIsUnbound=true, areUnbound=false)
60
+ function unbound(whatIsThis, opts=true, list)
39
61
  {
40
- if (areUnbound === true)
41
- { // If areUnbound is true, we use the unboundObjects
42
- areUnbound = unboundObjects;
62
+ if (isObj(opts))
63
+ { // Merge in defaults
64
+ if (opts instanceof Set || isArray(opts))
65
+ { // A shortcut to the `list` property
66
+ list = opts;
67
+ opts = Object.assign({}, UBDO);
68
+ }
69
+ else
70
+ { // Regular options were specified.
71
+ opts = Object.assign({}, UBDO, {list}, opts);
72
+ list = opts.list;
73
+ }
74
+ }
75
+ else
76
+ { // Assume old positional arguments are being used
77
+ opts = Object.assign({}, UBDO, {root: opts});
78
+ }
79
+
80
+ if (list === true)
81
+ { // Internal special unbound values
82
+ list = unboundObjects;
43
83
  }
44
84
 
45
- if (isNil(whatIsThis)) return true;
46
- if (rootIsUnbound && whatIsThis === root) return true;
47
- if (isArray(areUnbound) && areUnbound.includes(whatIsThis)) return true;
85
+ if (opts.nil && isNil(whatIsThis)) return true;
86
+ if (opts.root && whatIsThis === root) return true;
87
+ if (list instanceof Set && list.has(whatIsThis)) return true;
88
+ if (isArray(list) && list.includes(whatIsThis)) return true;
48
89
 
49
90
  // Nothing considered unbound.
50
91
  return false;
@@ -2,45 +2,41 @@
2
2
 
3
3
  const def = require('../def');
4
4
  const {needObj} = require('../needs');
5
- const removeFromArray = require('../../arrays/list').removeItems;
6
5
  const unboundObjects = require('./objects');
7
6
 
8
- // Adds a couple magic methods to the `unbound` function.
7
+ // Adds a couple proxy methods to the `unbound` function.
9
8
  module.exports = function(unbound)
10
9
  {
11
10
  /**
12
11
  * Add an item to the unbound global objects list.
13
12
  *
14
- * @function
15
- * @param {(object|function)} obj - The object to be considered unbound.
16
- * @returns {boolean} Will be `false` if `obj` is already unbound.
17
- * @throws {TypeError} If `obj` was neither an `object` nor a `function`.
18
- * @name module:@lumjs/core/types.unbound.add
13
+ * @deprecated the global list is going away in 2.0
14
+ * @function module:@lumjs/core/types.unbound.add
15
+ * @param {(object|function)} obj - Value to be added
16
+ * @returns {boolean} always true as of v1.37.2
17
+ * @throws {TypeError} If `obj` was not a valid value
19
18
  */
20
19
  def(unbound, 'add', function (obj)
21
20
  {
22
21
  needObj(obj, true);
23
- if (unbound(obj, true, true))
24
- { // Item is already unbound.
25
- return false;
26
- }
27
- // Add to list and we're done.
28
- unboundObjects.push(obj);
22
+ if (unboundObjects.has(obj)) return false;
23
+ unboundObjects.add(obj);
29
24
  return true;
30
25
  });
31
26
 
32
27
  /**
33
28
  * Remove an item from the unbound global objects list.
34
29
  *
35
- * @function
36
- * @param {(object|function)} obj - The object to be removed.
37
- * @returns {boolean} Will be `false` if the item was not in the list.
38
- * @throws {TypeError} If `obj` was neither an `object` nor a `function`.
39
- * @name module:@lumjs/core/types.unbound.remove
30
+ * @deprecated the global list is going away in 2.0
31
+ * @function module:@lumjs/core/types.unbound.remove
32
+ * @param {(object|function)} obj - value to be removed
33
+ * @returns {boolean} always true as of v1.37.2
34
+ * @throws {TypeError} If `obj` was not a valid value
40
35
  */
41
36
  def(unbound, 'remove', function(obj)
42
37
  {
43
38
  needObj(obj, true);
44
- return (removeFromArray(unboundObjects, obj) > 0);
39
+ unboundObjects.delete(obj);
40
+ return true;
45
41
  });
46
42
  }
@@ -1,2 +1,3 @@
1
1
  // Private storage, not exported outside the package.
2
- module.exports = [];
2
+ // TODO: remove this in 2.0
3
+ module.exports = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumjs/core",
3
- "version": "1.37.1",
3
+ "version": "1.37.2",
4
4
  "main": "lib/index.js",
5
5
  "exports":
6
6
  {