@lumjs/core 1.1.1 → 1.2.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.
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2022-08-10
10
+ ### Added
11
+ - Moved the `array.powerset()` and `array.random()` methods from Lum.js v4 into `core.arrays`.
12
+ - Added a new `core.context.isCommonJS()` method which is only used in certain circumstances.
13
+
14
+ ### Fixed
15
+ - A typo in one of the `package.json` exports.
16
+ - Commented out a debugging line.
17
+
9
18
  ## [1.1.1] - 2022-08-02
10
19
  ### Fixed
11
20
  - A couple missing constants in some functions.
@@ -31,7 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
31
40
  - See [1.0-beta.md](1.0-beta.md) for the beta versions of `1.0`
32
41
  - See [lum.js](https://github.com/supernovus/lum.js) for the original library this is replacing.
33
42
 
34
- [Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.1.1...HEAD
43
+ [Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.2.0...HEAD
44
+ [1.2.0]: https://github.com/supernovus/lum.core.js/compare/v1.1.1...v1.2.0
35
45
  [1.1.1]: https://github.com/supernovus/lum.core.js/compare/v1.1.0...v1.1.1
36
46
  [1.1.0]: https://github.com/supernovus/lum.core.js/compare/v1.0.0...v1.1.0
37
47
  [1.0.0]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0
package/lib/arrays.js CHANGED
@@ -76,3 +76,36 @@ function removeItems(array, ...items)
76
76
  }
77
77
 
78
78
  exports.removeItems = removeItems;
79
+
80
+ /**
81
+ * Return a Powerset of values in the array.
82
+ * @param {Array} array The array to make the powerset from.
83
+ * @returns {Array} The powerset.
84
+ * @alias module:@lumjs/core/arrays.powerset
85
+ */
86
+ function powerset(array)
87
+ {
88
+ var ps = [[]];
89
+ for (var i=0; i < array.length; i++)
90
+ {
91
+ // we modify the ps array in the next loop,
92
+ // so can't use the ps.length property directly in the loop condition.
93
+ var current_length = ps.length;
94
+ for (var j = 0; j < current_length; j++)
95
+ {
96
+ ps.push(ps[j].concat(array[i]));
97
+ }
98
+ }
99
+ return ps;
100
+ }
101
+
102
+ /**
103
+ * Get a random element from an array.
104
+ * @param {Array} array The array to get an item from.
105
+ * @returns {mixed} The randomly selected item.
106
+ * @alias module:@lumjs/core/arrays.random
107
+ */
108
+ function random(array)
109
+ {
110
+ return array[Math.floor(Math.random()*array.length)];
111
+ }
package/lib/context.js CHANGED
@@ -28,18 +28,31 @@ const ctx = {root};
28
28
  const rootHas = what => typeof root[what] !== U;
29
29
  const cd = def(ctx, true);
30
30
 
31
+ function isCommonJS(module)
32
+ {
33
+ if (typeof module !== O || module === null) return false;
34
+ if (!ctx.hasRequire) return false;
35
+ if (!isComplex(module.exports)) return false;
36
+ if (typeof module.$lib === O && typeof module.$lib.$cached === O)
37
+ return false; // It's our fake CommonJS emulation layer.
38
+ // Okay, all tests are okay.
39
+ return true;
40
+ }
41
+
31
42
  cd('AMD', typeof define === F && define.amd)
32
43
  ('hasRequire', typeof require === F)
33
44
  ('hasExports', typeof exports !== U)
34
45
  ('hasModule', typeof module === O && module !== null)
35
- ('CJS', ctx.hasRequire && ctx.hasModule && isComplex(module.exports))
46
+ ('CJS', isCommonJS(module)) // Detected value at load time in *this* module.
47
+ ('isCommonJS', isCommonJS) // Dynamically detect via a module *reference*.
36
48
  ('isNode', ctx.CJS && ctx.hasExports)
37
49
  ('isWindow', !ctx.CJS && rootHas('window'))
38
50
  ('isWorker', !ctx.CJS && rootHas('WorkerGlobalScope'))
39
51
  ('isServiceWorker', !ctx.CJS && rootHas('ServiceWorkerGlobalScope'))
40
52
  ('isDedicatedWorker', !ctx.CJS && rootHas('DedicatedWorkerGlobalScope'))
41
53
  ('isSharedWorker', !ctx.CJS && rootHas('SharedWorkerGlobalScope'))
42
- ('isBrowser', ctx.isWindow || ctx.isWorker);
54
+ ('isBrowser', ctx.isWindow || ctx.isWorker)
55
+ ;
43
56
 
44
57
  /**
45
58
  * See if a root-level name is defined.
package/lib/obj/ns.js CHANGED
@@ -169,7 +169,7 @@ function setObjectPath(obj, proppath, opts={})
169
169
  const nsc = proppath.length;
170
170
  const lastns = nsc - 1;
171
171
 
172
- console.debug("setObjectPath", obj, proppath, opts, nsc, arguments);
172
+ //console.debug("setObjectPath", obj, proppath, opts, nsc, arguments);
173
173
 
174
174
  for (let n = 0; n < nsc; n++)
175
175
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumjs/core",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "main": "lib/index.js",
5
5
  "exports":
6
6
  {
@@ -12,7 +12,7 @@
12
12
  "./flags": "./lib/flags.js",
13
13
  "./obj": "./lib/obj/index.js",
14
14
  "./opt": "./lib/opt.js",
15
- "./modules": "./lib/moduless.js",
15
+ "./modules": "./lib/modules.js",
16
16
  "./meta": "./lib/meta.js",
17
17
  "./enum": "./lib/enum.js",
18
18
  "./observable": "./lib/observable.js",