@lumjs/compat 1.4.0 → 2.0.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.
@@ -1,34 +0,0 @@
1
- const core = require('@lumjs/core');
2
-
3
- /**
4
- * A helper for building modules «Lazy»
5
- *
6
- * @name module:@lumjs/core.ModuleBuilder
7
- * @see module:@lumjs/core/modulebuilder
8
- * @deprecated
9
- */
10
- core.lazy(core, 'ModuleBuilder', () => require('./index'), E);
11
-
12
- /**
13
- * Return a set of functions for building a module.
14
- *
15
- * @alias module:@lumjs/core.buildModule
16
- * @see module:@lumjs/core/modulebuilder.build
17
- * @deprecated
18
- */
19
- core.buildModule = function(m,o)
20
- {
21
- return core.ModuleBuilder.build(m,o);
22
- }
23
-
24
- /**
25
- * Create a new `ModuleBuilder` instance.
26
- *
27
- * @alias module:@lumjs/core.newBuilder
28
- * @see module:@lumjs/core/modulebuilder.new
29
- * @deprecated
30
- */
31
- core.newBuilder = function(m, o)
32
- {
33
- return core.ModuleBuilder.new(m,o);
34
- }
@@ -1,122 +0,0 @@
1
- /**
2
- * Mark a function/method/property as deprecated.
3
- *
4
- * Adds a warning to the Console that the method is deprecated.
5
- *
6
- * It can also optionally give example replacement code, and run a function
7
- * that will call the replacement code automatically.
8
- *
9
- * @param {string} name The name of the deprecated method/property/etc.
10
- *
11
- * This should actually be the full method signature, or at least the
12
- * signature matching what a call to the deprecated method made.
13
- *
14
- * So rather than 'someOldMethod', use 'MyClass.someOldMethod(foo, bar)'
15
- * as a more detailed name. This is only used in the Console warning.
16
- *
17
- * This is the only mandatory parameter.
18
- *
19
- * @param {mixed} [replace={}] Replacement options.
20
- *
21
- * If this is a {string}, it is the same as passing an {object} with
22
- * the following options specified:
23
- *
24
- * ```{msg: replace}```
25
- *
26
- * If it is a {function}, it is the same as passing an {object} with
27
- * the following options specified:
28
- *
29
- * ```{exec: replace, msg: true, strip: true}```
30
- *
31
- * If it is an {object}, then it will be a set of options:
32
- *
33
- * "exec" {function}
34
- *
35
- * If specified, this function will be called and the value returned.
36
- * No paramters are passed to the function, so it should be a simple
37
- * anonymous closure which simply calls the actual replacement code.
38
- *
39
- * "msg" {string|boolean}
40
- *
41
- * If this is a {string} it will be added to the warning output.
42
- *
43
- * If this is `true` and `exec` is set, we will extract the function
44
- * text using `exec.toString()` and add it to the warning output.
45
- *
46
- * In any other cases, no replacement message will be appended.
47
- *
48
- * "strip" {boolean}
49
- *
50
- * If this is `true`, then we will strip `'function() { return '`
51
- * from the start of the function text (whitespace ignored), as well
52
- * as stripping '}' from the very end of the function text.
53
- *
54
- * This is only applicable if `exec` is set, and `msg` is `true`.
55
- *
56
- * If the `replace` value is none of the above, it will be ignored.
57
- *
58
- * @return {mixed} The output is dependent on the parameters passed.
59
- *
60
- * If `replace` is a function or an object with
61
- *
62
- * In any other case the return value will be undefined.
63
- *
64
- * @alias module:@lumjs/compat/v4/deprecated
65
- */
66
- module.exports = function (name, replace={})
67
- {
68
- const DEP_MSG = ':Deprecated =>';
69
- const REP_MSG = ':replaceWith =>';
70
-
71
- if (typeof replace === S)
72
- { // A string replacement example only.
73
- replace = {msg: replace};
74
- }
75
- else if (typeof replace === F)
76
- { // A function replacement.
77
- replace = {exec: replace, msg: true, strip: true};
78
- }
79
- else if (!is_obj(replace))
80
- { // Not an object, that's not valid.
81
- replace = {};
82
- }
83
-
84
- const msgs = [DEP_MSG, name];
85
- const exec = (typeof replace.exec === F)
86
- ? replace.exec
87
- : null;
88
-
89
- if (exec && replace.msg === true)
90
- { // Extract the function text.
91
- const strip = (typeof replace.strip === B)
92
- ? replace.strip
93
- : false;
94
-
95
- let methtext = replace.exec.toString();
96
-
97
- if (strip)
98
- { // Remove wrapping anonymous closure function.
99
- methtext = methtext.replace(/^function\(\)\s*\{\s*(return\s*)?/, '');
100
- methtext = methtext.replace(/\s*\}$/, '');
101
- // Also support arrow function version.
102
- methtext = methtext.replace(/^\(\)\s*\=\>\s*/, '');
103
- }
104
-
105
- // Set the replacement msg to the method text.
106
- replace.msg = methtext;
107
- }
108
-
109
- if (typeof replace.msg === 'string')
110
- { // A replacement message.
111
- msgs.push(REP_MSG, replace.msg);
112
- }
113
-
114
- // Show the messages.
115
- console.warn(...msgs);
116
-
117
- // Finally, call the replacement function if it was defined.
118
- if (exec)
119
- {
120
- return exec();
121
- }
122
- }
@@ -1,217 +0,0 @@
1
- /**
2
- * Descriptors magic objects library.
3
- * @module @lumjs/compat/v4/descriptors
4
- */
5
-
6
- const core = require('@lumjs/core');
7
- const {InternalObjectId,Enum,types} = core;
8
- const {doesDescriptor,isObj,def,B,F,N} = types;
9
-
10
- // We moved getProperty() to the `@lumjs/core/obj` module.
11
- const getProperty = core.obj.getProperty;
12
- exports.getProperty = getProperty;
13
-
14
- const DESC_ID = new InternalObjectId({name: '$LumDescriptor'});
15
- const DESC_ADD = Enum(['ONE', 'SHORT', 'SET'], {flags: true});
16
-
17
- /**
18
- * Create a magic Descriptor object.
19
- * @param {object} desc - Descriptor template.
20
- * @param {object} [opts] - Options (to be documented.)
21
- * @returns {object} `desc`
22
- * @alias module:@lumjs/compat/v4/descriptors.descriptor
23
- */
24
- function descriptor(desc, opts={})
25
- {
26
- if (!isObj(opts)) throw new TypeError("Options must be an object");
27
-
28
- if (typeof desc === B)
29
- { // This is a special case.
30
- opts.accessorSafe = desc;
31
- opts.add = DESC_ADD.ONE;
32
- desc = {};
33
- }
34
-
35
- if (!isObj(desc))
36
- throw new TypeError("First parameter (desc) must be a descriptor template object");
37
-
38
- if (!Object.isExtensible(desc))
39
- throw new RangeError("First parameter (desc) must not be locked, sealed, frozen, etc.");
40
-
41
- const accessorSafe = (typeof opts.accessorSafe === B)
42
- ? opts.accessorSafe
43
- : (desc.writable === undefined);
44
-
45
- DESC_ID.tag(desc);
46
-
47
- // Add a function or other property.
48
- const add = def(desc);
49
-
50
- // Add a getter.
51
- function accessor(name, getter, setter)
52
- {
53
- const adef = {configurable: true};
54
- if (typeof getter === F) adef.get = getter;
55
- if (typeof setter === F) adef.set = setter;
56
- def(desc, name, adef);
57
- }
58
-
59
- add('accessorSafe', accessorSafe);
60
-
61
- add('whenDone', function(func)
62
- {
63
- if (typeof func === F)
64
- {
65
- add('done', func);
66
- }
67
- return this;
68
- });
69
-
70
- if (typeof opts.done === F)
71
- {
72
- desc.whenDone(opts.done);
73
- }
74
-
75
- add('setValue', function (val, noClean)
76
- {
77
- if (this.get !== undefined || this.set !== undefined)
78
- {
79
- console.error("Accessor properties already defined", this);
80
- }
81
- else
82
- {
83
- this.value = val;
84
- }
85
-
86
- return this;
87
- });
88
-
89
- if (accessorSafe)
90
- {
91
- function validate ()
92
- {
93
- if (this.value !== undefined)
94
- {
95
- console.error("Data 'value' property defined", this);
96
- return false;
97
- }
98
-
99
- for (const arg of arguments)
100
- { // All accessor arguments must be functions.
101
- if (typeof arg !== F) throw new TypeError("Parameter must be a function");
102
- }
103
-
104
- return true;
105
- }
106
-
107
- add('setGetter', function(func)
108
- {
109
- if (validate.call(this, func))
110
- this.get = func;
111
- return this;
112
- });
113
-
114
- add('setSetter', function(func)
115
- {
116
- if (validate.call(this, func))
117
- this.set = func;
118
- return this;
119
- });
120
-
121
- add('setAccessor', function(getter, setter)
122
- {
123
- if (validate.call(this, getter, setter))
124
- {
125
- this.get = getter;
126
- this.set = setter;
127
- }
128
- return this;
129
- });
130
-
131
- } // accessorSafe
132
-
133
- if (opts.add)
134
- {
135
- const addTypes
136
- = (typeof opts.add === N)
137
- ? opts.add
138
- : DESC_ADD.SET;
139
-
140
- function addBool(propname)
141
- {
142
- const setBool = function()
143
- {
144
- this[propname] = true;
145
- return this;
146
- }
147
-
148
- if (addTypes & DESC_ADD.ONE)
149
- {
150
- const aname = propname[0];
151
- accessor(aname, setBool);
152
- }
153
- if (addTypes & DESC_ADD.SHORT)
154
- {
155
- const aname = propname.substring(0,4);
156
- accessor(aname, setBool);
157
- }
158
- if (addTypes & DESC_ADD.SET)
159
- {
160
- const aname = 'set'+ucfirst(propname);
161
- accessor(aname, setBool);
162
- }
163
- }
164
-
165
- addBool('configurable');
166
- addBool('enumerable');
167
- addBool('writable');
168
-
169
- } // addBools
170
-
171
- // Is the descriptor ready to be used?
172
- accessor('isReady', function()
173
- {
174
- return doesDescriptor(this);
175
- });
176
-
177
- return desc;
178
- } // descriptor()
179
-
180
- exports.descriptor = descriptor;
181
-
182
- /**
183
- * Get a Descriptor object.
184
- * @param {object} desc - Either a Descriptor, or a descriptor template.
185
- * @returns {object}
186
- * @alias module:@lumjs/compat/v4/descriptors.getDescriptor
187
- */
188
- function getDescriptor(desc)
189
- {
190
- return DESC_ID.is(desc) ? desc : descriptor(desc);
191
- }
192
-
193
- exports.getDescriptor = getDescriptor;
194
-
195
- /**
196
- * A factory for building magic Descriptor objects.
197
- * @alias module:@lumjs/compat/v4/descriptors.DESC
198
- */
199
- const DESC =
200
- {
201
- get RO() { return descriptor(true) },
202
- get CONF() { return descriptor(true).c },
203
- get ENUM() { return descriptor(true).e },
204
- get WRITE() { return descriptor(false).w },
205
- get RW() { return descriptor(false).c.w },
206
- get DEF() { return descriptor(true).c.e },
207
- get OPEN() { return descriptor(false).c.e.w },
208
- }
209
-
210
- def(DESC)
211
- ('make', descriptor)
212
- ('is', DESC_ID.isFunction())
213
- ('get', getDescriptor)
214
- ('does', doesDescriptor)
215
- ('ADD', DESC_ADD);
216
-
217
- exports.DESC = DESC;
package/lib/v4/index.js DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * Lum.js v4 compatibility set.
3
- *
4
- * Now uses lazy-loading for all properties.
5
- *
6
- * @module @lumjs/compat/v4
7
- */
8
-
9
- const {lazy} = require('@lumjs/core/types');
10
-
11
- const E = lazy.def.e;
12
-
13
- /**
14
- * @name module:@lumjs/compat/v4.descriptors
15
- * @see module:@lumjs/compat/v4/descriptors
16
- */
17
- lazy(exports, 'descriptors', () => require('./descriptors'), E);
18
-
19
- /**
20
- * @name module:@lumjs/compat/v4.DESC
21
- * @see module:@lumjs/compat/v4/descriptors.DESC
22
- */
23
- lazy(exports, 'DESC', () => exports.descriptors.DESC, E);
24
-
25
- /**
26
- * @name module:@lumjs/compat/v4.prop
27
- * @see module:@lumjs/compat/v4/prop
28
- */
29
- lazy(exports, 'prop', () => require('./prop'), E);
30
-
31
- /**
32
- * @name module:@lumjs/compat/v4.deprecated
33
- * @see module:@lumjs/compat/v4/deprecated
34
- */
35
- lazy(exports, 'deprecated', () => require('./deprecated'), E);
36
-
37
- /**
38
- * @name module:@lumjs/compat/v4.LoadTracker
39
- * @see module:@lumjs/compat/v4/loadtracker
40
- */
41
- lazy(exports, 'LoadTracker', () => require('./loadtracker'), E);
42
-
43
- /**
44
- * @name module:@lumjs/compat/v4.Promise
45
- * @see module:@lumjs/compat/v4/promise
46
- */
47
- lazy(exports, 'Promise', () => require('./promise'), E);
48
-
49
- /**
50
- * @name module:@lumjs/compat/v4.obj
51
- * @see module:@lumjs/compat/v4/object-helpers
52
- */
53
- lazy(exports, 'obj', () => require('./object-helpers'), E);