@lumjs/core 1.0.0-beta.2 → 1.0.0-beta.4
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 +7 -2
- package/TODO.md +18 -5
- package/docs/changelogs/1.0-beta.md +69 -0
- package/jsdoc.json +33 -0
- package/lib/arrays.js +66 -0
- package/lib/context.js +4 -2
- package/lib/enum.js +6 -3
- package/lib/index.js +10 -20
- package/lib/lazy.js +29 -33
- package/lib/meta.js +29 -2
- package/lib/modules.js +16 -4
- package/lib/obj/clone.js +148 -131
- package/lib/obj/index.js +8 -3
- package/lib/obj/lock.js +3 -4
- package/lib/observable.js +3 -2
- package/lib/types/basics.js +142 -0
- package/lib/types/def.js +180 -0
- package/lib/types/index.js +38 -0
- package/lib/types/isa.js +193 -0
- package/lib/types/js.js +12 -0
- package/lib/types/needs.js +112 -0
- package/lib/types/root.js +94 -0
- package/lib/types/typelist.js +104 -0
- package/package.json +6 -1
- package/test/arrays.js +19 -0
- package/test/meta.js +17 -0
- package/test/types.js +5 -11
- package/CHANGELOG.md +0 -25
- package/lib/descriptors.js +0 -243
- package/lib/prop.js +0 -170
- package/lib/types.js +0 -545
package/README.md
CHANGED
|
@@ -6,9 +6,14 @@ and work in CommonJS/Node.js and modern browsers without any modifications.
|
|
|
6
6
|
|
|
7
7
|
Used by all the rest of my *Lum.js* libraries.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Documentation
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
I am working on fleshing out the documentation in `jsdoc3` format.
|
|
12
|
+
You can compile the unfinished version using `jsdoc -c ./jsdoc.json`
|
|
13
|
+
which will put the generated docs into the `./docs/api` folder.
|
|
14
|
+
|
|
15
|
+
### [Changelog](CHANGELOG.md)
|
|
16
|
+
### [TODO](TODO.md)
|
|
12
17
|
|
|
13
18
|
## Official URLs
|
|
14
19
|
|
package/TODO.md
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
|
+
## 1.0.0 Release
|
|
4
|
+
|
|
3
5
|
- Proper tests using new [@lumjs/tests](https://github.com/supernovus/lum.tests.js) library.
|
|
4
|
-
- [
|
|
5
|
-
- [x] `types`
|
|
6
|
+
- [x] `types/js`
|
|
7
|
+
- [x] `types/basics`
|
|
8
|
+
- [x] `types/root`
|
|
9
|
+
- [ ] `types/isa`
|
|
10
|
+
- [ ] `types/needs`
|
|
11
|
+
- [ ] `types/def`
|
|
12
|
+
- [ ] `types/typelist`
|
|
13
|
+
- [ ] `types/index`
|
|
14
|
+
- [x] `arrays`
|
|
6
15
|
- [ ] `context`
|
|
7
16
|
- [ ] `strings`
|
|
8
17
|
- [ ] `flags`
|
|
9
|
-
- [ ] `descriptors`
|
|
10
18
|
- [ ] `obj/copyall`
|
|
11
19
|
- [ ] `obj/copyprops`
|
|
12
20
|
- [ ] `obj/clone`
|
|
13
21
|
- [ ] `obj/lock`
|
|
14
22
|
- [ ] `obj/merge`
|
|
15
23
|
- [ ] `obj/ns`
|
|
24
|
+
- [ ] `obj/index`
|
|
16
25
|
- [ ] `opt`
|
|
17
26
|
- [ ] `objectid`
|
|
18
27
|
- [ ] `meta`
|
|
19
28
|
- [ ] `enum`
|
|
20
|
-
- [ ] `prop`
|
|
21
29
|
- [ ] `lazy`
|
|
22
30
|
- [ ] `observable`
|
|
23
|
-
-
|
|
31
|
+
- [ ] `index`
|
|
32
|
+
- Finish the documentation marked as *TODO*.
|
|
33
|
+
- Create new `Changelog-1.x.md` and make it the active `CHANGELOG.md` link.
|
|
34
|
+
|
|
35
|
+
## Future
|
|
24
36
|
|
|
37
|
+
- Who knows, further work on this can wait until the rest of the libraries are finished.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.0.0-beta.4] - 2022-07-15
|
|
10
|
+
### Added
|
|
11
|
+
- Two new clone modes:
|
|
12
|
+
- `CLONE.DEEP` : A recursive clone of enumerable properties.
|
|
13
|
+
- `CLONE.ENTIRE` : A recursive clone of all properties.
|
|
14
|
+
- Added `types.isa()` which wraps `isType()` and `isInstance()` along with some added magic that makes it a generic *smart match* function.
|
|
15
|
+
- Added `types.needs()` which does for `isa()` what `needOb()` and `needType()` do for `isObj()` and `isType()` respectively.
|
|
16
|
+
- A `jsdoc.json` based on the one from the old [Lum.js](https://github.com/supernovus/lum.js) codebase.
|
|
17
|
+
- A temporary `test` script to the `package.json` which uses the `prove` utility from Perl 5.
|
|
18
|
+
### Removed
|
|
19
|
+
- Removed `descriptors` and `prop()` modules.
|
|
20
|
+
- They'll be in a new `@lumjs/compat` library for legacy compatibility code.
|
|
21
|
+
### Changed
|
|
22
|
+
- Updated this *changelog* which I forgot to do last time.
|
|
23
|
+
- Fixed some formatting in the changelog.
|
|
24
|
+
- Split `types` into separated files.
|
|
25
|
+
- Moved/renamed a few functions:
|
|
26
|
+
- `types.containsAny()` → `arrays.containsAny()`
|
|
27
|
+
- `types.containsAll()` → `arrays.containsAll()`
|
|
28
|
+
- `types.removeFromArray()` → `arrays.removeItems()`
|
|
29
|
+
- `types.NYI()` → `meta.NYI()`
|
|
30
|
+
- Updated tests to reflect the moved/renamed functions.
|
|
31
|
+
- Enhanced `def()` function as it has fully replaced `prop()` now.
|
|
32
|
+
- Has a new `opts` parameter which can be used for a few different options.
|
|
33
|
+
- Allows assigning a *getter* and *setter* without using a descriptor.
|
|
34
|
+
- Updated `lazy()` to be an extension of `def()` instead of `prop()`.
|
|
35
|
+
- Updated `obj/clone` and `obj/lock` to remove use of `descriptors` magic.
|
|
36
|
+
- Updated `CLONE` mode documentation to use a table format.
|
|
37
|
+
- A few minor tweaks and cleanups related to the rest of the above changes.
|
|
38
|
+
- Updated [TODO.md](TODO.md) with the plans for the final `1.0.0` release.
|
|
39
|
+
|
|
40
|
+
## [1.0.0-beta.3] - 2022-07-11
|
|
41
|
+
### Added
|
|
42
|
+
- `core.context.hasRequire`: A boolean value indicating `require()`
|
|
43
|
+
- `core.context.isNode`: A boolean value guessing the environment is node.js
|
|
44
|
+
### Changed
|
|
45
|
+
- `core.context.CJS`: Made slightly tighter in definition.
|
|
46
|
+
- `core.modules.name()`: Made it more flexible.
|
|
47
|
+
- `core.obj`: Changed namespace exports.
|
|
48
|
+
### Fixed
|
|
49
|
+
- `core.modules.name()`: Actually return the value!
|
|
50
|
+
|
|
51
|
+
## [1.0.0-beta.2] - 2022-07-08
|
|
52
|
+
### Changed
|
|
53
|
+
- Renamed `src` to `lib` as we're not compiling/transpiling this code.
|
|
54
|
+
- Moved `index.js` into `lib` with the rest of the module files.
|
|
55
|
+
- Added `modules.js` with a method for generating a name/id for a module.
|
|
56
|
+
- Added `isSearch()`,`isReplacement()`, and `replaceItems()` to `strings.js`.
|
|
57
|
+
|
|
58
|
+
## [1.0.0-beta.1] - 2022-07-07
|
|
59
|
+
### Added
|
|
60
|
+
- Initial release.
|
|
61
|
+
- Pulled a bunch of the core libraries from the old Lum.js project.
|
|
62
|
+
- Refactored and reorganized the libraries a lot.
|
|
63
|
+
|
|
64
|
+
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.4...HEAD
|
|
65
|
+
[1.0.0-beta.4]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.3...v1.0.0-beta.4
|
|
66
|
+
[1.0.0-beta.3]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.2...v1.0.0-beta.3
|
|
67
|
+
[1.0.0-beta.2]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.1...v1.0.0-beta.2
|
|
68
|
+
[1.0.0-beta.1]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0-beta.1
|
|
69
|
+
|
package/jsdoc.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tags":
|
|
3
|
+
{
|
|
4
|
+
"allowUnknownTags": true
|
|
5
|
+
},
|
|
6
|
+
"source":
|
|
7
|
+
{
|
|
8
|
+
"include": ["./lib"]
|
|
9
|
+
},
|
|
10
|
+
"opts":
|
|
11
|
+
{
|
|
12
|
+
"destination": "./docs/api",
|
|
13
|
+
"recurse": true
|
|
14
|
+
},
|
|
15
|
+
"plugins":
|
|
16
|
+
[
|
|
17
|
+
"plugins/markdown"
|
|
18
|
+
],
|
|
19
|
+
"templates":
|
|
20
|
+
{
|
|
21
|
+
"cleverLinks": false,
|
|
22
|
+
"monospaceLinks": false,
|
|
23
|
+
"default":
|
|
24
|
+
{
|
|
25
|
+
"outputSourceFiles": true
|
|
26
|
+
},
|
|
27
|
+
"path": "ink-docstrap",
|
|
28
|
+
"theme": "cerulean",
|
|
29
|
+
"navType": "vertical",
|
|
30
|
+
"linenums": true,
|
|
31
|
+
"dateFormat": "YYYY-MM-DD, hh:mm:ss"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/lib/arrays.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See if an array contains *any* of the specified items.
|
|
3
|
+
* @param {Array} array
|
|
4
|
+
* @param {...any} items
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
*/
|
|
7
|
+
function containsAny(array, ...items)
|
|
8
|
+
{
|
|
9
|
+
for (const item of items)
|
|
10
|
+
{
|
|
11
|
+
if (array.includes(item))
|
|
12
|
+
{ // Item found.
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// No items found.
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.containsAny = containsAny;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* See if an array contains *all* of the specified items.
|
|
25
|
+
* @param {Array} array
|
|
26
|
+
* @param {...any} items
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
function containsAll(array, ...items)
|
|
30
|
+
{
|
|
31
|
+
for (const item of items)
|
|
32
|
+
{
|
|
33
|
+
if (!array.includes(item))
|
|
34
|
+
{ // An item was missing.
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// All items found.
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.containsAll = containsAll;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Remove items from an array.
|
|
47
|
+
* @param {Array} array
|
|
48
|
+
* @param {...any} items
|
|
49
|
+
* @returns {number} Number of items removed.
|
|
50
|
+
*/
|
|
51
|
+
function removeItems(array, ...items)
|
|
52
|
+
{
|
|
53
|
+
let removed = 0;
|
|
54
|
+
for (const item of items)
|
|
55
|
+
{
|
|
56
|
+
const index = array.indexOf(item);
|
|
57
|
+
if (index !== -1)
|
|
58
|
+
{
|
|
59
|
+
array.splice(index, 1);
|
|
60
|
+
removed++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return removed;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.removeItems = removeItems;
|
package/lib/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
const {root,B,F,U,O,isObj,def} = require('./types');
|
|
2
|
+
const {root,B,F,U,O,isObj,isComplex,def} = require('./types');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Context object.
|
|
@@ -16,9 +16,11 @@ const rootHas = what => typeof root[what] !== U;
|
|
|
16
16
|
const cd = def(ctx, true);
|
|
17
17
|
|
|
18
18
|
cd('AMD', typeof define === F && define.amd)
|
|
19
|
+
('hasRequire', typeof require === F)
|
|
19
20
|
('hasExports', typeof exports !== U)
|
|
20
21
|
('hasModule', typeof module === O && module !== null)
|
|
21
|
-
('CJS', ctx.hasModule &&
|
|
22
|
+
('CJS', ctx.hasRequire && ctx.hasModule && isComplex(module.exports))
|
|
23
|
+
('isNode', ctx.CJS && ctx.hasExports)
|
|
22
24
|
('isWindow', !ctx.CJS && rootHas('window'))
|
|
23
25
|
('isWorker', !ctx.CJS && rootHas('WorkerGlobalScope'))
|
|
24
26
|
('isServiceWorker', !ctx.CJS && rootHas('ServiceWorkerGlobalScope'))
|
package/lib/enum.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const {S,def,notNil,isObj} =
|
|
1
|
+
const types = require('./types');
|
|
2
|
+
const {S,def,notNil,isObj,needObj} = types;
|
|
3
3
|
const {InternalObjectId} = require('./objectid');
|
|
4
4
|
|
|
5
5
|
const ENUM_ID = new InternalObjectId({name: '$Enum'});
|
|
@@ -117,7 +117,10 @@ function Enum (spec, opts={})
|
|
|
117
117
|
|
|
118
118
|
} // Enum
|
|
119
119
|
|
|
120
|
-
// Add an
|
|
120
|
+
// Add an is() method.
|
|
121
121
|
def(Enum, 'is', ENUM_ID.isFunction());
|
|
122
122
|
|
|
123
|
+
// And an isEnum() method to the `types` namespace.
|
|
124
|
+
def(types, 'isEnum', Enum.is);
|
|
125
|
+
|
|
123
126
|
module.exports = Enum;
|
package/lib/index.js
CHANGED
|
@@ -3,46 +3,36 @@
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Constants and functions for basic type checking.
|
|
6
|
-
* @namespace types
|
|
7
6
|
*/
|
|
8
7
|
const types = require('./types');
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Array utility functions.
|
|
11
|
+
*/
|
|
12
|
+
const arrays = require('./arrays');
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Information about the JS context we're running in.
|
|
13
|
-
* @namespace context
|
|
14
16
|
*/
|
|
15
17
|
const context = require('./context');
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Functions for working with strings and locales.
|
|
19
|
-
* @namespace strings
|
|
20
21
|
*/
|
|
21
22
|
const strings = require('./strings');
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Functions for working with binary flags.
|
|
25
|
-
* @namespace flags
|
|
26
26
|
*/
|
|
27
27
|
const flags = require('./flags');
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Functions and Enums for working with Descriptors.
|
|
31
|
-
* @namespace descriptors
|
|
32
|
-
*/
|
|
33
|
-
const descriptors = require('./descriptors');
|
|
34
|
-
// The *primary* export from descriptors is DESC.
|
|
35
|
-
const DESC = descriptors.DESC;
|
|
36
|
-
|
|
37
29
|
/**
|
|
38
30
|
* Functions for manipulating objects.
|
|
39
|
-
* @namespace obj
|
|
40
31
|
*/
|
|
41
32
|
const obj = require('./obj');
|
|
42
33
|
|
|
43
34
|
/**
|
|
44
35
|
* Functions for getting values and properties with fallback defaults.
|
|
45
|
-
* @namespace opt
|
|
46
36
|
*/
|
|
47
37
|
const opt = require('./opt');
|
|
48
38
|
|
|
@@ -53,17 +43,17 @@ const modules = require('./modules');
|
|
|
53
43
|
|
|
54
44
|
// A few modules that we're going to expand into the main exports.
|
|
55
45
|
const {randomNumber, InternalObjectId} = require('./objectid');
|
|
56
|
-
const {stacktrace,AbstractClass,Functions} = require('./meta');
|
|
46
|
+
const {stacktrace,AbstractClass,Functions,NYI} = require('./meta');
|
|
57
47
|
|
|
58
48
|
// And finally some standalone functions.
|
|
59
49
|
const Enum = require('./enum');
|
|
60
|
-
const prop = require('./prop');
|
|
61
50
|
const lazy = require('./lazy');
|
|
62
51
|
const observable = require('./observable');
|
|
52
|
+
const def = types.def;
|
|
63
53
|
|
|
64
54
|
module.exports =
|
|
65
55
|
{
|
|
66
|
-
types, context, strings, flags,
|
|
67
|
-
randomNumber, InternalObjectId, Enum,
|
|
68
|
-
stacktrace, AbstractClass, Functions,
|
|
56
|
+
types, arrays, context, strings, flags, obj, opt, modules,
|
|
57
|
+
def, randomNumber, InternalObjectId, Enum, lazy, observable,
|
|
58
|
+
stacktrace, AbstractClass, Functions, NYI,
|
|
69
59
|
}
|
package/lib/lazy.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
|
|
2
|
-
const {S,F,
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const {S,F,TYPES:{COMPLEX},needType,needObj,def} = require('./types');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @callback InitFunc
|
|
6
|
+
* @param {string} name - The `name` parameter passed to `lazy()`
|
|
7
|
+
* @this {object} - The `obj` parameter passed to `lazy()`
|
|
8
|
+
*/
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Build a lazy initializer property.
|
|
8
12
|
*
|
|
9
13
|
* Basically the first time the property is accessed it's built.
|
|
10
14
|
* Subsequent accesses will use the already built property.
|
|
11
|
-
* This is an extension of the {@link
|
|
12
|
-
* alias called `
|
|
15
|
+
* This is an extension of the {@link def} method, and indeed an
|
|
16
|
+
* alias called `def.lazy()` is also available.
|
|
13
17
|
*
|
|
14
18
|
* @param {object} obj - The object to add the property to.
|
|
15
19
|
* @param {string} name - The name of the property to add.
|
|
16
|
-
* @param {
|
|
17
|
-
*
|
|
18
|
-
* This function will have `this` set to the `obj` parameter.
|
|
19
|
-
* It will also be passed `name` as the sole parameter.
|
|
20
|
-
*
|
|
21
|
-
* @param {mixed} [onset] How to handle assignment.
|
|
20
|
+
* @param {InitFunc} initfunc - The function to initialize the property.
|
|
21
|
+
* @param {*} [onset] How to handle assignment.
|
|
22
22
|
*
|
|
23
23
|
* If this is `true` then the new value will be assigned directly,
|
|
24
24
|
* skipping the initialization process entirely.
|
|
@@ -36,29 +36,25 @@ const {DESC} = require('./descriptors');
|
|
|
36
36
|
*
|
|
37
37
|
* If this is anything else, assignment will do nothing at all.
|
|
38
38
|
*
|
|
39
|
-
* @param {object} [desc=
|
|
39
|
+
* @param {object} [desc={}] Descriptor rules for the property.
|
|
40
|
+
* We only support two descriptor rules with this function, and
|
|
41
|
+
* their default values are the same as the `def()` function.
|
|
42
|
+
* - `configurable` → `true`
|
|
43
|
+
* - `enumerable` → `false`
|
|
44
|
+
* Any other descriptor properties are invalid here.
|
|
40
45
|
*
|
|
41
46
|
* @return {object} The object we defined the property on.
|
|
42
47
|
*/
|
|
43
|
-
function lazy(obj, name, initfunc, onset, desc=
|
|
48
|
+
function lazy(obj, name, initfunc, onset, desc={})
|
|
44
49
|
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (typeof name !== S)
|
|
50
|
-
{
|
|
51
|
-
throw new TypeError("name parameter was not a string");
|
|
52
|
-
}
|
|
53
|
-
if (typeof initfunc !== F)
|
|
54
|
-
{
|
|
55
|
-
throw new TypeError("initfunc parameter was not a function");
|
|
56
|
-
}
|
|
50
|
+
needType(COMPLEX, obj, 'obj must be an object');
|
|
51
|
+
needType(S, name, 'name must be a string');
|
|
52
|
+
needType(F, initfunc, 'initfunc must be a function');
|
|
53
|
+
needObj(desc, 'desc parameter was not an object');
|
|
57
54
|
|
|
58
55
|
let value;
|
|
59
|
-
let setter = null;
|
|
60
56
|
|
|
61
|
-
function
|
|
57
|
+
desc.get = function()
|
|
62
58
|
{
|
|
63
59
|
if (value === undefined)
|
|
64
60
|
{
|
|
@@ -69,23 +65,23 @@ function lazy(obj, name, initfunc, onset, desc=DESC.CONF)
|
|
|
69
65
|
|
|
70
66
|
if (onset === true)
|
|
71
67
|
{ // Allow direct assignment.
|
|
72
|
-
|
|
68
|
+
desc.set = function(newval)
|
|
73
69
|
{
|
|
74
70
|
value = newval;
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
else if (onset === false)
|
|
78
74
|
{ // Throw an error on assignment.
|
|
79
|
-
|
|
75
|
+
desc.set = function()
|
|
80
76
|
{
|
|
81
77
|
throw new ReferenceError("The "+name+" property is read-only");
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
else if (typeof onset === F)
|
|
85
81
|
{ // A proxy method for assignment.
|
|
86
|
-
|
|
82
|
+
desc.set = function(newval)
|
|
87
83
|
{
|
|
88
|
-
const setval = onset.call(this, newval);
|
|
84
|
+
const setval = onset.call(this, newval, value);
|
|
89
85
|
if (setval !== undefined)
|
|
90
86
|
{
|
|
91
87
|
value = setval;
|
|
@@ -93,10 +89,10 @@ function lazy(obj, name, initfunc, onset, desc=DESC.CONF)
|
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
91
|
|
|
96
|
-
|
|
92
|
+
def(obj, name, desc);
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
// Gotta be one of the greatest lines...
|
|
100
|
-
|
|
96
|
+
def(def, 'lazy', lazy);
|
|
101
97
|
|
|
102
98
|
module.exports = lazy;
|
package/lib/meta.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Get a stacktrace. Differs from browser to browser.
|
|
3
|
+
*
|
|
4
|
+
* Uses the `stack` property of an `Error` object as the source.
|
|
5
|
+
* This is a super simplistic hack. For a more complete solution, try
|
|
6
|
+
* the `stacktrace-js` library, which will be used in the new `@lumjs/debug`
|
|
7
|
+
* library as a dependency.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} [msg] - A message for the Error object.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string[]} An array of stack strings.
|
|
5
12
|
*/
|
|
6
13
|
function stacktrace(msg)
|
|
7
14
|
{
|
|
@@ -59,3 +66,23 @@ const Functions =
|
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
exports.Functions = Functions;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A placeholder function for when something is not implemented.
|
|
72
|
+
*
|
|
73
|
+
* @param {boolean} [fatal=true] If `true` throw Error.
|
|
74
|
+
* If `false` use `console.error()` instead.
|
|
75
|
+
* @param {string} [prefix=''] A prefix for the error message.
|
|
76
|
+
*
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
79
|
+
function NYI(fatal=true, prefix='')
|
|
80
|
+
{
|
|
81
|
+
const msg = prefix+"« NOT YET IMPLEMENTED »";
|
|
82
|
+
if (fatal)
|
|
83
|
+
throw new Error(msg);
|
|
84
|
+
else
|
|
85
|
+
console.error(msg);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.NYI = NYI;
|
package/lib/modules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Stuff specific to mostly Node.js, but browser-shims may wrap this.
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const {S,
|
|
4
|
+
const {S,isObj} = require('./types');
|
|
5
5
|
const replace = require('./strings').replaceItems;
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -11,10 +11,21 @@ const replace = require('./strings').replaceItems;
|
|
|
11
11
|
*/
|
|
12
12
|
function name(module, opts={})
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
let filename;
|
|
15
|
+
|
|
16
|
+
if (typeof module === S)
|
|
17
|
+
{ // Going to assume a string is the filename.
|
|
18
|
+
filename = module;
|
|
19
|
+
}
|
|
20
|
+
else if (isObj(module) && typeof module.filename === S)
|
|
21
|
+
{ // It's a CommonJS module context object.
|
|
22
|
+
filename = module.filename;
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
{ // Sorry, we don't support that.
|
|
26
|
+
throw new TypeError("Unsupported module parameter");
|
|
27
|
+
}
|
|
16
28
|
|
|
17
|
-
let filename = module.filename;
|
|
18
29
|
const ext = path.extname(filename);
|
|
19
30
|
|
|
20
31
|
let useFallback = true;
|
|
@@ -72,6 +83,7 @@ function name(module, opts={})
|
|
|
72
83
|
.replace(RegExp(ext+'$'), '');
|
|
73
84
|
}
|
|
74
85
|
|
|
86
|
+
return filename;
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
exports.name = name;
|