@lumjs/core 1.1.0 → 1.2.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/docs/changelogs/1.x.md +24 -1
- package/lib/arrays.js +33 -0
- package/lib/context.js +15 -2
- package/lib/obj/getproperty.js +3 -3
- package/lib/obj/ns.js +3 -2
- package/lib/objectid.js +14 -0
- package/lib/opt.js +1 -1
- package/package.json +2 -2
- package/test/types.js +1 -1
package/docs/changelogs/1.x.md
CHANGED
|
@@ -6,6 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.2.1] - 2022-09-05
|
|
10
|
+
### Added
|
|
11
|
+
- `core.InternalObjectId#untag()`
|
|
12
|
+
### Changed
|
|
13
|
+
- Cleaned up the wording in a docblock, and updated a test to use `done()`.
|
|
14
|
+
|
|
15
|
+
## [1.2.0] - 2022-08-10
|
|
16
|
+
### Added
|
|
17
|
+
- Moved the `array.powerset()` and `array.random()` methods from Lum.js v4 into `core.arrays`.
|
|
18
|
+
- Added a new `core.context.isCommonJS()` method which is only used in certain circumstances.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- A typo in one of the `package.json` exports.
|
|
22
|
+
- Commented out a debugging line.
|
|
23
|
+
|
|
24
|
+
## [1.1.1] - 2022-08-02
|
|
25
|
+
### Fixed
|
|
26
|
+
- A couple missing constants in some functions.
|
|
27
|
+
|
|
9
28
|
## [1.1.0] - 2022-07-29
|
|
10
29
|
### Added
|
|
11
30
|
- `types.doesDescriptorTemplate()` method.
|
|
@@ -27,6 +46,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
46
|
- See [1.0-beta.md](1.0-beta.md) for the beta versions of `1.0`
|
|
28
47
|
- See [lum.js](https://github.com/supernovus/lum.js) for the original library this is replacing.
|
|
29
48
|
|
|
30
|
-
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.
|
|
49
|
+
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.2.1...HEAD
|
|
50
|
+
[1.2.1]: https://github.com/supernovus/lum.core.js/compare/v1.2.0...v1.2.1
|
|
51
|
+
[1.2.0]: https://github.com/supernovus/lum.core.js/compare/v1.1.1...v1.2.0
|
|
52
|
+
[1.1.1]: https://github.com/supernovus/lum.core.js/compare/v1.1.0...v1.1.1
|
|
53
|
+
[1.1.0]: https://github.com/supernovus/lum.core.js/compare/v1.0.0...v1.1.0
|
|
31
54
|
[1.0.0]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0
|
|
32
55
|
|
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',
|
|
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/getproperty.js
CHANGED
|
@@ -4,9 +4,9 @@ const {isComplex,isObj} = types;
|
|
|
4
4
|
/**
|
|
5
5
|
* Get a property descriptor.
|
|
6
6
|
*
|
|
7
|
-
* This is like `Object.getOwnPropertyDescriptor`, except
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* This is like `Object.getOwnPropertyDescriptor`, except unlike
|
|
8
|
+
* that method, this will travel through the entire prototype chain
|
|
9
|
+
* until it finds the descriptor.
|
|
10
10
|
*
|
|
11
11
|
* @param {object|function} obj - Object to find a property in.
|
|
12
12
|
* @param {string} prop - Name of the property we want the descriptor of.
|
package/lib/obj/ns.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Import required bits here.
|
|
2
2
|
const
|
|
3
3
|
{
|
|
4
|
-
B,
|
|
4
|
+
B, S,
|
|
5
|
+
root, isObj, needObj, def, nonEmptyArray, notNil,
|
|
5
6
|
doesDescriptorTemplate,
|
|
6
7
|
} = require('../types');
|
|
7
8
|
|
|
@@ -168,7 +169,7 @@ function setObjectPath(obj, proppath, opts={})
|
|
|
168
169
|
const nsc = proppath.length;
|
|
169
170
|
const lastns = nsc - 1;
|
|
170
171
|
|
|
171
|
-
console.debug("setObjectPath", obj, proppath, opts, nsc, arguments);
|
|
172
|
+
//console.debug("setObjectPath", obj, proppath, opts, nsc, arguments);
|
|
172
173
|
|
|
173
174
|
for (let n = 0; n < nsc; n++)
|
|
174
175
|
{
|
package/lib/objectid.js
CHANGED
|
@@ -56,6 +56,20 @@ class InternalObjectId
|
|
|
56
56
|
return def(obj, this.property, val);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Remove the tag from a tagged object.
|
|
61
|
+
*
|
|
62
|
+
* @param {*} obj
|
|
63
|
+
*/
|
|
64
|
+
untag(obj)
|
|
65
|
+
{
|
|
66
|
+
if (notNil(obj))
|
|
67
|
+
{
|
|
68
|
+
delete(obj[this.property]);
|
|
69
|
+
}
|
|
70
|
+
return obj;
|
|
71
|
+
}
|
|
72
|
+
|
|
59
73
|
/**
|
|
60
74
|
* Is the specified object tagged with this object id?
|
|
61
75
|
*
|
package/lib/opt.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumjs/core",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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/
|
|
15
|
+
"./modules": "./lib/modules.js",
|
|
16
16
|
"./meta": "./lib/meta.js",
|
|
17
17
|
"./enum": "./lib/enum.js",
|
|
18
18
|
"./observable": "./lib/observable.js",
|
package/test/types.js
CHANGED