@lumjs/core 1.3.0 → 1.3.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.0-beta.md +3 -9
- package/docs/changelogs/1.x.md +17 -7
- package/docs/changelogs/index.md +19 -0
- package/lib/arrays.js +4 -0
- package/lib/enum.js +14 -8
- package/lib/index.js +2 -2
- package/lib/obj/clone.js +48 -46
- package/lib/strings.js +1 -2
- package/package.json +1 -1
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
All notable changes to this project will be documented in this file.
|
|
1
|
+
# Changelog → 1.0-beta.x
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
3
|
+
This is the changelog for the `1.0-beta.x` versions.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
This is the *Changelog* for the `1.0.0-beta.x` releases.
|
|
10
|
-
See [1.x.md](1.x.md) for the stable `1.x` *Changelog*.
|
|
5
|
+
See [Changelogs](index.md) for more information on the changelogs.
|
|
11
6
|
|
|
12
7
|
## [1.0.0-beta.6]
|
|
13
8
|
- This is the **final** beta version.
|
|
@@ -96,4 +91,3 @@ See [1.x.md](1.x.md) for the stable `1.x` *Changelog*.
|
|
|
96
91
|
[1.0.0-beta.3]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.2...v1.0.0-beta.3
|
|
97
92
|
[1.0.0-beta.2]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.1...v1.0.0-beta.2
|
|
98
93
|
[1.0.0-beta.1]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0-beta.1
|
|
99
|
-
|
package/docs/changelogs/1.x.md
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
All notable changes to this project will be documented in this file.
|
|
1
|
+
# Changelog → 1.x
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
This is the changelog for the `1.x` versions.
|
|
4
|
+
|
|
5
|
+
See [Changelogs](index.md) for more information on the changelogs.
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.3.1] - 2022-09-23
|
|
10
|
+
### Fixed
|
|
11
|
+
- The `arrays` module exports `powerset` and `random` as it should.
|
|
12
|
+
- Recursive dependency order issues with `clone`, `lock`, and `enum` resolved.
|
|
13
|
+
- Custom `lock` options in `enum` module actually work now.
|
|
14
|
+
### Changed
|
|
15
|
+
- The `Enum()` function now has `configurable` and `enumerable` options.
|
|
16
|
+
- The `configurable` property in `enums` defaults to `false` now.
|
|
17
|
+
- Tweaked the *changelogs* a bit and added a new [changelog listing](index.md).
|
|
18
|
+
|
|
9
19
|
## [1.3.0] - 2022-09-11
|
|
10
20
|
### Changed
|
|
11
21
|
- Overhauled the `obj.clone()` method.
|
|
@@ -62,13 +72,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
62
72
|
### Changed
|
|
63
73
|
- Initial *stable* release.
|
|
64
74
|
- See [1.0-beta.md](1.0-beta.md) for the beta versions of `1.0`
|
|
65
|
-
- See [lum.js](https://github.com/supernovus/lum.js) for the original library this is replacing.
|
|
75
|
+
- See [lum.js](https://github.com/supernovus/lum.js) for the original library set this is replacing.
|
|
66
76
|
|
|
67
|
-
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.3.
|
|
77
|
+
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.3.1...HEAD
|
|
78
|
+
[1.3.1]: https://github.com/supernovus/lum.core.js/compare/v1.3.0...v1.3.1
|
|
68
79
|
[1.3.0]: https://github.com/supernovus/lum.core.js/compare/v1.2.1...v1.3.0
|
|
69
80
|
[1.2.1]: https://github.com/supernovus/lum.core.js/compare/v1.2.0...v1.2.1
|
|
70
81
|
[1.2.0]: https://github.com/supernovus/lum.core.js/compare/v1.1.1...v1.2.0
|
|
71
82
|
[1.1.1]: https://github.com/supernovus/lum.core.js/compare/v1.1.0...v1.1.1
|
|
72
83
|
[1.1.0]: https://github.com/supernovus/lum.core.js/compare/v1.0.0...v1.1.0
|
|
73
84
|
[1.0.0]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0
|
|
74
|
-
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelogs
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in these files.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## Versions
|
|
9
|
+
|
|
10
|
+
To avoid the changelogs getting too big, I'm planning on splitting them up based
|
|
11
|
+
on the major version changes.
|
|
12
|
+
|
|
13
|
+
Each major version will be listed here in reverse chronological order (newest first.)
|
|
14
|
+
|
|
15
|
+
- [1.x](1.x.md) → The first standalone core library.
|
|
16
|
+
- [1.0-beta.x](1.0-beta.md)
|
|
17
|
+
→ The *pre-releases* from when this split off of the older
|
|
18
|
+
[Lum.js](https://github.com/supernovus/lum.js) library collection.
|
|
19
|
+
|
package/lib/arrays.js
CHANGED
|
@@ -99,6 +99,8 @@ function powerset(array)
|
|
|
99
99
|
return ps;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
exports.powerset = powerset;
|
|
103
|
+
|
|
102
104
|
/**
|
|
103
105
|
* Get a random element from an array.
|
|
104
106
|
* @param {Array} array The array to get an item from.
|
|
@@ -109,3 +111,5 @@ function random(array)
|
|
|
109
111
|
{
|
|
110
112
|
return array[Math.floor(Math.random()*array.length)];
|
|
111
113
|
}
|
|
114
|
+
|
|
115
|
+
exports.random = random;
|
package/lib/enum.js
CHANGED
|
@@ -21,6 +21,9 @@ function Enum (spec, opts={})
|
|
|
21
21
|
|
|
22
22
|
const anEnum = ENUM_ID.tag({});
|
|
23
23
|
|
|
24
|
+
const configurable = opts.configurable ?? false;
|
|
25
|
+
const enumerable = opts.enumerable ?? true;
|
|
26
|
+
|
|
24
27
|
function getVal (name, def)
|
|
25
28
|
{
|
|
26
29
|
if (opts.symbols)
|
|
@@ -42,7 +45,7 @@ function Enum (spec, opts={})
|
|
|
42
45
|
|
|
43
46
|
function addVal(pName, sName, inVal)
|
|
44
47
|
{
|
|
45
|
-
const desc = {configurable
|
|
48
|
+
const desc = {configurable, enumerable};
|
|
46
49
|
desc.value = getVal(sName, inVal);
|
|
47
50
|
def(anEnum, pName, desc);
|
|
48
51
|
}
|
|
@@ -83,25 +86,25 @@ function Enum (spec, opts={})
|
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
if (notNil(opts.lock))
|
|
86
|
-
{ // Use lock.
|
|
89
|
+
{ // Use lock() function.
|
|
87
90
|
let lockOpts;
|
|
88
91
|
if (Array.isArray(opts.lock))
|
|
89
|
-
{
|
|
92
|
+
{ // Specified the lock parameters as an array.
|
|
90
93
|
lockOpts = opts.lock;
|
|
91
94
|
}
|
|
92
95
|
else if (isObj(opts.lock))
|
|
93
|
-
{
|
|
96
|
+
{ // An object is assumed to be the `cloneOpts` parameter.
|
|
94
97
|
lockOpts = [true, opts.lock, false];
|
|
95
98
|
}
|
|
96
99
|
else if (typeof opts.lock === B)
|
|
97
|
-
{
|
|
100
|
+
{ // Boolean is assumed to be the `cloneable` parameter.
|
|
98
101
|
lockOpts = [opts.lock, null, false];
|
|
99
102
|
}
|
|
100
103
|
else
|
|
101
|
-
{
|
|
102
|
-
lockOpts = [
|
|
104
|
+
{ // Anything else we use default values.
|
|
105
|
+
lockOpts = [];
|
|
103
106
|
}
|
|
104
|
-
return lock(anEnum);
|
|
107
|
+
return lock(anEnum, ...lockOpts);
|
|
105
108
|
}
|
|
106
109
|
else if (!opts.open)
|
|
107
110
|
{ // Use Object.freeze()
|
|
@@ -138,3 +141,6 @@ def(Enum, 'is', isEnum);
|
|
|
138
141
|
TYPES.add('ENUM', 'enum', isEnum, 'isEnum');
|
|
139
142
|
|
|
140
143
|
module.exports = Enum;
|
|
144
|
+
|
|
145
|
+
// Loading this at the end.
|
|
146
|
+
const {lock} = require('./obj/lock');
|
package/lib/index.js
CHANGED
|
@@ -125,7 +125,7 @@ const def = types.def;
|
|
|
125
125
|
|
|
126
126
|
module.exports =
|
|
127
127
|
{
|
|
128
|
-
types,
|
|
128
|
+
types, context, flags, obj, opt, modules, arrays, strings,
|
|
129
129
|
def, randomNumber, InternalObjectId, Enum, lazy, observable,
|
|
130
|
-
stacktrace, AbstractClass, Functions, NYI,
|
|
130
|
+
stacktrace, AbstractClass, Functions, NYI,
|
|
131
131
|
}
|
package/lib/obj/clone.js
CHANGED
|
@@ -1,49 +1,7 @@
|
|
|
1
1
|
// Import *most* required bits here.
|
|
2
|
-
const {
|
|
3
|
-
const Enum = require('../enum');
|
|
2
|
+
const {N,F, isObj, isComplex, def, isArray} = require('../types');
|
|
4
3
|
const copyProps = require('./copyprops');
|
|
5
4
|
const getProp = require('./getproperty');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* An `enum` of supported *modes* for the `clone()` method.
|
|
9
|
-
*
|
|
10
|
-
* - **P** → All properties. If unchecked, *enumerable* properties only.
|
|
11
|
-
* - **A** → Uses `Array.slice()` shortcut for shallow `Array` cloning.
|
|
12
|
-
* - **R** → Recursive (deep) cloning of nested objects.
|
|
13
|
-
* - **D** → Uses *descriptor* cloning instead of direct assignment.
|
|
14
|
-
* - **T** → Sets the `prototype` of the clone as well.
|
|
15
|
-
*
|
|
16
|
-
* | Mode | P | A | R | D | T | Notes |
|
|
17
|
-
* | ---- | - | - | - | - | - | ----- |
|
|
18
|
-
* | `CLONE.N` | × | × | × | × | × | Can be used to manually specify options. |
|
|
19
|
-
* | `CLONE.DEF` | × | ✓ | × | × | × | Default mode for cloning functions. |
|
|
20
|
-
* | `CLONE.DEEP` | × | × | ✓ | ✓ | × | |
|
|
21
|
-
* | `CLONE.FULL` | ✓ | ✓ | × | ✓ | × | |
|
|
22
|
-
* | `CLONE.ALL` | ✓ | × | × | ✓ | × | |
|
|
23
|
-
* | `CLONE.ENTIRE` | ✓ | × | ✓ | ✓ | ✓ | |
|
|
24
|
-
* | `CLONE.JSON` | - | - | ✓ | - | × | Uses JSON, so no `function` or `symbol` support. |
|
|
25
|
-
*
|
|
26
|
-
* The `✓` and `×` marks signify the *default settings* in the mode.
|
|
27
|
-
* In *most* cases there are options that can override the
|
|
28
|
-
* defaults.
|
|
29
|
-
*
|
|
30
|
-
* Any feature in the `CLONE.JSON` row marked with `-` are
|
|
31
|
-
* incompatible with that mode and cannot be enabled at all.
|
|
32
|
-
*
|
|
33
|
-
* @alias module:@lumjs/core/obj.CLONE
|
|
34
|
-
*/
|
|
35
|
-
const CLONE = Enum(['N','DEF','FULL','ALL','DEEP','ENTIRE','JSON']);
|
|
36
|
-
|
|
37
|
-
exports.CLONE = CLONE;
|
|
38
|
-
|
|
39
|
-
// A list of modes that should use the array.slice shallow shortcut.
|
|
40
|
-
const SLICE_ARRAYS = [CLONE.DEF, CLONE.FULL];
|
|
41
|
-
|
|
42
|
-
// A list of modes that should get *all* properties.
|
|
43
|
-
const ALL_PROPS = [CLONE.FULL, CLONE.ALL, CLONE.ENTIRE];
|
|
44
|
-
|
|
45
|
-
// A list of modes that should do recursive cloning of objects.
|
|
46
|
-
const RECURSIVE = [CLONE.DEEP, CLONE.ENTIRE];
|
|
47
5
|
|
|
48
6
|
/**
|
|
49
7
|
* Clone an object or function.
|
|
@@ -295,9 +253,6 @@ function clone(obj, opts={})
|
|
|
295
253
|
return copy;
|
|
296
254
|
}
|
|
297
255
|
|
|
298
|
-
// Alias the CLONE enum as clone.MODE
|
|
299
|
-
def(clone, 'MODE', CLONE);
|
|
300
|
-
|
|
301
256
|
// Export the clone here.
|
|
302
257
|
exports.clone = clone;
|
|
303
258
|
|
|
@@ -371,3 +326,50 @@ exports.cloneIfLocked = cloneIfLocked;
|
|
|
371
326
|
|
|
372
327
|
// Import `addLock()` here *after* assigning the clone methods.
|
|
373
328
|
const {addLock} = require('./lock');
|
|
329
|
+
|
|
330
|
+
// And setting all the Enum definitions at the very end.
|
|
331
|
+
const Enum = require('../enum');
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* An `enum` of supported *modes* for the `clone()` method.
|
|
335
|
+
*
|
|
336
|
+
* - **P** → All properties. If unchecked, *enumerable* properties only.
|
|
337
|
+
* - **A** → Uses `Array.slice()` shortcut for shallow `Array` cloning.
|
|
338
|
+
* - **R** → Recursive (deep) cloning of nested objects.
|
|
339
|
+
* - **D** → Uses *descriptor* cloning instead of direct assignment.
|
|
340
|
+
* - **T** → Sets the `prototype` of the clone as well.
|
|
341
|
+
*
|
|
342
|
+
* | Mode | P | A | R | D | T | Notes |
|
|
343
|
+
* | ---- | - | - | - | - | - | ----- |
|
|
344
|
+
* | `CLONE.N` | × | × | × | × | × | Can be used to manually specify options. |
|
|
345
|
+
* | `CLONE.DEF` | × | ✓ | × | × | × | Default mode for cloning functions. |
|
|
346
|
+
* | `CLONE.DEEP` | × | × | ✓ | ✓ | × | |
|
|
347
|
+
* | `CLONE.FULL` | ✓ | ✓ | × | ✓ | × | |
|
|
348
|
+
* | `CLONE.ALL` | ✓ | × | × | ✓ | × | |
|
|
349
|
+
* | `CLONE.ENTIRE` | ✓ | × | ✓ | ✓ | ✓ | |
|
|
350
|
+
* | `CLONE.JSON` | - | - | ✓ | - | × | Uses JSON, so no `function` or `symbol` support. |
|
|
351
|
+
*
|
|
352
|
+
* The `✓` and `×` marks signify the *default settings* in the mode.
|
|
353
|
+
* In *most* cases there are options that can override the
|
|
354
|
+
* defaults.
|
|
355
|
+
*
|
|
356
|
+
* Any feature in the `CLONE.JSON` row marked with `-` are
|
|
357
|
+
* incompatible with that mode and cannot be enabled at all.
|
|
358
|
+
*
|
|
359
|
+
* @alias module:@lumjs/core/obj.CLONE
|
|
360
|
+
*/
|
|
361
|
+
const CLONE = Enum(['N','DEF','FULL','ALL','DEEP','ENTIRE','JSON']);
|
|
362
|
+
|
|
363
|
+
exports.CLONE = CLONE;
|
|
364
|
+
|
|
365
|
+
// A list of modes that should use the array.slice shallow shortcut.
|
|
366
|
+
const SLICE_ARRAYS = [CLONE.DEF, CLONE.FULL];
|
|
367
|
+
|
|
368
|
+
// A list of modes that should get *all* properties.
|
|
369
|
+
const ALL_PROPS = [CLONE.FULL, CLONE.ALL, CLONE.ENTIRE];
|
|
370
|
+
|
|
371
|
+
// A list of modes that should do recursive cloning of objects.
|
|
372
|
+
const RECURSIVE = [CLONE.DEEP, CLONE.ENTIRE];
|
|
373
|
+
|
|
374
|
+
// Alias the CLONE enum as clone.MODE
|
|
375
|
+
def(clone, 'MODE', CLONE);
|
package/lib/strings.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* String and locale related functions.
|
|
3
3
|
* @module @lumjs/core/strings
|
|
4
4
|
*/
|
|
5
|
-
const {S,B,F,isObj,root,isArray,needType,needObj} = require('./types')
|
|
5
|
+
const {S,B,F,isObj,root,isArray,needType,needObj} = require('./types');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get the locale/language string.
|
|
@@ -189,4 +189,3 @@ function replaceItems(string, replacements, useAll)
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
exports.replaceItems = replaceItems;
|
|
192
|
-
|