@lumjs/core 1.38.7 → 1.39.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.
- package/lib/arrays/index.js +23 -11
- package/lib/arrays/util.js +83 -1
- package/lib/context.js +3 -3
- package/lib/enum.js +9 -5
- package/lib/env.js +28 -12
- package/lib/index.js +7 -2
- package/lib/meta.js +259 -57
- package/lib/obj/apply.js +1 -3
- package/lib/obj/basics.js +12 -0
- package/lib/obj/cp.js +1 -1
- package/lib/obj/df.js +9 -9
- package/lib/obj/getproperty.js +1 -1
- package/lib/obj/index.js +18 -14
- package/lib/obj/keys.js +55 -0
- package/lib/obj/lock.js +2 -68
- package/lib/obj/unlocked.js +8 -10
- package/lib/proxy.js +417 -0
- package/lib/state.js +35 -4
- package/lib/types/js.js +3 -0
- package/lib/types/root.js +1 -0
- package/package.json +5 -2
- package/lib/arrays/add.js +0 -233
- package/lib/arrays/list.js +0 -314
- package/lib/arrays/typed.js +0 -139
- package/lib/obj/clone.js +0 -378
- package/lib/obj/copyall.js +0 -45
- package/lib/obj/copyprops.js +0 -73
- package/lib/obj/merge.js +0 -84
package/lib/arrays/index.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Array helper libraries
|
|
3
3
|
*
|
|
4
|
+
* A lot of this sub-module has been moved into the @lumjs/lists package now.
|
|
5
|
+
* Aliases will continue to exist here until v2.x is released.
|
|
6
|
+
*
|
|
4
7
|
* @module @lumjs/core/arrays
|
|
5
8
|
*/
|
|
6
9
|
|
|
7
10
|
const {lazy} = require('../obj/df');
|
|
8
|
-
const {powerset, random} = require('./util');
|
|
11
|
+
const {move, powerset, random, swap} = require('./util');
|
|
12
|
+
|
|
13
|
+
// Utils; the only bits that will remain here in v2.
|
|
14
|
+
module.exports = exports = {move, powerset, random, swap};
|
|
15
|
+
|
|
16
|
+
// TODO: wrap the following via wrapDepr for the v1.39.x; remove in v2.0.
|
|
9
17
|
|
|
10
|
-
|
|
11
|
-
exports.powerset = powerset;
|
|
12
|
-
exports.random = random;
|
|
18
|
+
const loadLists = () => require('@lumjs/lists');
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
const listsExports = [
|
|
21
|
+
'add',
|
|
22
|
+
'containsAll',
|
|
23
|
+
'containsAny',
|
|
24
|
+
'ConvertType',
|
|
25
|
+
'List',
|
|
26
|
+
'makeTyped',
|
|
27
|
+
'removeItems',
|
|
28
|
+
'TypedArray',
|
|
29
|
+
];
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
lazy(exports,
|
|
31
|
+
for (let le of listsExports) {
|
|
32
|
+
lazy(exports, le, () => loadLists()[le]);
|
|
33
|
+
}
|
package/lib/arrays/util.js
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const indOf = (arr, ind) => (ind < 0) ? (arr.length + ind) : ind;
|
|
4
|
+
const indexes = (arr, inds) => {
|
|
5
|
+
for (let ind in inds) {
|
|
6
|
+
inds[ind] = indOf(arr, inds[ind]);
|
|
7
|
+
}
|
|
8
|
+
return inds;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Move an array item to a new position.
|
|
13
|
+
*
|
|
14
|
+
* Negative position values will be from the end of the Array.
|
|
15
|
+
*
|
|
16
|
+
* This will directly MODIFY the array!
|
|
17
|
+
*
|
|
18
|
+
* @param {Array} array - Array we are moving the item in.
|
|
19
|
+
* @param {number} a - Current position of item to move.
|
|
20
|
+
* @param {number} b - Position to move the item to.
|
|
21
|
+
* @param {boolean} [rp=false] Return the calculated positions?
|
|
22
|
+
* @returns {(Array|module:@lumjs/core/arrays~Position)}
|
|
23
|
+
* If `rp` is false this will return the original array.
|
|
24
|
+
*/
|
|
25
|
+
function move(array, a, b, rp=false) {
|
|
26
|
+
let pos = indexes(array, {a, b});
|
|
27
|
+
if (pos.a !== pos.b) {
|
|
28
|
+
array.splice(pos.b, 0, ...array.splice(pos.a, 1));
|
|
29
|
+
}
|
|
30
|
+
return rp ? pos : array;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Swap the positions of two items in an array.
|
|
35
|
+
*
|
|
36
|
+
* Negative position values will be from the end of the Array.
|
|
37
|
+
*
|
|
38
|
+
* This will directly MODIFY the array!
|
|
39
|
+
*
|
|
40
|
+
* @param {Array} array - Array we are swapping items in.
|
|
41
|
+
* @param {number} a - Current position of item to move.
|
|
42
|
+
* @param {number} b - Position to move the item to.
|
|
43
|
+
* @param {?Array} [moves=null] Return calculated positions?
|
|
44
|
+
*
|
|
45
|
+
* If this argument is supplied, the array will be populated with
|
|
46
|
+
* either one or two Position objects (from the move() function).
|
|
47
|
+
*
|
|
48
|
+
* If `a` and `b` are directly next to each other there will be
|
|
49
|
+
* only one Position object as only one call to move() is required.
|
|
50
|
+
*
|
|
51
|
+
* If they are more than 1 position away from each other there
|
|
52
|
+
* will be two Position objects, the first being from moving `a`
|
|
53
|
+
* to `b` and the second moving `b` to `a`.
|
|
54
|
+
*
|
|
55
|
+
* @returns {(Array|module:@lumjs/core/arrays~Position[])}
|
|
56
|
+
* The return value will be `moves` if it was set, or `array` otherwise.
|
|
57
|
+
*/
|
|
58
|
+
function swap(array, a, b, moves=null) {
|
|
59
|
+
let rp = Array.isArray(moves);
|
|
60
|
+
let pos = move(array, a, b, true);
|
|
61
|
+
if (rp) moves.push(pos);
|
|
62
|
+
if (pos.a !== pos.b) {
|
|
63
|
+
let n2 = (pos.a < pos.b) ? pos.b -1 : pos.b + 1;
|
|
64
|
+
if (n2 !== pos.a) {
|
|
65
|
+
pos = move(array, n2, pos.a, true);
|
|
66
|
+
if (rp) moves.push(pos);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return rp ? moves : array;
|
|
71
|
+
}
|
|
1
72
|
|
|
2
73
|
/**
|
|
3
74
|
* Return a Powerset of values in the array.
|
|
@@ -34,5 +105,16 @@ function random(array)
|
|
|
34
105
|
|
|
35
106
|
module.exports = exports =
|
|
36
107
|
{
|
|
37
|
-
powerset, random,
|
|
108
|
+
move, powerset, random, swap,
|
|
38
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Position movement info.
|
|
113
|
+
*
|
|
114
|
+
* All positions in this will be the final calculated positions
|
|
115
|
+
* after conversion of negative arguments and offsets in two-stage swaps.
|
|
116
|
+
*
|
|
117
|
+
* @typedef {object} module:@lumjs/core/arrays~Position
|
|
118
|
+
* @prop {number} a - Position item was moved from.
|
|
119
|
+
* @prop {number} b - Position item was moved to.
|
|
120
|
+
*/
|
package/lib/context.js
CHANGED
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
* @property {boolean} isBundled - Is this a bundled app?
|
|
43
43
|
* @property {boolean} isMain - Is this the main renderer frame?
|
|
44
44
|
* @property {?string} type - `process.type`
|
|
45
|
-
* @property {object} root - See {@link module:@lumjs/core/types.root}
|
|
46
45
|
*/
|
|
47
46
|
|
|
48
|
-
const {
|
|
49
|
-
const { df, dfor } = require('./obj');
|
|
47
|
+
const {B,F,U,O,isComplex,isObj} = require('./types/basics');
|
|
48
|
+
const { df, dfor } = require('./obj/df');
|
|
50
49
|
|
|
50
|
+
const root = globalThis;
|
|
51
51
|
const fo = {enumerable: true}
|
|
52
52
|
const ctx = {root};
|
|
53
53
|
const rootHas = what => typeof root[what] !== U;
|
package/lib/enum.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { deprecated } = require('./meta');
|
|
1
2
|
const {S,F,def,notNil,isObj,needObj,TYPES} = require('./types');
|
|
2
3
|
const {InternalObjectId} = require('./objectid');
|
|
3
4
|
|
|
@@ -79,6 +80,8 @@ const EOPT = Symbol(EID+':opts');
|
|
|
79
80
|
* used as the `opts` for {@see module:@lumjs/core/obj.addLock addLock()},
|
|
80
81
|
* which will be called on the open Enum object.
|
|
81
82
|
*
|
|
83
|
+
* This option is **deprecated** and will be removed in v2.0.
|
|
84
|
+
*
|
|
82
85
|
* @param {bool} [opts.configurable=false] Enum properties are configurable?
|
|
83
86
|
*
|
|
84
87
|
* This option is ignored if `opts.open` is `false`.
|
|
@@ -188,7 +191,9 @@ function Enum (spec, opts={})
|
|
|
188
191
|
{ // Save the options into a special Symbol property.
|
|
189
192
|
def(anEnum, EOPT, {value: opts});
|
|
190
193
|
if (isObj(opts.lock))
|
|
191
|
-
{ // Add lock() method.
|
|
194
|
+
{ // Add lock() method; TODO: remove this in 2.0!
|
|
195
|
+
deprecated("Enum(opts.lock)");
|
|
196
|
+
let { addLock } = require('./obj/lock');
|
|
192
197
|
addLock(anEnum, opts.lock);
|
|
193
198
|
}
|
|
194
199
|
}
|
|
@@ -196,7 +201,9 @@ function Enum (spec, opts={})
|
|
|
196
201
|
else
|
|
197
202
|
{
|
|
198
203
|
if (notNil(opts.lock))
|
|
199
|
-
{ // Use lock() function.
|
|
204
|
+
{ // Use lock() function; TODO: remove this in 2.0!
|
|
205
|
+
deprecated("Enum(opts.lock)");
|
|
206
|
+
let { lock } = require('./obj/lock');
|
|
200
207
|
let lockOpts;
|
|
201
208
|
if (Array.isArray(opts.lock))
|
|
202
209
|
{ // Specified the lock parameters as an array.
|
|
@@ -250,6 +257,3 @@ def(Enum, 'is', isEnum);
|
|
|
250
257
|
TYPES.add('ENUM', 'enum', isEnum, 'isEnum');
|
|
251
258
|
|
|
252
259
|
module.exports = Enum;
|
|
253
|
-
|
|
254
|
-
// Loading this at the end.
|
|
255
|
-
const {lock,addLock} = require('./obj/lock');
|
package/lib/env.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const cp = Object.assign;
|
|
4
4
|
const ctx = require('./context');
|
|
5
|
-
const { df, lazy } = require('./obj');
|
|
6
|
-
const { isObj } = require('./types');
|
|
5
|
+
const { df, lazy } = require('./obj/df');
|
|
6
|
+
const { isObj } = require('./types/basics');
|
|
7
7
|
const NS = '@lumjs/core/env';
|
|
8
8
|
const DataCache = Symbol(NS+'~DataCache');
|
|
9
9
|
const Metadata = Symbol(NS+'~Metadata');
|
|
@@ -316,7 +316,8 @@ exports = module.exports =
|
|
|
316
316
|
let info = {key, opts, env: this};
|
|
317
317
|
|
|
318
318
|
let value = this.getStr(key),
|
|
319
|
-
cache = false
|
|
319
|
+
cache = false,
|
|
320
|
+
isdef = false;
|
|
320
321
|
|
|
321
322
|
if (typeof value === 'string')
|
|
322
323
|
{
|
|
@@ -326,18 +327,22 @@ exports = module.exports =
|
|
|
326
327
|
if (value === undefined)
|
|
327
328
|
{
|
|
328
329
|
value = (typeof opts.default === 'function')
|
|
329
|
-
? opts.default.call(this, key, opts)
|
|
330
|
+
? opts.default.call(this, key, opts, this)
|
|
330
331
|
: opts.default;
|
|
332
|
+
isdef = true;
|
|
331
333
|
}
|
|
332
334
|
|
|
333
|
-
if (
|
|
334
|
-
{
|
|
335
|
-
cache = (opts.cache > 0);
|
|
336
|
-
this.extendObject(value, info);
|
|
337
|
-
}
|
|
338
|
-
else if (value !== undefined)
|
|
335
|
+
if (!isdef || opts.cache > 2)
|
|
339
336
|
{
|
|
340
|
-
|
|
337
|
+
if (isObj(value))
|
|
338
|
+
{
|
|
339
|
+
cache = (opts.cache > 0);
|
|
340
|
+
this.extendObject(value, info);
|
|
341
|
+
}
|
|
342
|
+
else if (value !== undefined)
|
|
343
|
+
{
|
|
344
|
+
cache = (opts.cache > 1);
|
|
345
|
+
}
|
|
341
346
|
}
|
|
342
347
|
|
|
343
348
|
if (cache)
|
|
@@ -453,7 +458,7 @@ exports = module.exports =
|
|
|
453
458
|
let meth = opts.dataSave;
|
|
454
459
|
if (value[meth] !== undefined)
|
|
455
460
|
{
|
|
456
|
-
console.error({
|
|
461
|
+
console.error({meth, value, opts, info});
|
|
457
462
|
throw new RangeError(meth+' property already exists');
|
|
458
463
|
}
|
|
459
464
|
|
|
@@ -874,10 +879,14 @@ exports = module.exports =
|
|
|
874
879
|
*/
|
|
875
880
|
exports.delete = exports.remove;
|
|
876
881
|
|
|
882
|
+
//console.debug('Main env exports setup', exports);
|
|
883
|
+
|
|
877
884
|
// Now the platform-specific methods are added!
|
|
878
885
|
|
|
879
886
|
if (ctx.isNode)
|
|
880
887
|
{
|
|
888
|
+
//console.debug('Adding node env helpers');
|
|
889
|
+
|
|
881
890
|
exports.getStr = function(key)
|
|
882
891
|
{
|
|
883
892
|
return process.env[key];
|
|
@@ -893,6 +902,7 @@ if (ctx.isNode)
|
|
|
893
902
|
exports.unset = function(key)
|
|
894
903
|
{
|
|
895
904
|
delete process.env[key];
|
|
905
|
+
return this;
|
|
896
906
|
}
|
|
897
907
|
|
|
898
908
|
exports.forEach = function(cb, opts)
|
|
@@ -907,6 +917,8 @@ if (ctx.isNode)
|
|
|
907
917
|
}
|
|
908
918
|
else if (ctx.isBrowser)
|
|
909
919
|
{
|
|
920
|
+
console.debug('Adding browser env helpers');
|
|
921
|
+
|
|
910
922
|
exports.getStr = function(key)
|
|
911
923
|
{ // getItem returns null for no value, but we want undefined.
|
|
912
924
|
return localStorage.getItem(key) ?? undefined;
|
|
@@ -935,3 +947,7 @@ else if (ctx.isBrowser)
|
|
|
935
947
|
return cb.done();
|
|
936
948
|
}
|
|
937
949
|
}
|
|
950
|
+
else
|
|
951
|
+
{
|
|
952
|
+
throw new RangeError('Invalid environment');
|
|
953
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -24,18 +24,23 @@ exports = module.exports =
|
|
|
24
24
|
Enum: require('./enum'),
|
|
25
25
|
env: require('./env'),
|
|
26
26
|
flags: require('./flags'),
|
|
27
|
-
lazy,
|
|
27
|
+
lazy, // ← TODO: nix in 2.x
|
|
28
28
|
maps: require('./maps'),
|
|
29
29
|
meta,
|
|
30
|
-
...(meta), // ← TODO: nix in 2.x
|
|
31
30
|
...(require('./objectid')),
|
|
32
31
|
// obj: require('./obj'), // ← TODO: uncomment in 2.x
|
|
33
32
|
opt: require('./opt'),
|
|
33
|
+
proxy: require('./proxy'),
|
|
34
34
|
state: require('./state'),
|
|
35
35
|
strings: require('./strings'),
|
|
36
36
|
types,
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
meta.deprecateAll(meta, {
|
|
40
|
+
dep: '@lumjs/core',
|
|
41
|
+
rep: '@lumjs/core.meta.{DEP}',
|
|
42
|
+
}, exports);
|
|
43
|
+
|
|
39
44
|
// ↓ TODO: nix everything below here in 2.x
|
|
40
45
|
|
|
41
46
|
df(exports, 'AbstractClass',
|