@lumjs/core 1.14.0 → 1.16.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/debug/2023-06-08T19_55_05_247Z-debug-0.log +107 -0
- package/lib/arrays.js +290 -55
- package/lib/index.js +12 -14
- package/lib/obj/apply.js +52 -0
- package/lib/obj/copyall.js +1 -1
- package/lib/obj/copyprops.js +89 -11
- package/lib/obj/index.js +2 -1
- package/lib/observable.js +2 -2
- package/lib/types/console.js +119 -20
- package/lib/types/typelist.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
0 verbose cli /usr/bin/node /usr/bin/npm
|
|
2
|
+
1 info using npm@9.7.1
|
|
3
|
+
2 info using node@v18.16.0
|
|
4
|
+
3 timing npm:load:whichnode Completed in 1ms
|
|
5
|
+
4 timing config:load:defaults Completed in 1ms
|
|
6
|
+
5 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 1ms
|
|
7
|
+
6 timing config:load:builtin Completed in 1ms
|
|
8
|
+
7 timing config:load:cli Completed in 1ms
|
|
9
|
+
8 timing config:load:env Completed in 0ms
|
|
10
|
+
9 timing config:load:file:/system/docs/dev/js/lumjs/core/.npmrc Completed in 0ms
|
|
11
|
+
10 timing config:load:project Completed in 1ms
|
|
12
|
+
11 timing config:load:file:/home/novus/.npmrc Completed in 1ms
|
|
13
|
+
12 timing config:load:user Completed in 1ms
|
|
14
|
+
13 timing config:load:file:/usr/etc/npmrc Completed in 0ms
|
|
15
|
+
14 timing config:load:global Completed in 0ms
|
|
16
|
+
15 timing config:load:setEnvs Completed in 1ms
|
|
17
|
+
16 timing config:load Completed in 6ms
|
|
18
|
+
17 timing npm:load:configload Completed in 6ms
|
|
19
|
+
18 timing config:load:flatten Completed in 1ms
|
|
20
|
+
19 timing npm:load:mkdirpcache Completed in 0ms
|
|
21
|
+
20 timing npm:load:mkdirplogs Completed in 0ms
|
|
22
|
+
21 verbose title npm publish
|
|
23
|
+
22 verbose argv "publish"
|
|
24
|
+
23 timing npm:load:setTitle Completed in 0ms
|
|
25
|
+
24 timing npm:load:display Completed in 1ms
|
|
26
|
+
25 verbose logfile logs-max:10 dir:/home/novus/.npm/_logs/2023-06-08T19_55_05_247Z-
|
|
27
|
+
26 verbose logfile /home/novus/.npm/_logs/2023-06-08T19_55_05_247Z-debug-0.log
|
|
28
|
+
27 timing npm:load:logFile Completed in 5ms
|
|
29
|
+
28 timing npm:load:timers Completed in 0ms
|
|
30
|
+
29 timing npm:load:configScope Completed in 0ms
|
|
31
|
+
30 timing npm:load Completed in 22ms
|
|
32
|
+
31 verbose publish [ '.' ]
|
|
33
|
+
32 silly logfile start cleaning logs, removing 1 files
|
|
34
|
+
33 silly logfile done cleaning log files
|
|
35
|
+
34 timing arborist:ctor Completed in 0ms
|
|
36
|
+
35 notice
|
|
37
|
+
36 notice 📦 @lumjs/core@1.16.0
|
|
38
|
+
37 notice === Tarball Contents ===
|
|
39
|
+
38 notice 928B README.md
|
|
40
|
+
38 notice 627B TODO.md
|
|
41
|
+
38 notice 501B jsdoc.json
|
|
42
|
+
38 notice 8.6kB lib/arrays.js
|
|
43
|
+
38 notice 6.4kB lib/context.js
|
|
44
|
+
38 notice 5.8kB lib/enum.js
|
|
45
|
+
38 notice 1.3kB lib/flags.js
|
|
46
|
+
38 notice 3.6kB lib/index.js
|
|
47
|
+
38 notice 3.8kB lib/meta.js
|
|
48
|
+
38 notice 3.6kB lib/modules.js
|
|
49
|
+
38 notice 1.2kB lib/obj/apply.js
|
|
50
|
+
38 notice 12.1kB lib/obj/clone.js
|
|
51
|
+
38 notice 1.2kB lib/obj/copyall.js
|
|
52
|
+
38 notice 12.5kB lib/obj/copyprops.js
|
|
53
|
+
38 notice 3.2kB lib/obj/getmethods.js
|
|
54
|
+
38 notice 1.2kB lib/obj/getproperty.js
|
|
55
|
+
38 notice 870B lib/obj/index.js
|
|
56
|
+
38 notice 2.2kB lib/obj/lock.js
|
|
57
|
+
38 notice 2.8kB lib/obj/merge.js
|
|
58
|
+
38 notice 6.8kB lib/obj/ns.js
|
|
59
|
+
38 notice 2.5kB lib/objectid.js
|
|
60
|
+
38 notice 8.7kB lib/observable.js
|
|
61
|
+
38 notice 2.2kB lib/opt.js
|
|
62
|
+
38 notice 5.3kB lib/strings.js
|
|
63
|
+
38 notice 6.0kB lib/types/basics.js
|
|
64
|
+
38 notice 4.7kB lib/types/console.js
|
|
65
|
+
38 notice 7.2kB lib/types/def.js
|
|
66
|
+
38 notice 1.1kB lib/types/dt.js
|
|
67
|
+
38 notice 1.8kB lib/types/index.js
|
|
68
|
+
38 notice 4.9kB lib/types/isa.js
|
|
69
|
+
38 notice 457B lib/types/js.js
|
|
70
|
+
38 notice 7.2kB lib/types/lazy.js
|
|
71
|
+
38 notice 3.4kB lib/types/needs.js
|
|
72
|
+
38 notice 2.7kB lib/types/root.js
|
|
73
|
+
38 notice 3.8kB lib/types/stringify.js
|
|
74
|
+
38 notice 5.5kB lib/types/typelist.js
|
|
75
|
+
38 notice 826B package.json
|
|
76
|
+
39 notice === Tarball Details ===
|
|
77
|
+
40 notice name: @lumjs/core
|
|
78
|
+
40 notice version: 1.16.0
|
|
79
|
+
40 notice filename: lumjs-core-1.16.0.tgz
|
|
80
|
+
40 notice package size: 42.7 kB
|
|
81
|
+
40 notice unpacked size: 147.6 kB
|
|
82
|
+
40 notice shasum: 424727206c94f94fbf8e18c5f62eab4aa64e52af
|
|
83
|
+
40 notice integrity: sha512-iPLVQTAe/Bf8P[...]TV8PNxn6/ji5A==
|
|
84
|
+
40 notice total files: 37
|
|
85
|
+
41 notice
|
|
86
|
+
42 notice Publishing to https://registry.npmjs.org/ with tag latest and default access
|
|
87
|
+
43 http fetch PUT 401 https://registry.npmjs.org/@lumjs%2fcore 277ms
|
|
88
|
+
44 timing command:publish Completed in 367ms
|
|
89
|
+
45 verbose stack HttpErrorGeneral: 401 Unauthorized - PUT https://registry.npmjs.org/@lumjs%2fcore - unexpected status code from "get-packument" = 401
|
|
90
|
+
45 verbose stack at /usr/lib/node_modules/npm/node_modules/npm-registry-fetch/lib/check-response.js:95:15
|
|
91
|
+
45 verbose stack at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
|
92
|
+
45 verbose stack at async publish (/usr/lib/node_modules/npm/node_modules/libnpmpublish/lib/publish.js:54:17)
|
|
93
|
+
45 verbose stack at async otplease (/usr/lib/node_modules/npm/lib/utils/otplease.js:4:12)
|
|
94
|
+
45 verbose stack at async Publish.exec (/usr/lib/node_modules/npm/lib/commands/publish.js:123:7)
|
|
95
|
+
45 verbose stack at async module.exports (/usr/lib/node_modules/npm/lib/cli-entry.js:61:5)
|
|
96
|
+
46 verbose statusCode 401
|
|
97
|
+
47 verbose pkgid @lumjs/core@1.16.0
|
|
98
|
+
48 verbose cwd /system/docs/dev/js/lumjs/core
|
|
99
|
+
49 verbose Linux 5.10.0-22-amd64
|
|
100
|
+
50 verbose node v18.16.0
|
|
101
|
+
51 verbose npm v9.7.1
|
|
102
|
+
52 error code E401
|
|
103
|
+
53 error 401 Unauthorized - PUT https://registry.npmjs.org/@lumjs%2fcore - unexpected status code from "get-packument" = 401
|
|
104
|
+
54 verbose exit 1
|
|
105
|
+
55 timing npm Completed in 495ms
|
|
106
|
+
56 verbose code 1
|
|
107
|
+
57 error A complete log of this run can be found in: /home/novus/.npm/_logs/2023-06-08T19_55_05_247Z-debug-0.log
|
package/lib/arrays.js
CHANGED
|
@@ -1,82 +1,314 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Array helper functions.
|
|
2
|
+
* Array (and other list objects) helper functions.
|
|
3
3
|
* @module @lumjs/core/arrays
|
|
4
4
|
*/
|
|
5
|
+
const {F,S} = require('./types/js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A wrapper class to abstract functionality of various kinds of lists.
|
|
9
|
+
*
|
|
10
|
+
* Supports `Array`, `Set`, and `Map` explicitly.
|
|
11
|
+
* Other classes may be supported. YMMV.
|
|
12
|
+
*
|
|
13
|
+
* @alias module:@lumjs/core/arrays.List
|
|
14
|
+
*/
|
|
15
|
+
class List
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* A list of known closure properties.
|
|
19
|
+
*
|
|
20
|
+
* Corresponding `wrap_${closure}` methods will be used to generate
|
|
21
|
+
* the closure properties.
|
|
22
|
+
*/
|
|
23
|
+
static get KNOWN_CLOSURES()
|
|
24
|
+
{
|
|
25
|
+
return (Object.getOwnPropertyNames(this.prototype)
|
|
26
|
+
.filter(name => name.startsWith('wrap_')));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Build a new List wrapper.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} obj - The list object.
|
|
33
|
+
*
|
|
34
|
+
* Typically an `Array`, `Set`, `Map`, or something similar.
|
|
35
|
+
* Not all of types will support all features. YMMV.
|
|
36
|
+
*
|
|
37
|
+
* @param {object} [opts] Options for advanced use.
|
|
38
|
+
*
|
|
39
|
+
* @param {bool} [opts.allowRaw=false] Attempt to support raw objects?
|
|
40
|
+
*
|
|
41
|
+
* Treat regular Javascript objects as lists, as they are a kind of
|
|
42
|
+
* map after all. This may lead to unusual results. YMMV.
|
|
43
|
+
*
|
|
44
|
+
* @param {mixed} [opts.closures=true] Create closure methods?
|
|
45
|
+
*
|
|
46
|
+
* If `true` or `"*"` we will create all known closure properties.
|
|
47
|
+
*
|
|
48
|
+
* If an `Array` it's the list of closure names we want to create.
|
|
49
|
+
* Possible values can be found in `List.KNOWN_CLOSURES`.
|
|
50
|
+
*
|
|
51
|
+
* If it's a `string` it's treated as a whitespace separated list
|
|
52
|
+
* of closure names and split into an `Array`.
|
|
53
|
+
*
|
|
54
|
+
* If `false` we won't create any closure properties.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
constructor(obj, opts={})
|
|
58
|
+
{
|
|
59
|
+
this.obj = obj;
|
|
60
|
+
this.opts = opts;
|
|
61
|
+
this.allowRaw = opts.allowRaw ?? false;
|
|
62
|
+
this.setupClosures(opts.closures ?? true);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setupClosures(closures)
|
|
66
|
+
{
|
|
67
|
+
if (!closures)
|
|
68
|
+
{ // Nothing to do.
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (closures === true || closures === '*')
|
|
73
|
+
{ // Setup all closures.
|
|
74
|
+
closures = this.constructor.KNOWN_CLOSURES;
|
|
75
|
+
}
|
|
76
|
+
else if (typeof closures === S)
|
|
77
|
+
{
|
|
78
|
+
closures = closures.trim().split(/\s+/);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (Array.isArray(closures))
|
|
82
|
+
{
|
|
83
|
+
for (const closure of closures)
|
|
84
|
+
{
|
|
85
|
+
const meth = 'wrap_'+closure;
|
|
86
|
+
if (typeof this[meth] === F)
|
|
87
|
+
{ // Create the detail property.
|
|
88
|
+
this[closure] = this[meth]();
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
{
|
|
92
|
+
console.error({closure, closures, list: this});
|
|
93
|
+
throw new Error("Unsupported closure");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
{
|
|
99
|
+
console.error({closures, list: this});
|
|
100
|
+
throw new TypeError("Invalid closures value");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
unsupported(obj, forClosure, info, retVal=false)
|
|
105
|
+
{
|
|
106
|
+
console.error("Unsupported object", {obj, forClosure, info, list: this});
|
|
107
|
+
return () => retVal;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Return a closure that returns if an item is in a list object.
|
|
112
|
+
*
|
|
113
|
+
* @param {object} obj - The list object the closure will be for.
|
|
114
|
+
*
|
|
115
|
+
* May be an `Array`, `Set`, `Map`, or `TypedArray` or any object
|
|
116
|
+
* that has either an `includes()` or `has()` method.
|
|
117
|
+
*
|
|
118
|
+
* @returns {function}
|
|
119
|
+
* @throws {TypeError}
|
|
120
|
+
*/
|
|
121
|
+
wrap_contains(obj=this.obj, allowRaw=this.allowRaw)
|
|
122
|
+
{
|
|
123
|
+
if (typeof obj.includes === F)
|
|
124
|
+
{ // Array and TypedArray have includes()
|
|
125
|
+
return item => obj.includes(item);
|
|
126
|
+
}
|
|
127
|
+
else if (typeof obj.has === F)
|
|
128
|
+
{ // Set and Map have has()
|
|
129
|
+
return item => obj.has(item);
|
|
130
|
+
}
|
|
131
|
+
else if (allowRaw)
|
|
132
|
+
{ // A fallback to raw object search.
|
|
133
|
+
return item => (typeof obj[item] !== undefined);
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
{ // Nope.
|
|
137
|
+
return this.unsupported(obj, 'contains', {allowRaw});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Return a closure that removes an item from a list.
|
|
143
|
+
*
|
|
144
|
+
* @param {object} obj - The list object the closure will be for.
|
|
145
|
+
*
|
|
146
|
+
* May be an `Array`, `Set`, `Map`, or anything with a `delete()` method.
|
|
147
|
+
*
|
|
148
|
+
* @returns {function}
|
|
149
|
+
* @throws {TypeError}
|
|
150
|
+
*/
|
|
151
|
+
wrap_remove(obj=this.obj, allowRaw=this.allowRaw)
|
|
152
|
+
{
|
|
153
|
+
let closure;
|
|
154
|
+
if (Array.isArray(obj))
|
|
155
|
+
{ // Arrays have no easy method to do this.
|
|
156
|
+
closure = function(item)
|
|
157
|
+
{
|
|
158
|
+
let removed = 0;
|
|
159
|
+
let index = obj.indexOf(item);
|
|
160
|
+
while (index !== -1)
|
|
161
|
+
{
|
|
162
|
+
obj.splice(index, 1);
|
|
163
|
+
removed++;
|
|
164
|
+
index = obj.indexOf(item, index);
|
|
165
|
+
}
|
|
166
|
+
return removed;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (typeof obj.delete === F)
|
|
170
|
+
{ // Use the delete() method.
|
|
171
|
+
closure = item => (obj.delete(item) ? 1 : 0);
|
|
172
|
+
}
|
|
173
|
+
else if (allowRaw)
|
|
174
|
+
{ // Fallback to removing the property.
|
|
175
|
+
closure = function(item)
|
|
176
|
+
{
|
|
177
|
+
if (obj[item] === undefined)
|
|
178
|
+
{
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
else
|
|
182
|
+
{
|
|
183
|
+
return (delete obj[item] ? 1 : 0);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
{ // Nada.
|
|
189
|
+
closure = this.unsupported(obj, 'remove', {allowRaw}, 0);
|
|
190
|
+
}
|
|
191
|
+
return closure;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* See if our list object contains *any* of the specified items.
|
|
196
|
+
*
|
|
197
|
+
* @param {...any} items
|
|
198
|
+
* @returns {boolean}
|
|
199
|
+
*/
|
|
200
|
+
containsAny(...items)
|
|
201
|
+
{
|
|
202
|
+
for (const item of items)
|
|
203
|
+
{
|
|
204
|
+
if (this.contains(item))
|
|
205
|
+
{ // Item found.
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// No items found.
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* See if our list contains *all* of the specified items.
|
|
216
|
+
*
|
|
217
|
+
* @param {...any} items
|
|
218
|
+
* @returns {boolean}
|
|
219
|
+
*/
|
|
220
|
+
containsAll(...items)
|
|
221
|
+
{
|
|
222
|
+
for (const item of items)
|
|
223
|
+
{
|
|
224
|
+
if (!this.contains(item))
|
|
225
|
+
{ // An item was missing.
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// All items found.
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Remove items from our list object.
|
|
235
|
+
*
|
|
236
|
+
* Passed any number of items, it will see if any of those items are
|
|
237
|
+
* found in the array, and if they are, will remove them from the array.
|
|
238
|
+
*
|
|
239
|
+
* @param {...any} items
|
|
240
|
+
* @returns {number} Number of items actually removed.
|
|
241
|
+
*/
|
|
242
|
+
removeAll(...items)
|
|
243
|
+
{
|
|
244
|
+
let removed = 0;
|
|
245
|
+
for (const item of items)
|
|
246
|
+
{
|
|
247
|
+
removed += this.remove(item);
|
|
248
|
+
}
|
|
249
|
+
return removed;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Return a List instance for the passed object.
|
|
254
|
+
*
|
|
255
|
+
* If the object is already a `List` it is returned as is.
|
|
256
|
+
*
|
|
257
|
+
* @param {object} obj - The list object.
|
|
258
|
+
* @param {object} [opts] - Passed to constructor.
|
|
259
|
+
*/
|
|
260
|
+
static for(obj, opts)
|
|
261
|
+
{
|
|
262
|
+
return (obj instanceof this) ? obj : new this(obj, opts);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const CONTAINS_OPTS = {closures: ['contains']};
|
|
5
267
|
|
|
6
268
|
/**
|
|
7
|
-
* See if an
|
|
8
|
-
*
|
|
269
|
+
* See if an list object contains *any* of the specified items.
|
|
270
|
+
*
|
|
271
|
+
* @param {object} list - A `List` or object for `new List(list)`;
|
|
9
272
|
* @param {...any} items
|
|
10
273
|
* @returns {boolean}
|
|
11
274
|
* @alias module:@lumjs/core/arrays.containsAny
|
|
12
275
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (array.includes(item))
|
|
18
|
-
{ // Item found.
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// No items found.
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.containsAny = containsAny;
|
|
276
|
+
function containsAny(list, ...items)
|
|
277
|
+
{
|
|
278
|
+
return List.for(list, CONTAINS_OPTS).containsAny(...items);
|
|
279
|
+
}
|
|
28
280
|
|
|
29
281
|
/**
|
|
30
|
-
* See if
|
|
31
|
-
*
|
|
282
|
+
* See if a list contains *all* of the specified items.
|
|
283
|
+
*
|
|
284
|
+
* @param {object} list - A `List` or object for `new List(list)`;
|
|
32
285
|
* @param {...any} items
|
|
33
286
|
* @returns {boolean}
|
|
34
287
|
* @alias module:@lumjs/core/arrays.containsAll
|
|
35
288
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// All items found.
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.containsAll = containsAll;
|
|
51
|
-
|
|
289
|
+
function containsAll(list, ...items)
|
|
290
|
+
{
|
|
291
|
+
return List.for(list, CONTAINS_OPTS).containsAll(...items);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const REMOVE_OPTS = {closures: ['remove']};
|
|
295
|
+
|
|
52
296
|
/**
|
|
53
|
-
* Remove items from
|
|
297
|
+
* Remove items from a list object.
|
|
54
298
|
*
|
|
55
299
|
* Passed any number of items, it will see if any of those items are
|
|
56
300
|
* found in the array, and if they are, will remove them from the array.
|
|
57
301
|
*
|
|
58
|
-
* @param {
|
|
302
|
+
* @param {object} list - A `List` or object for `new List(list)`;
|
|
59
303
|
* @param {...any} items
|
|
60
304
|
* @returns {number} Number of items actually removed.
|
|
61
305
|
* @alias module:@lumjs/core/arrays.removeItems
|
|
62
306
|
*/
|
|
63
|
-
function removeItems(
|
|
307
|
+
function removeItems(list, ...items)
|
|
64
308
|
{
|
|
65
|
-
|
|
66
|
-
for (const item of items)
|
|
67
|
-
{
|
|
68
|
-
const index = array.indexOf(item);
|
|
69
|
-
if (index !== -1)
|
|
70
|
-
{
|
|
71
|
-
array.splice(index, 1);
|
|
72
|
-
removed++;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return removed;
|
|
309
|
+
return List.for(list, REMOVE_OPTS).removeAll(...items);
|
|
76
310
|
}
|
|
77
311
|
|
|
78
|
-
exports.removeItems = removeItems;
|
|
79
|
-
|
|
80
312
|
/**
|
|
81
313
|
* Return a Powerset of values in the array.
|
|
82
314
|
* @param {Array} array The array to make the powerset from.
|
|
@@ -99,8 +331,6 @@ function powerset(array)
|
|
|
99
331
|
return ps;
|
|
100
332
|
}
|
|
101
333
|
|
|
102
|
-
exports.powerset = powerset;
|
|
103
|
-
|
|
104
334
|
/**
|
|
105
335
|
* Get a random element from an array.
|
|
106
336
|
* @param {Array} array The array to get an item from.
|
|
@@ -112,4 +342,9 @@ function random(array)
|
|
|
112
342
|
return array[Math.floor(Math.random()*array.length)];
|
|
113
343
|
}
|
|
114
344
|
|
|
115
|
-
exports
|
|
345
|
+
module.exports = exports =
|
|
346
|
+
{
|
|
347
|
+
List, containsAny, containsAll,
|
|
348
|
+
removeItems, powerset, random,
|
|
349
|
+
}
|
|
350
|
+
|
package/lib/index.js
CHANGED
|
@@ -33,47 +33,44 @@ const def = types.def;
|
|
|
33
33
|
*/
|
|
34
34
|
const lazy = types.lazy;
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def(exports, 'types', types, E);
|
|
40
|
-
def(exports, 'def', def, E);
|
|
41
|
-
def(exports, 'lazy', lazy, E);
|
|
36
|
+
def(exports, 'types', types);
|
|
37
|
+
def(exports, 'def', def);
|
|
38
|
+
def(exports, 'lazy', lazy);
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
41
|
* Array utility functions «Lazy»
|
|
45
42
|
* @name module:@lumjs/core.arrays
|
|
46
43
|
* @type {module:@lumjs/core/arrays}
|
|
47
44
|
*/
|
|
48
|
-
lazy(exports, 'arrays', () => require('./arrays')
|
|
45
|
+
lazy(exports, 'arrays', () => require('./arrays'));
|
|
49
46
|
|
|
50
47
|
/**
|
|
51
48
|
* Information about the JS context we're running in
|
|
52
49
|
* @name module:@lumjs/core.context
|
|
53
50
|
* @type {module:@lumjs/core/context}
|
|
54
51
|
*/
|
|
55
|
-
def(exports, 'context', require('./context')
|
|
52
|
+
def(exports, 'context', require('./context'));
|
|
56
53
|
|
|
57
54
|
/**
|
|
58
55
|
* Functions for working with strings and locales «Lazy»
|
|
59
56
|
* @name module:@lumjs/core.strings
|
|
60
57
|
* @type {module:@lumjs/core/strings}
|
|
61
58
|
*/
|
|
62
|
-
lazy(exports, 'strings', () => require('./strings')
|
|
59
|
+
lazy(exports, 'strings', () => require('./strings'));
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
62
|
* Functions for working with binary flags «Lazy»
|
|
66
63
|
* @name module:@lumjs/core.flags
|
|
67
64
|
* @type {module:@lumjs/core/flags}
|
|
68
65
|
*/
|
|
69
|
-
lazy(exports, 'flags', () => require('./flags')
|
|
66
|
+
lazy(exports, 'flags', () => require('./flags'));
|
|
70
67
|
|
|
71
68
|
/**
|
|
72
69
|
* Functions for manipulating objects «Lazy»
|
|
73
70
|
* @name module:@lumjs/core.obj
|
|
74
71
|
* @type {module:@lumjs/core/obj}
|
|
75
72
|
*/
|
|
76
|
-
lazy(exports, 'obj', () => require('./obj')
|
|
73
|
+
lazy(exports, 'obj', () => require('./obj'));
|
|
77
74
|
|
|
78
75
|
/**
|
|
79
76
|
* Functions for getting values and properties with fallback defaults «Lazy»
|
|
@@ -88,7 +85,7 @@ function from(submod, ...libs)
|
|
|
88
85
|
{
|
|
89
86
|
for (const lib of libs)
|
|
90
87
|
{
|
|
91
|
-
def(exports, lib, submod[lib]
|
|
88
|
+
def(exports, lib, submod[lib]);
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
|
|
@@ -133,7 +130,7 @@ from(meta, 'stacktrace', 'AbstractClass', 'Functions', 'NYI');
|
|
|
133
130
|
* @function
|
|
134
131
|
* @see module:@lumjs/core/enum
|
|
135
132
|
*/
|
|
136
|
-
lazy(exports, 'Enum', () => require('./enum')
|
|
133
|
+
lazy(exports, 'Enum', () => require('./enum'));
|
|
137
134
|
|
|
138
135
|
/**
|
|
139
136
|
* Make an object support the *Observable* API «Lazy»
|
|
@@ -141,4 +138,5 @@ lazy(exports, 'Enum', () => require('./enum'), E);
|
|
|
141
138
|
* @function
|
|
142
139
|
* @see module:@lumjs/core/observable
|
|
143
140
|
*/
|
|
144
|
-
lazy(exports, 'observable', () => require('./observable')
|
|
141
|
+
lazy(exports, 'observable', () => require('./observable'));
|
|
142
|
+
|
package/lib/obj/apply.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const {F,isObj} = require('../types');
|
|
2
|
+
const copyProps = require('./copyprops');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Apply functions to an object
|
|
6
|
+
*
|
|
7
|
+
* In addition to the parameters passed, we'll also define:
|
|
8
|
+
*
|
|
9
|
+
* - `cp` will be a `CopyProps` instance via `copyProps.cache.into(obj)`;
|
|
10
|
+
* - `args` will be an array of `[obj, opts]`;
|
|
11
|
+
* - `opts` will be an object of `{obj, cp, args}`;
|
|
12
|
+
*
|
|
13
|
+
* @param {(object|function)} obj - The target we're applying to.
|
|
14
|
+
*
|
|
15
|
+
* @param {...(function|object)} fns - Values we are applying.
|
|
16
|
+
*
|
|
17
|
+
* For each value of `fns` as `fn`:
|
|
18
|
+
*
|
|
19
|
+
* - If a `function` we'll call `fn.apply(obj, args)`;
|
|
20
|
+
* - If an `object` we'll call `cp.from(fn)`.
|
|
21
|
+
*
|
|
22
|
+
* @returns {object} `obj`
|
|
23
|
+
* @throws {TypeError} If a `fns` value is not valid.
|
|
24
|
+
* @alias module:@lumjs/core/obj.apply
|
|
25
|
+
*/
|
|
26
|
+
function apply(obj, ...fns)
|
|
27
|
+
{
|
|
28
|
+
const cp = copyProps.cache.into(obj);
|
|
29
|
+
const opts = {obj, cp};
|
|
30
|
+
const args = [obj, opts];
|
|
31
|
+
opts.args = args;
|
|
32
|
+
|
|
33
|
+
for (const fn of fns)
|
|
34
|
+
{
|
|
35
|
+
if (typeof fn === F)
|
|
36
|
+
{
|
|
37
|
+
fn.apply(obj, args);
|
|
38
|
+
}
|
|
39
|
+
else if (isObj(fn))
|
|
40
|
+
{
|
|
41
|
+
cp.from(fn);
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
{
|
|
45
|
+
throw new TypeError("invalid parameter value");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = apply;
|
package/lib/obj/copyall.js
CHANGED
|
@@ -39,7 +39,7 @@ exports.duplicateOne = copyAll.clone = obj => copyAll({}, obj);
|
|
|
39
39
|
*
|
|
40
40
|
* Use `copyProps.into({}).from(...sources)` for a more robust version.
|
|
41
41
|
*
|
|
42
|
-
* Alias: `copyAll.
|
|
42
|
+
* Alias: `copyAll.duplicate`
|
|
43
43
|
*
|
|
44
44
|
* @alias module:@lumjs/core/obj.duplicateOne
|
|
45
45
|
* @param {object} obj - The object to duplicate.
|
package/lib/obj/copyprops.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
// Get some constants
|
|
3
|
-
const {B,N,F,isObj,isArray,needObj,def,console} = require('../types');
|
|
4
|
-
const {duplicateOne: clone} = require('./copyall');
|
|
3
|
+
const {S,B,N,F,isObj,isArray,needObj,def,console} = require('../types');
|
|
4
|
+
const {copyAll, duplicateOne: clone} = require('./copyall');
|
|
5
5
|
|
|
6
6
|
const RECURSE_NONE = 0;
|
|
7
7
|
const RECURSE_ALL = -1;
|
|
@@ -233,22 +233,35 @@ def(copyProps, 'RECURSE_LIST', RECURSE_LIST);
|
|
|
233
233
|
* // Get a copy of the `copyProps` function.
|
|
234
234
|
* const cp = require('@lumjs/core').obj.copyProps;
|
|
235
235
|
*
|
|
236
|
-
* // Starting with the target:
|
|
236
|
+
* // Starting with the target(s):
|
|
237
237
|
* cp.into(targetObj).given({all: true}).from(source1, source2);
|
|
238
238
|
*
|
|
239
|
-
* // Starting with the
|
|
239
|
+
* // Starting with the source(s):
|
|
240
240
|
* cp.from(sourceObj).given({exclude: ['dontCopy']}).into(target1, target2);
|
|
241
241
|
*
|
|
242
242
|
* // Starting with the options:
|
|
243
243
|
* cp.given({recursive: cp.RECURSE_ALL}).from(source1, source2).into(target1, target2);
|
|
244
244
|
*
|
|
245
|
+
* // Call `cp.into()` and cache the instance in a `Map`.
|
|
246
|
+
* // Future calls with the same `targetObj` will return the cached instance.
|
|
247
|
+
* // Unlike `cp.into()`, only supports a single `targetObj`.
|
|
248
|
+
* cp.cache.into(targetObj);
|
|
249
|
+
*
|
|
250
|
+
* // Call `cp.from()` and cache the instance in a `Map`.
|
|
251
|
+
* // Future calls with the same `sourceObj` will return the cached instance.
|
|
252
|
+
* // Unlike `cp.from()`, only supports a single `sourceObj`.
|
|
253
|
+
* cp.cache.from(sourceObj);
|
|
245
254
|
*
|
|
255
|
+
* // Clear the `Map` instances for `cp.cache.into` and `cp.cache.from`
|
|
256
|
+
* cp.cache.clear();
|
|
257
|
+
*
|
|
246
258
|
* ```
|
|
247
259
|
*
|
|
248
260
|
* @alias module:@lumjs/core/obj~CopyProps
|
|
249
261
|
*/
|
|
250
262
|
class $CopyProps
|
|
251
263
|
{
|
|
264
|
+
// Constructor is private so we won't document it.
|
|
252
265
|
constructor(opts={})
|
|
253
266
|
{
|
|
254
267
|
this.opts = opts;
|
|
@@ -257,21 +270,42 @@ class $CopyProps
|
|
|
257
270
|
}
|
|
258
271
|
|
|
259
272
|
/**
|
|
260
|
-
* Set
|
|
261
|
-
*
|
|
262
|
-
* @param {
|
|
273
|
+
* Set options.
|
|
274
|
+
*
|
|
275
|
+
* @param {(string|object)} opt - Option(s) to set.
|
|
276
|
+
*
|
|
277
|
+
* If this is a `string` it's the name of an option to set.
|
|
278
|
+
* If this is an `object`, it's map of options to set with `copyAll`.
|
|
279
|
+
*
|
|
280
|
+
* @param {*} value - The option value.
|
|
281
|
+
*
|
|
282
|
+
* Only used if `option` is a `string`.
|
|
283
|
+
*
|
|
263
284
|
* @returns {object} `this`
|
|
264
285
|
*/
|
|
265
|
-
set(
|
|
286
|
+
set(opt, value)
|
|
266
287
|
{
|
|
267
|
-
|
|
288
|
+
//console.debug("CopyProps.set(", opt, value, ')');
|
|
289
|
+
if (typeof opt === S)
|
|
290
|
+
{ // Set a single option.
|
|
291
|
+
this.opts[opt] = value;
|
|
292
|
+
}
|
|
293
|
+
else if (isObj(opt))
|
|
294
|
+
{ // Set a bunch of options.
|
|
295
|
+
copyAll(this.opts, opt);
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
{ // That's not supported
|
|
299
|
+
console.error("invalid opt", {opt, value, cp: this});
|
|
300
|
+
}
|
|
301
|
+
//console.debug("CopyProps.set:after", this);
|
|
268
302
|
return this;
|
|
269
303
|
}
|
|
270
304
|
|
|
271
305
|
/**
|
|
272
|
-
* Set all
|
|
306
|
+
* Set all options.
|
|
273
307
|
*
|
|
274
|
-
* This replaces
|
|
308
|
+
* This replaces any existing options entirely.
|
|
275
309
|
*
|
|
276
310
|
* @param {object} opts - The options to set.
|
|
277
311
|
* @returns {object} `this`
|
|
@@ -372,4 +406,48 @@ copyProps.from = function(...sources)
|
|
|
372
406
|
return ((new $CopyProps()).from(...sources));
|
|
373
407
|
}
|
|
374
408
|
|
|
409
|
+
const CPC = copyProps.cache =
|
|
410
|
+
{
|
|
411
|
+
into(target)
|
|
412
|
+
{
|
|
413
|
+
if (this.intoCache === undefined)
|
|
414
|
+
this.intoCache = new Map();
|
|
415
|
+
const cache = this.intoCache;
|
|
416
|
+
if (cache.has(target))
|
|
417
|
+
{
|
|
418
|
+
return cache.get(target);
|
|
419
|
+
}
|
|
420
|
+
else
|
|
421
|
+
{
|
|
422
|
+
const cp = copyProps.into(target);
|
|
423
|
+
cache.set(target, cp);
|
|
424
|
+
return cp;
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
from(source)
|
|
428
|
+
{
|
|
429
|
+
if (this.fromCache === undefined)
|
|
430
|
+
this.fromCache = new Map();
|
|
431
|
+
const cache = this.fromCache;
|
|
432
|
+
if (cache.has(source))
|
|
433
|
+
{
|
|
434
|
+
return cache.get(source);
|
|
435
|
+
}
|
|
436
|
+
else
|
|
437
|
+
{
|
|
438
|
+
const cp = copyProps.from(source);
|
|
439
|
+
cache.set(source, cp);
|
|
440
|
+
return cp;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
clear()
|
|
444
|
+
{
|
|
445
|
+
if (this.intoCache)
|
|
446
|
+
this.intoCache.clear();
|
|
447
|
+
if (this.fromCache)
|
|
448
|
+
this.fromCache.clear();
|
|
449
|
+
return this;
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
|
|
375
453
|
module.exports = copyProps;
|
package/lib/obj/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @module @lumjs/core/obj
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const apply = require('./apply');
|
|
6
7
|
const {copyAll,duplicateOne,duplicateAll} = require('./copyall');
|
|
7
8
|
const copyProps = require('./copyprops');
|
|
8
9
|
const {CLONE,clone,addClone,cloneIfLocked} = require('./clone');
|
|
@@ -23,5 +24,5 @@ module.exports =
|
|
|
23
24
|
mergeNested, syncNested, copyProps, copyAll, ns,
|
|
24
25
|
getObjectPath, setObjectPath, getNamespace, setNamespace,
|
|
25
26
|
getProperty, duplicateAll, duplicateOne, getMethods, signatureOf,
|
|
26
|
-
MethodFilter,
|
|
27
|
+
MethodFilter, apply,
|
|
27
28
|
}
|
package/lib/observable.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Defining these after observable.
|
|
2
2
|
const {B,F,S,def,isObj,isComplex,TYPES,console} = require('./types');
|
|
3
3
|
const {duplicateAll: clone} = require('./obj/copyall');
|
|
4
4
|
const lock = Object.freeze;
|
|
@@ -150,7 +150,7 @@ function observable (el={}, opts={})
|
|
|
150
150
|
|
|
151
151
|
let fobj;
|
|
152
152
|
|
|
153
|
-
if (
|
|
153
|
+
if (wrapped)
|
|
154
154
|
{ // Something is going to use our wrapper object.
|
|
155
155
|
const isWild = (name === wildcard);
|
|
156
156
|
const fname = isWild ? (addname ? args[0] : args.shift()) : name;
|
package/lib/types/console.js
CHANGED
|
@@ -2,7 +2,7 @@ const def = require('./def');
|
|
|
2
2
|
const {F} = require('./js');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* A super simple wrapper around the Javascript console.
|
|
5
|
+
* A super simple singleton wrapper around the Javascript console.
|
|
6
6
|
*
|
|
7
7
|
* By default includes `info`, `log`, `warn`, and `error` methods.
|
|
8
8
|
* It may be expanded further using the `addMethod` method.
|
|
@@ -14,25 +14,68 @@ const LC =
|
|
|
14
14
|
/**
|
|
15
15
|
* A custom handler.
|
|
16
16
|
*
|
|
17
|
-
* If a `function`, will be
|
|
18
|
-
* first parameter, and method arguments as subsequent parameters.
|
|
17
|
+
* If a `function`, it will be called to handle all method calls.
|
|
19
18
|
*
|
|
20
19
|
* If an `Array`, it will have all log entries added as objects with
|
|
21
|
-
* `time`, `method`, and `
|
|
20
|
+
* at least `time`, `method`, and `opts` properties.
|
|
21
|
+
* By default and `arguments` property will also be included.
|
|
22
|
+
* See `msgArguments` and `msgArgs` for further details.
|
|
22
23
|
*
|
|
23
24
|
* If the boolean value `false`, all output will be thrown into the void.
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* If it is an `object`, then each property name represents a method name,
|
|
27
|
+
* and the values will be treated as a handler for that method only.
|
|
28
|
+
* All handler types are supported (i.e. `function`, `Array`, or `false`.)
|
|
29
|
+
* A special method name of `DEFAULT` may be specified as a default handler
|
|
30
|
+
* for method names not explicitly specified in the object.
|
|
31
|
+
* If no `DEFAULT` is specified and there is no handler value for a method
|
|
32
|
+
* name, calls to it will be passed through to the real console object.
|
|
33
|
+
*
|
|
34
|
+
* If no handler was set, all methods are passed to the real console object.
|
|
35
|
+
*
|
|
36
|
+
* Default value: `null`
|
|
27
37
|
*/
|
|
28
|
-
handler: null,
|
|
38
|
+
handler: null,
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* Return the message object?
|
|
31
42
|
*
|
|
32
43
|
* Only applicable if `handler` is an `Array`.
|
|
33
|
-
*
|
|
44
|
+
*
|
|
45
|
+
* If `true`, return the message `object`.
|
|
46
|
+
* If `false`, returns `undefined`.
|
|
47
|
+
*
|
|
48
|
+
* Default value: `false`
|
|
49
|
+
*/
|
|
50
|
+
returnMsg: false,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The name to include the `arguments` magic object in the log.
|
|
54
|
+
*
|
|
55
|
+
* Only applicable if `handler` is an `Array`.
|
|
56
|
+
*
|
|
57
|
+
* This used to be hard-coded as `"arguments"` but the `shortArgs`
|
|
58
|
+
* option has replaced it as the array is simpler for most purposes.
|
|
59
|
+
*
|
|
60
|
+
* Default value: `null`
|
|
61
|
+
*/
|
|
62
|
+
msgArguments: null,
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The name to include the `args` array in the log.
|
|
66
|
+
*
|
|
67
|
+
* Only applicable if `handler` is an `Array`.
|
|
68
|
+
*
|
|
69
|
+
* Default value: `"arguments"`
|
|
34
70
|
*/
|
|
35
|
-
|
|
71
|
+
msgArgs: 'arguments',
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Use the method name as the first argument in function calls.
|
|
75
|
+
*
|
|
76
|
+
* Default value: `true`
|
|
77
|
+
*/
|
|
78
|
+
methodArg: true,
|
|
36
79
|
}
|
|
37
80
|
|
|
38
81
|
/**
|
|
@@ -45,6 +88,12 @@ def(LC, 'real', RC);
|
|
|
45
88
|
// Only including a few common ones.
|
|
46
89
|
const DEFAULT_METHODS = ['debug','info','log','warn','error'];
|
|
47
90
|
|
|
91
|
+
// Options that can be changed via handler settings.
|
|
92
|
+
const HANDLER_OPTIONS =
|
|
93
|
+
[
|
|
94
|
+
'returnMsg', 'methodArg', 'msgArguments', 'msgArgs'
|
|
95
|
+
];
|
|
96
|
+
|
|
48
97
|
/**
|
|
49
98
|
* Add a wrapper method to the console wrapper object.
|
|
50
99
|
* @param {string} method - The console method to wrap.
|
|
@@ -52,25 +101,75 @@ const DEFAULT_METHODS = ['debug','info','log','warn','error'];
|
|
|
52
101
|
*/
|
|
53
102
|
function addMethod(method)
|
|
54
103
|
{
|
|
55
|
-
def(LC, method, function()
|
|
104
|
+
def(LC, method, function(...args)
|
|
56
105
|
{
|
|
57
|
-
if (typeof LC.
|
|
58
|
-
{ //
|
|
59
|
-
|
|
106
|
+
if (typeof LC.trigger === F)
|
|
107
|
+
{ // Support for core.observable(core.types.console);
|
|
108
|
+
LC.trigger(method, ...args);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let handler = LC.handler;
|
|
112
|
+
const opts = {}
|
|
113
|
+
|
|
114
|
+
function checkHandlerOptions(src)
|
|
115
|
+
{
|
|
116
|
+
for (const opt of HANDLER_OPTIONS)
|
|
117
|
+
{
|
|
118
|
+
if (src[opt] !== undefined)
|
|
119
|
+
{
|
|
120
|
+
opts[opt] = src[opt];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Get the default options.
|
|
126
|
+
checkHandlerOptions(LC);
|
|
127
|
+
|
|
128
|
+
// Check for complex handler definitions as a plain object.
|
|
129
|
+
if (isObj(handler) && !Array.isArray(handler))
|
|
130
|
+
{ // Look for options in the handler defs.
|
|
131
|
+
checkHandlerOptions(handler);
|
|
132
|
+
|
|
133
|
+
if (handler[method] !== undefined)
|
|
134
|
+
{ // A handler for that method was found.
|
|
135
|
+
handler = handler[method];
|
|
136
|
+
}
|
|
137
|
+
else if (handler.DEFAULT !== undefined)
|
|
138
|
+
{ // A default handler.
|
|
139
|
+
handler = handler.DEFAULT;
|
|
140
|
+
}
|
|
60
141
|
}
|
|
61
|
-
|
|
62
|
-
|
|
142
|
+
|
|
143
|
+
if (typeof handler === F)
|
|
144
|
+
{ // A custom handler function.
|
|
145
|
+
checkHandlerOptions(handler);
|
|
146
|
+
if (opts.methodArg)
|
|
147
|
+
args.unshift(method)
|
|
148
|
+
return handler(...args);
|
|
149
|
+
}
|
|
150
|
+
else if (Array.isArray(handler))
|
|
151
|
+
{ // Add a message item to a log array.
|
|
152
|
+
checkHandlerOptions(handler);
|
|
153
|
+
|
|
63
154
|
const time = new Date().toJSON();
|
|
64
|
-
const msg = {time, method,
|
|
65
|
-
|
|
66
|
-
if (
|
|
155
|
+
const msg = {time, method, opts};
|
|
156
|
+
|
|
157
|
+
if (typeof opts.msgArguments === S)
|
|
158
|
+
msg[opts.msgArguments] = arguments;
|
|
159
|
+
if (typeof opts.msgArgs === S)
|
|
160
|
+
msg[opts.msgArgs] = args;
|
|
161
|
+
|
|
162
|
+
handler.push(msg);
|
|
163
|
+
|
|
164
|
+
if (opts.returnMsg) return msg;
|
|
67
165
|
}
|
|
68
|
-
else if (
|
|
166
|
+
else if (handler !== false)
|
|
69
167
|
{ // Pass through to the real console.
|
|
70
|
-
return RC[method](...
|
|
168
|
+
return RC[method](...args);
|
|
71
169
|
}
|
|
72
170
|
});
|
|
73
171
|
}
|
|
172
|
+
|
|
74
173
|
def(LC, 'addMethod', addMethod);
|
|
75
174
|
|
|
76
175
|
for (const method of DEFAULT_METHODS)
|
package/lib/types/typelist.js
CHANGED
|
@@ -35,6 +35,7 @@ const
|
|
|
35
35
|
* @property {string} NIL - Either `null` or `undefined`.
|
|
36
36
|
* @property {string} NOTNIL - Anything other than `null` or `undefined`.
|
|
37
37
|
* @property {string} MAP - A `Map` object.
|
|
38
|
+
* @property {string} SET - A `Set` object.
|
|
38
39
|
* @property {object} tests - A map of tests for the above types.
|
|
39
40
|
*/
|
|
40
41
|
const TYPES = {};
|
|
@@ -162,6 +163,7 @@ const
|
|
|
162
163
|
NIL: isNil,
|
|
163
164
|
NOTNIL: notNil,
|
|
164
165
|
MAP: v => v instanceof Map,
|
|
166
|
+
SET: v => v instanceof Set,
|
|
165
167
|
});
|
|
166
168
|
|
|
167
169
|
module.exports = TYPES;
|