@lumjs/core 1.26.0 → 1.31.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/README.md +15 -1
- package/jsdoc.js +13 -0
- package/lib/console.js +54 -0
- package/lib/enum.js +65 -15
- package/lib/events/event.js +85 -0
- package/lib/events/index.js +30 -0
- package/lib/events/listener.js +127 -0
- package/lib/events/registry.js +537 -0
- package/lib/index.js +34 -17
- package/lib/meta.js +71 -82
- package/lib/obj/clone.js +1 -1
- package/lib/obj/copyprops.js +2 -2
- package/lib/obj/cp.js +1375 -0
- package/lib/obj/flip.js +2 -0
- package/lib/obj/index.js +2 -1
- package/lib/obj/merge.js +1 -1
- package/lib/obj/ns.js +1 -1
- package/lib/objectid.js +41 -13
- package/lib/observable.js +1 -1
- package/lib/old/abstractclass.js +82 -0
- package/lib/opt/args.js +50 -0
- package/lib/opt/getpath.js +70 -0
- package/lib/opt/getval.js +61 -0
- package/lib/opt/index.js +21 -0
- package/lib/opt/val.js +63 -0
- package/lib/strings.js +1 -1
- package/lib/types/basics.js +35 -16
- package/lib/types/def.js +49 -36
- package/lib/types/dt.js +147 -18
- package/lib/types/index.js +32 -59
- package/lib/types/isa.js +4 -0
- package/lib/types/js.js +43 -7
- package/lib/types/lazy.js +3 -2
- package/lib/types/needs.js +0 -1
- package/lib/types/typelist.js +6 -4
- package/lum.build.js +40 -0
- package/package.json +24 -14
- package/TODO.md +0 -76
- package/jsdoc.json +0 -33
- package/lib/opt.js +0 -664
package/lib/meta.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
|
-
* Meta-programming helpers
|
|
3
|
+
* Meta-programming helpers
|
|
4
|
+
*
|
|
5
|
+
* All of the function exported by this module are also available
|
|
6
|
+
* in the main {@link module:@lumjs/core core object} itself.
|
|
7
|
+
*
|
|
3
8
|
* @module @lumjs/core/meta
|
|
4
9
|
*/
|
|
5
10
|
|
|
6
|
-
const {F
|
|
11
|
+
const {F} = require('./types/js');
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Get a stacktrace. Differs from browser to browser.
|
|
@@ -25,85 +30,6 @@ function stacktrace(msg)
|
|
|
25
30
|
|
|
26
31
|
exports.stacktrace = stacktrace;
|
|
27
32
|
|
|
28
|
-
/**
|
|
29
|
-
* Abstract classes for Javascript.
|
|
30
|
-
* @deprecated Just use `throw new AbstractError()` instead.
|
|
31
|
-
* @alias module:@lumjs/core/meta.AbstractClass
|
|
32
|
-
*/
|
|
33
|
-
class AbstractClass
|
|
34
|
-
{
|
|
35
|
-
/**
|
|
36
|
-
* If you want to mark a method as abstract use this.
|
|
37
|
-
*/
|
|
38
|
-
$abstract(name)
|
|
39
|
-
{
|
|
40
|
-
if (name.indexOf('(') === -1)
|
|
41
|
-
{ // Add empty method signature.
|
|
42
|
-
name += '()';
|
|
43
|
-
}
|
|
44
|
-
throw new Error(`Abstract method ${name} was not implemented`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Check for required properties
|
|
49
|
-
*
|
|
50
|
-
* @param {...(string|Array)} needs - What is needed
|
|
51
|
-
*
|
|
52
|
-
* If this is a `string` it should be in a format like:
|
|
53
|
-
*
|
|
54
|
-
* - `methodName(arg1,arg2,arg3)`
|
|
55
|
-
* - `anotherMethod(number, string, object) : boolean`
|
|
56
|
-
* - `yetAnother (className) : resultClass`
|
|
57
|
-
*
|
|
58
|
-
* The names are case sensitive, and we'll look for the method after
|
|
59
|
-
* stripping off anything from the first *non-word* character.
|
|
60
|
-
*
|
|
61
|
-
* If this is an `Array`, the first item must be the name of a property,
|
|
62
|
-
* and each other item should be a type checking value, or array of type
|
|
63
|
-
* checking values from the [TYPES]{@link module:@lumjs/core/types.TYPES}
|
|
64
|
-
* object, as used by [isa()]{@link module:@lumjs/core/types.isa}.
|
|
65
|
-
*
|
|
66
|
-
* If you are calling this in an abstract class constructor, likely only
|
|
67
|
-
* the method checks will be useful, as the `super()` call must be done
|
|
68
|
-
* *before* any instance property assignments.
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
$needs(...needs)
|
|
72
|
-
{
|
|
73
|
-
const className = this.constructor.name;
|
|
74
|
-
|
|
75
|
-
const getName = fullName => fullName.replace(/\W.*/, '');
|
|
76
|
-
const missing = propName =>
|
|
77
|
-
{
|
|
78
|
-
throw new Error(`${className} is missing ${propName}`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (const need of needs)
|
|
82
|
-
{
|
|
83
|
-
if (typeof need === S)
|
|
84
|
-
{ // A simple method
|
|
85
|
-
const meth = getName(need);
|
|
86
|
-
if (typeof this[meth] !== F)
|
|
87
|
-
{
|
|
88
|
-
missing(need);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else if (isArray(need))
|
|
92
|
-
{
|
|
93
|
-
const prop = getName(need[0]);
|
|
94
|
-
const types = need.slice(1);
|
|
95
|
-
if (!isa(this[prop], ...types))
|
|
96
|
-
{
|
|
97
|
-
missing(need);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.AbstractClass = AbstractClass;
|
|
106
|
-
|
|
107
33
|
/**
|
|
108
34
|
* An Error that can be thrown from abstract methods.
|
|
109
35
|
*
|
|
@@ -164,7 +90,6 @@ exports.AbstractError = AbstractError;
|
|
|
164
90
|
|
|
165
91
|
/**
|
|
166
92
|
* Function prototypes for async, generator, and async generator functions.
|
|
167
|
-
* @namespace
|
|
168
93
|
* @alias module:@lumjs/core/meta.Functions
|
|
169
94
|
*/
|
|
170
95
|
const Functions =
|
|
@@ -208,3 +133,67 @@ function NYI(fatal=true, prefix='')
|
|
|
208
133
|
}
|
|
209
134
|
|
|
210
135
|
exports.NYI = NYI;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Send a deprecation message with a stack trace.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} dep - Name of what is deprecated
|
|
141
|
+
* @param {(string|string[])} [rep] Replacement suggestion(s).
|
|
142
|
+
* @param {*} [ret] Value to return
|
|
143
|
+
* @returns {mixed} `ret`
|
|
144
|
+
* @alias module:@lumjs/core/meta.deprecated
|
|
145
|
+
*/
|
|
146
|
+
function deprecated(dep, rep, ret)
|
|
147
|
+
{
|
|
148
|
+
const msgs = [dep,'is deprecated'];
|
|
149
|
+
if (rep)
|
|
150
|
+
{
|
|
151
|
+
msgs.push('replace with', rep);
|
|
152
|
+
}
|
|
153
|
+
console.trace(...msgs);
|
|
154
|
+
return ret;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
exports.deprecated = deprecated;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Assign a getter property that when accessed will
|
|
161
|
+
* show a deprecation message via `deprecated()` function
|
|
162
|
+
* before returning the deprecated property value.
|
|
163
|
+
*
|
|
164
|
+
* @param {object} obj - Target to assign property on
|
|
165
|
+
* @param {string} prop - Property to assign
|
|
166
|
+
* @param {(object|function)} spec - Specification
|
|
167
|
+
*
|
|
168
|
+
* If this is a `function` it will be used as the `spec.get` value.
|
|
169
|
+
*
|
|
170
|
+
* @param {function} spec.get - The function that returns the real value
|
|
171
|
+
* @param {string} [spec.dep=prop] Name of what is deprecated;
|
|
172
|
+
* defaults to `prop` if omitted.
|
|
173
|
+
* @param {(string|string[])} [spec.rep] Replacement suggestion(s).
|
|
174
|
+
* @param {object} [spec.opts] Options for `def()` to add getter with.
|
|
175
|
+
*
|
|
176
|
+
* @returns {object} `obj`
|
|
177
|
+
*
|
|
178
|
+
* @alias module:@lumjs/core/meta.wrapDepr
|
|
179
|
+
*/
|
|
180
|
+
function wrapDepr(obj,prop,spec)
|
|
181
|
+
{
|
|
182
|
+
if (typeof spec === F)
|
|
183
|
+
spec = {get: spec};
|
|
184
|
+
if (typeof spec.get !== F)
|
|
185
|
+
throw new TypeError("invalid init");
|
|
186
|
+
|
|
187
|
+
return def(obj, prop,
|
|
188
|
+
{
|
|
189
|
+
get: () =>
|
|
190
|
+
deprecated(spec.dep??prop, spec.rep, spec.get())
|
|
191
|
+
}, spec.opts);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
exports.wrapDepr = wrapDepr;
|
|
195
|
+
|
|
196
|
+
// This is near the bottom, but before any calls to wrapDepr.
|
|
197
|
+
const def = require('./types/def');
|
|
198
|
+
|
|
199
|
+
wrapDepr(exports, 'AbstractClass', () => require('./old/abstractclass'));
|
package/lib/obj/clone.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Import *most* required bits here.
|
|
2
|
-
const {N,F, isObj, isComplex, def, isArray
|
|
2
|
+
const {N,F, isObj, isComplex, def, isArray} = require('../types');
|
|
3
3
|
const copyProps = require('./copyprops');
|
|
4
4
|
const getProp = require('./getproperty');
|
|
5
5
|
|
package/lib/obj/copyprops.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
// Get some constants
|
|
3
|
-
const {S,B,N,F,isObj,isArray,needObj,def
|
|
3
|
+
const {S,B,N,F,isObj,isArray,needObj,def} = require('../types');
|
|
4
4
|
const {copyAll, duplicateOne: clone} = require('./copyall');
|
|
5
5
|
|
|
6
6
|
const RECURSE_NONE = 0;
|
|
@@ -406,7 +406,7 @@ copyProps.from = function(...sources)
|
|
|
406
406
|
return ((new $CopyProps()).from(...sources));
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
|
|
409
|
+
copyProps.cache =
|
|
410
410
|
{
|
|
411
411
|
into(target)
|
|
412
412
|
{
|