@lumjs/core 1.0.0-beta.2 → 1.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.
- package/README.md +11 -2
- package/TODO.md +12 -5
- package/docs/changelogs/1.0-beta.md +99 -0
- package/docs/changelogs/1.x.md +17 -0
- package/jsdoc.json +33 -0
- package/lib/arrays.js +78 -0
- package/lib/context.js +49 -10
- package/lib/enum.js +30 -13
- package/lib/flags.js +6 -0
- package/lib/index.js +87 -25
- package/lib/lazy.js +33 -35
- package/lib/meta.js +38 -1
- package/lib/modules.js +43 -7
- package/lib/obj/clone.js +158 -139
- package/lib/obj/copyall.js +3 -0
- package/lib/obj/copyprops.js +1 -0
- package/lib/obj/index.js +12 -7
- package/lib/obj/lock.js +16 -13
- package/lib/obj/merge.js +2 -0
- package/lib/obj/ns.js +45 -8
- package/lib/objectid.js +2 -3
- package/lib/observable.js +23 -8
- package/lib/opt.js +6 -1
- package/lib/strings.js +43 -4
- package/lib/types/basics.js +154 -0
- package/lib/types/def.js +183 -0
- package/lib/types/index.js +55 -0
- package/lib/types/isa.js +186 -0
- package/lib/types/js.js +12 -0
- package/lib/types/needs.js +117 -0
- package/lib/types/root.js +92 -0
- package/lib/types/stringify.js +98 -0
- package/lib/types/typelist.js +168 -0
- package/package.json +25 -2
- package/test/arrays.js +19 -0
- package/test/meta.js +17 -0
- package/test/types.js +105 -22
- 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,18 @@ 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
|
+
### [API Docs](https://supernovus.github.io/docs/js/@lumjs/core/)
|
|
12
|
+
|
|
13
|
+
The documentation is written in [JSDoc 3](https://jsdoc.app/) format.
|
|
14
|
+
|
|
15
|
+
You can compile the documentation using `npm run build-docs`
|
|
16
|
+
which will put the generated docs into the `./docs/api` folder.
|
|
17
|
+
|
|
18
|
+
### [Changelog](./docs/changelogs/1.x.md)
|
|
19
|
+
### [TODO](TODO.md)
|
|
20
|
+
### [Homepage](https://supernovus.github.io/)
|
|
12
21
|
|
|
13
22
|
## Official URLs
|
|
14
23
|
|
package/TODO.md
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
3
|
- Proper tests using new [@lumjs/tests](https://github.com/supernovus/lum.tests.js) library.
|
|
4
|
-
- [
|
|
5
|
-
- [x] `types`
|
|
4
|
+
- [x] `types/js`
|
|
5
|
+
- [x] `types/basics`
|
|
6
|
+
- [x] `types/root`
|
|
7
|
+
- [x] `types/isa`
|
|
8
|
+
- [x] `types/needs`
|
|
9
|
+
- [x] `types/def`
|
|
10
|
+
- [x] `types/typelist`
|
|
11
|
+
- [ ] `types/stringify`
|
|
12
|
+
- [x] `types/index`
|
|
13
|
+
- [x] `arrays`
|
|
6
14
|
- [ ] `context`
|
|
7
15
|
- [ ] `strings`
|
|
8
16
|
- [ ] `flags`
|
|
9
|
-
- [ ] `descriptors`
|
|
10
17
|
- [ ] `obj/copyall`
|
|
11
18
|
- [ ] `obj/copyprops`
|
|
12
19
|
- [ ] `obj/clone`
|
|
13
20
|
- [ ] `obj/lock`
|
|
14
21
|
- [ ] `obj/merge`
|
|
15
22
|
- [ ] `obj/ns`
|
|
23
|
+
- [ ] `obj/index`
|
|
16
24
|
- [ ] `opt`
|
|
17
25
|
- [ ] `objectid`
|
|
18
26
|
- [ ] `meta`
|
|
19
27
|
- [ ] `enum`
|
|
20
|
-
- [ ] `prop`
|
|
21
28
|
- [ ] `lazy`
|
|
22
29
|
- [ ] `observable`
|
|
23
|
-
-
|
|
30
|
+
- [ ] `index`
|
|
24
31
|
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
## Note
|
|
8
|
+
|
|
9
|
+
This is the *Changelog* for the `1.0.0-beta.x` releases.
|
|
10
|
+
See [1.x.md](1.x.md) for the stable `1.x` *Changelog*.
|
|
11
|
+
|
|
12
|
+
## [1.0.0-beta.6]
|
|
13
|
+
- This is the **final** beta version.
|
|
14
|
+
- Version `1.0.0` will be this but with the docs updated a bit.
|
|
15
|
+
### Added
|
|
16
|
+
- More tests for the `types` module.
|
|
17
|
+
- Changelog file for the upcoming `1.x` *stable* releases.
|
|
18
|
+
### Changed
|
|
19
|
+
- Removed some convoluted options from `def()`.
|
|
20
|
+
- Reworked `types.stringify()` to handle recursive mode better.
|
|
21
|
+
- Added `Error` stringification to `types.stringify()`
|
|
22
|
+
|
|
23
|
+
## [1.0.0-beta.5] - 2022-07-18
|
|
24
|
+
### Added
|
|
25
|
+
- A new `types.stringify()` method.
|
|
26
|
+
- Shortcut `string` options for the `types.def()` method.
|
|
27
|
+
- A `build-docs` script in `package.json`.
|
|
28
|
+
### Changed
|
|
29
|
+
- Overhauled all DocBlocks to conform to `JSDoc 3` format.
|
|
30
|
+
- Changed `context.has` to support a magic `Proxy` version.
|
|
31
|
+
- Some tweaks to `Enum` to cleanup some things.
|
|
32
|
+
- Both `Enum` and `observable` use `TYPES.add()` now.
|
|
33
|
+
- In `modules.name()` nixed `opts.noAuto` and added `opts.useAuto` instead.
|
|
34
|
+
- Created explicit `exports` definition in `package.json` with our sub-modules.
|
|
35
|
+
### Fixed
|
|
36
|
+
- Fixed a property definition issue in `obj.SOA()`.
|
|
37
|
+
|
|
38
|
+
## [1.0.0-beta.4] - 2022-07-15
|
|
39
|
+
### Added
|
|
40
|
+
- Two new clone modes:
|
|
41
|
+
- `CLONE.DEEP` : A recursive clone of enumerable properties.
|
|
42
|
+
- `CLONE.ENTIRE` : A recursive clone of all properties.
|
|
43
|
+
- Added `types.isa()` which wraps `isType()` and `isInstance()` along with some added magic that makes it a generic *smart match* function.
|
|
44
|
+
- Added `types.needs()` which does for `isa()` what `needOb()` and `needType()` do for `isObj()` and `isType()` respectively.
|
|
45
|
+
- A `jsdoc.json` based on the one from the old [Lum.js](https://github.com/supernovus/lum.js) codebase.
|
|
46
|
+
- A temporary `test` script to the `package.json` which uses the `prove` utility from Perl 5.
|
|
47
|
+
### Removed
|
|
48
|
+
- Removed `descriptors` and `prop()` modules.
|
|
49
|
+
- They'll be in a new `@lumjs/compat` library for legacy compatibility code.
|
|
50
|
+
### Changed
|
|
51
|
+
- Updated this *changelog* which I forgot to do last time.
|
|
52
|
+
- Fixed some formatting in the changelog.
|
|
53
|
+
- Split `types` into separated files.
|
|
54
|
+
- Moved/renamed a few functions:
|
|
55
|
+
- `types.containsAny()` → `arrays.containsAny()`
|
|
56
|
+
- `types.containsAll()` → `arrays.containsAll()`
|
|
57
|
+
- `types.removeFromArray()` → `arrays.removeItems()`
|
|
58
|
+
- `types.NYI()` → `meta.NYI()`
|
|
59
|
+
- Updated tests to reflect the moved/renamed functions.
|
|
60
|
+
- Enhanced `def()` function as it has fully replaced `prop()` now.
|
|
61
|
+
- Has a new `opts` parameter which can be used for a few different options.
|
|
62
|
+
- Allows assigning a *getter* and *setter* without using a descriptor.
|
|
63
|
+
- Updated `lazy()` to be an extension of `def()` instead of `prop()`.
|
|
64
|
+
- Updated `obj/clone` and `obj/lock` to remove use of `descriptors` magic.
|
|
65
|
+
- Updated `CLONE` mode documentation to use a table format.
|
|
66
|
+
- A few minor tweaks and cleanups related to the rest of the above changes.
|
|
67
|
+
- Updated [../../TODO.md](TODO.md) with the plans for the final `1.0.0` release.
|
|
68
|
+
|
|
69
|
+
## [1.0.0-beta.3] - 2022-07-11
|
|
70
|
+
### Added
|
|
71
|
+
- `core.context.hasRequire`: A boolean value indicating `require()`
|
|
72
|
+
- `core.context.isNode`: A boolean value guessing the environment is node.js
|
|
73
|
+
### Changed
|
|
74
|
+
- `core.context.CJS`: Made slightly tighter in definition.
|
|
75
|
+
- `core.modules.name()`: Made it more flexible.
|
|
76
|
+
- `core.obj`: Changed namespace exports.
|
|
77
|
+
### Fixed
|
|
78
|
+
- `core.modules.name()`: Actually return the value!
|
|
79
|
+
|
|
80
|
+
## [1.0.0-beta.2] - 2022-07-08
|
|
81
|
+
### Changed
|
|
82
|
+
- Renamed `src` to `lib` as we're not compiling/transpiling this code.
|
|
83
|
+
- Moved `index.js` into `lib` with the rest of the module files.
|
|
84
|
+
- Added `modules.js` with a method for generating a name/id for a module.
|
|
85
|
+
- Added `isSearch()`,`isReplacement()`, and `replaceItems()` to `strings.js`.
|
|
86
|
+
|
|
87
|
+
## [1.0.0-beta.1] - 2022-07-07
|
|
88
|
+
### Added
|
|
89
|
+
- Initial release.
|
|
90
|
+
- Pulled a bunch of the core libraries from the old Lum.js project.
|
|
91
|
+
- Refactored and reorganized the libraries a lot.
|
|
92
|
+
|
|
93
|
+
[1.0.0-beta.6]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.5...v1.0.0-beta.6
|
|
94
|
+
[1.0.0-beta.5]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.4...v1.0.0-beta.5
|
|
95
|
+
[1.0.0-beta.4]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.3...v1.0.0-beta.4
|
|
96
|
+
[1.0.0-beta.3]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.2...v1.0.0-beta.3
|
|
97
|
+
[1.0.0-beta.2]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.1...v1.0.0-beta.2
|
|
98
|
+
[1.0.0-beta.1]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0-beta.1
|
|
99
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
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] - 2022-07-27
|
|
10
|
+
### Changed
|
|
11
|
+
- Initial *stable* release.
|
|
12
|
+
- See [1.0-beta.md](1.0-beta.md) for the beta versions of `1.0`
|
|
13
|
+
- See [lum.js](https://github.com/supernovus/lum.js) for the original library this is replacing.
|
|
14
|
+
|
|
15
|
+
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.0.0...HEAD
|
|
16
|
+
[1.0.0]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0
|
|
17
|
+
|
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,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array helper functions.
|
|
3
|
+
* @module module:@lumjs/core/arrays
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* See if an array contains *any* of the specified items.
|
|
8
|
+
* @param {Array} array
|
|
9
|
+
* @param {...any} items
|
|
10
|
+
* @returns {boolean}
|
|
11
|
+
* @alias module:@lumjs/core/arrays.containsAny
|
|
12
|
+
*/
|
|
13
|
+
function containsAny(array, ...items)
|
|
14
|
+
{
|
|
15
|
+
for (const item of items)
|
|
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;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* See if an array contains *all* of the specified items.
|
|
31
|
+
* @param {Array} array
|
|
32
|
+
* @param {...any} items
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
* @alias module:@lumjs/core/arrays.containsAll
|
|
35
|
+
*/
|
|
36
|
+
function containsAll(array, ...items)
|
|
37
|
+
{
|
|
38
|
+
for (const item of items)
|
|
39
|
+
{
|
|
40
|
+
if (!array.includes(item))
|
|
41
|
+
{ // An item was missing.
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// All items found.
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.containsAll = containsAll;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remove items from an array.
|
|
54
|
+
*
|
|
55
|
+
* Passed any number of items, it will see if any of those items are
|
|
56
|
+
* found in the array, and if they are, will remove them from the array.
|
|
57
|
+
*
|
|
58
|
+
* @param {Array} array
|
|
59
|
+
* @param {...any} items
|
|
60
|
+
* @returns {number} Number of items actually removed.
|
|
61
|
+
* @alias module:@lumjs/core/arrays.removeItems
|
|
62
|
+
*/
|
|
63
|
+
function removeItems(array, ...items)
|
|
64
|
+
{
|
|
65
|
+
let removed = 0;
|
|
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;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
exports.removeItems = removeItems;
|
package/lib/context.js
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
|
|
2
|
-
const {root,B,F,U,O,isObj,def} = require('./types');
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
|
-
* Context
|
|
6
|
-
*
|
|
7
|
-
* @namespace Lum.context
|
|
3
|
+
* Context sub-module
|
|
8
4
|
*
|
|
9
|
-
*
|
|
5
|
+
* Used as a static object that has a bunch of properties
|
|
6
|
+
* describing the current JS environment and execution context.
|
|
10
7
|
*
|
|
8
|
+
* @module @lumjs/core/context
|
|
9
|
+
* @property {boolean} AMD - AMD (*RequireJS*) module loading detected.
|
|
10
|
+
* @property {boolean} CJS - CommonJS environment detected.
|
|
11
|
+
* @property {boolean} hasRequire - A global `require()` function was found.
|
|
12
|
+
* @property {boolean} hasExports - A global `exports` object was found.
|
|
13
|
+
* @property {boolean} hasModule - A global `module` object was found.
|
|
14
|
+
* @property {boolean} isNode - Is likely *Node.js*, *Electron*, etc.
|
|
15
|
+
* @property {boolean} isBrowser - A web-browser environment detected.
|
|
16
|
+
* @property {boolean} isWindow - Is a browser `Window` context.
|
|
17
|
+
* @property {boolean} isWorker - Is a browser `Worker` (sub-types below.)
|
|
18
|
+
* @property {boolean} isServiceWorker - Is a `ServiceWorker` context.
|
|
19
|
+
* @property {boolean} isDedicatedWorker - Is a `DedicatedWorker` context.
|
|
20
|
+
* @property {boolean} isSharedWorker - Is a `SharedWorker` context.
|
|
21
|
+
* @property {object} root - See {@link module:@lumjs/core/types.root}
|
|
11
22
|
*/
|
|
12
23
|
|
|
24
|
+
const {root,B,F,U,O,isComplex,def} = require('./types');
|
|
25
|
+
|
|
13
26
|
const ctx = {root};
|
|
14
27
|
|
|
15
28
|
const rootHas = what => typeof root[what] !== U;
|
|
16
29
|
const cd = def(ctx, true);
|
|
17
30
|
|
|
18
31
|
cd('AMD', typeof define === F && define.amd)
|
|
32
|
+
('hasRequire', typeof require === F)
|
|
19
33
|
('hasExports', typeof exports !== U)
|
|
20
34
|
('hasModule', typeof module === O && module !== null)
|
|
21
|
-
('CJS', ctx.hasModule &&
|
|
35
|
+
('CJS', ctx.hasRequire && ctx.hasModule && isComplex(module.exports))
|
|
36
|
+
('isNode', ctx.CJS && ctx.hasExports)
|
|
22
37
|
('isWindow', !ctx.CJS && rootHas('window'))
|
|
23
38
|
('isWorker', !ctx.CJS && rootHas('WorkerGlobalScope'))
|
|
24
39
|
('isServiceWorker', !ctx.CJS && rootHas('ServiceWorkerGlobalScope'))
|
|
@@ -26,8 +41,20 @@ cd('AMD', typeof define === F && define.amd)
|
|
|
26
41
|
('isSharedWorker', !ctx.CJS && rootHas('SharedWorkerGlobalScope'))
|
|
27
42
|
('isBrowser', ctx.isWindow || ctx.isWorker);
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
/**
|
|
45
|
+
* See if a root-level name is defined.
|
|
46
|
+
*
|
|
47
|
+
* This adds a `context.has.{name}` boolean property which caches the
|
|
48
|
+
* result so it can be referred to directly.
|
|
49
|
+
*
|
|
50
|
+
* In any JS environment with the `Proxy` object (which honestly should
|
|
51
|
+
* be all modern ones), you can simple do `context.has.SomeObject` instead
|
|
52
|
+
* of `context.has('SomeObject')` and it will do the Right Thing™.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} ns - The global function/class/object we're looking for.
|
|
55
|
+
* @returns {boolean} If that global name is defined or not.
|
|
56
|
+
* @alias module:@lumjs/core/context.has
|
|
57
|
+
*/
|
|
31
58
|
function hasRoot(ns)
|
|
32
59
|
{
|
|
33
60
|
if (typeof hasRoot[ns] === B) return hasRoot[ns];
|
|
@@ -42,6 +69,18 @@ for (const what of ['Proxy','Promise','Reflect','fetch'])
|
|
|
42
69
|
hasRoot(what);
|
|
43
70
|
}
|
|
44
71
|
|
|
45
|
-
|
|
72
|
+
if (hasRoot.Proxy)
|
|
73
|
+
{ // Make a Proxy-wrapped version of `context.has`
|
|
74
|
+
cd('has', new Proxy(hasRoot,
|
|
75
|
+
{
|
|
76
|
+
get(t, p) { return (typeof t[p] !== U) ? t[p] : t(p) }
|
|
77
|
+
}));
|
|
78
|
+
// And include the unwrapped version for good measure.
|
|
79
|
+
cd('$has', hasRoot);
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{ // No Proxy support, just directly assign `context.has()`
|
|
83
|
+
cd('has', hasRoot);
|
|
84
|
+
}
|
|
46
85
|
|
|
47
86
|
module.exports = ctx;
|
package/lib/enum.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const {S,def,notNil,isObj} = require('./types')
|
|
1
|
+
const {S,def,notNil,isObj,needObj,TYPES} = require('./types');
|
|
3
2
|
const {InternalObjectId} = require('./objectid');
|
|
4
3
|
|
|
4
|
+
// Internal id instances should never be exported.
|
|
5
5
|
const ENUM_ID = new InternalObjectId({name: '$Enum'});
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -12,17 +12,12 @@ const ENUM_ID = new InternalObjectId({name: '$Enum'});
|
|
|
12
12
|
* @param {*} spec - TBD
|
|
13
13
|
* @param {*} [opts] - TBD
|
|
14
14
|
* @returns {object} A magic Enum object.
|
|
15
|
+
* @exports module:@lumjs/core/enum
|
|
15
16
|
*/
|
|
16
17
|
function Enum (spec, opts={})
|
|
17
18
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
throw new TypeError("Enum spec must be an object");
|
|
21
|
-
}
|
|
22
|
-
if (!isObj(opts))
|
|
23
|
-
{
|
|
24
|
-
throw new TypeError("Enum options must be an object")
|
|
25
|
-
}
|
|
19
|
+
needObj(spec, "Enum spec must be an object")
|
|
20
|
+
needObj(opts, "Enum options must be an object")
|
|
26
21
|
|
|
27
22
|
const anEnum = ENUM_ID.tag({});
|
|
28
23
|
|
|
@@ -61,7 +56,7 @@ function Enum (spec, opts={})
|
|
|
61
56
|
const name = spec[i];
|
|
62
57
|
if (typeof name !== S)
|
|
63
58
|
{
|
|
64
|
-
throw new TypeError("Non-string passed in
|
|
59
|
+
throw new TypeError("Non-string passed in Enum object");
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
const val
|
|
@@ -117,7 +112,29 @@ function Enum (spec, opts={})
|
|
|
117
112
|
|
|
118
113
|
} // Enum
|
|
119
114
|
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Is a value an *Enum* magic object?
|
|
117
|
+
* @function module:@lumjs/core/enum.is
|
|
118
|
+
* @param {*} obj - The expected object/function to test.
|
|
119
|
+
* @returns {boolean}
|
|
120
|
+
*/
|
|
121
|
+
const isEnum = ENUM_ID.isFunction()
|
|
122
|
+
def(Enum, 'is', isEnum);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Is a value an *Enum* magic object?
|
|
126
|
+
* @name module:@lumjs/core/types.isEnum
|
|
127
|
+
* @function
|
|
128
|
+
* @param {*} v - The value to test.
|
|
129
|
+
* @returns {boolean}
|
|
130
|
+
* @see module:@lumjs/core/enum.is
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Extension type for {@link module:@lumjs/core/enum} magic objeccts.
|
|
135
|
+
* @memberof module:@lumjs/core/types.TYPES
|
|
136
|
+
* @member {string} ENUM - Is an Enum object?
|
|
137
|
+
*/
|
|
138
|
+
TYPES.add('ENUM', 'enum', isEnum, 'isEnum');
|
|
122
139
|
|
|
123
140
|
module.exports = Enum;
|
package/lib/flags.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions for working with binary flags.
|
|
4
|
+
* @module @lumjs/core/flags
|
|
5
|
+
*/
|
|
2
6
|
const {N} = require('./types');
|
|
3
7
|
|
|
4
8
|
/**
|
|
@@ -7,6 +11,7 @@ const {N} = require('./types');
|
|
|
7
11
|
* @param {number} flag - An integer representing the flag to add or remove.
|
|
8
12
|
* @param {boolean} [value=true] `true` means add, `false` means remove.
|
|
9
13
|
* @returns {number} The `flags` with the `flag` added or removed accordingly.
|
|
14
|
+
* @alias module:@lumjs/core/flags.setFlag
|
|
10
15
|
*/
|
|
11
16
|
function setFlag(flags, flag, value=true)
|
|
12
17
|
{
|
|
@@ -27,6 +32,7 @@ exports.setFlag = setFlag;
|
|
|
27
32
|
* Combine an entire set of flags into a single set.
|
|
28
33
|
* @param {...number} flag - Any number of flags you want to add.
|
|
29
34
|
* @returns {number} All the passed flags combined into one set.
|
|
35
|
+
* @alias module:@lumjs/core/flags.allFlags
|
|
30
36
|
*/
|
|
31
37
|
function allFlags()
|
|
32
38
|
{
|
package/lib/index.js
CHANGED
|
@@ -1,69 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Core Library
|
|
3
|
+
*
|
|
4
|
+
* This is the foundation upon which all the rest of my JS libraries
|
|
5
|
+
* are built. It provides fundamental helper functions and classes.
|
|
6
|
+
*
|
|
7
|
+
* @module @lumjs/core
|
|
8
|
+
*/
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
11
|
* Constants and functions for basic type checking.
|
|
6
|
-
* @
|
|
12
|
+
* @alias module:@lumjs/core.types
|
|
13
|
+
* @see module:@lumjs/core/types
|
|
7
14
|
*/
|
|
8
15
|
const types = require('./types');
|
|
9
|
-
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Array utility functions.
|
|
19
|
+
* @alias module:@lumjs/core.arrays
|
|
20
|
+
* @see module:@lumjs/core/arrays
|
|
21
|
+
*/
|
|
22
|
+
const arrays = require('./arrays');
|
|
10
23
|
|
|
11
24
|
/**
|
|
12
25
|
* Information about the JS context we're running in.
|
|
13
|
-
* @
|
|
26
|
+
* @alias module:@lumjs/core.context
|
|
27
|
+
* @see module:@lumjs/core/context
|
|
14
28
|
*/
|
|
15
29
|
const context = require('./context');
|
|
16
30
|
|
|
17
31
|
/**
|
|
18
32
|
* Functions for working with strings and locales.
|
|
19
|
-
* @
|
|
33
|
+
* @alias module:@lumjs/core.strings
|
|
34
|
+
* @see module:@lumjs/core/strings
|
|
20
35
|
*/
|
|
21
36
|
const strings = require('./strings');
|
|
22
37
|
|
|
23
38
|
/**
|
|
24
39
|
* Functions for working with binary flags.
|
|
25
|
-
* @
|
|
40
|
+
* @alias module:@lumjs/core.flags
|
|
41
|
+
* @see module:@lumjs/core/flags
|
|
26
42
|
*/
|
|
27
43
|
const flags = require('./flags');
|
|
28
44
|
|
|
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
45
|
/**
|
|
38
46
|
* Functions for manipulating objects.
|
|
39
|
-
* @
|
|
47
|
+
* @alis module:@lumjs/core.obj
|
|
48
|
+
* @see module:@lumjs/core/obj
|
|
40
49
|
*/
|
|
41
50
|
const obj = require('./obj');
|
|
42
51
|
|
|
43
52
|
/**
|
|
44
53
|
* Functions for getting values and properties with fallback defaults.
|
|
45
|
-
* @
|
|
54
|
+
* @alias module:@lumjs/core.opt
|
|
55
|
+
* @see module:@lumjs/core/opt
|
|
46
56
|
*/
|
|
47
57
|
const opt = require('./opt');
|
|
48
58
|
|
|
49
59
|
/**
|
|
50
60
|
* Meta functions related to JS modules.
|
|
61
|
+
* @alias module:@lumjs/core.modules
|
|
62
|
+
* @see module:@lumjs/core/modules
|
|
51
63
|
*/
|
|
52
64
|
const modules = require('./modules');
|
|
53
65
|
|
|
54
|
-
//
|
|
66
|
+
// ObjectID stuff is imported directly without registering a sub-module.
|
|
55
67
|
const {randomNumber, InternalObjectId} = require('./objectid');
|
|
56
|
-
const {stacktrace,AbstractClass,Functions} = require('./meta');
|
|
57
68
|
|
|
58
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Get a simplistic debugging stacktrace.
|
|
71
|
+
* @name module:@lumjs/core.stacktrace
|
|
72
|
+
* @function
|
|
73
|
+
* @see module:@lumjs/core/meta.stacktrace
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A simple base class for making *abstract* classes.
|
|
78
|
+
* @name module:@lumjs/core.AbstractClass
|
|
79
|
+
* @see module:@lumjs/core/meta.AbstractClass
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A *factory* for special types of JS `function` constructors.
|
|
84
|
+
* @name module:@lumjs/core.Functions
|
|
85
|
+
* @see module:@lumjs/core/meta.Functions
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Throw an `Error` saying that a feature is not yet implemented.
|
|
90
|
+
* @name module:@lumjs/core.NYI
|
|
91
|
+
* @function
|
|
92
|
+
* @see module:@lumjs/core/meta.NYI
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
// These are exported directly, but a meta sub-module also exists.
|
|
96
|
+
// Unlike most sub-modules there is no `meta` property in the main library.
|
|
97
|
+
const {stacktrace,AbstractClass,Functions,NYI} = require('./meta');
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create a magic *Enum* object.
|
|
101
|
+
* @alias module:@lumjs/core.Enum
|
|
102
|
+
* @function
|
|
103
|
+
* @see module:@lumjs/core/enum
|
|
104
|
+
*/
|
|
59
105
|
const Enum = require('./enum');
|
|
60
|
-
|
|
61
|
-
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Make an object support the *Observable* API.
|
|
109
|
+
* @alias module:@lumjs/core.observable
|
|
110
|
+
* @function
|
|
111
|
+
* @see module:@lumjs/core/observable
|
|
112
|
+
*/
|
|
62
113
|
const observable = require('./observable');
|
|
63
114
|
|
|
115
|
+
// One function exported directly with no sub-module available.
|
|
116
|
+
const lazy = require('./lazy');
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Define properties on an object or function.
|
|
120
|
+
* @alias module:@lumjs/core.def
|
|
121
|
+
* @function
|
|
122
|
+
* @see module:@lumjs/core/types.def
|
|
123
|
+
*/
|
|
124
|
+
const def = types.def;
|
|
125
|
+
|
|
64
126
|
module.exports =
|
|
65
127
|
{
|
|
66
|
-
types, context, strings, flags,
|
|
67
|
-
randomNumber, InternalObjectId, Enum,
|
|
68
|
-
stacktrace, AbstractClass, Functions,
|
|
128
|
+
types, arrays, context, strings, flags, obj, opt, modules,
|
|
129
|
+
def, randomNumber, InternalObjectId, Enum, lazy, observable,
|
|
130
|
+
stacktrace, AbstractClass, Functions, NYI,
|
|
69
131
|
}
|