@lumjs/core 1.0.0-beta.4 → 1.1.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 CHANGED
@@ -8,12 +8,16 @@ Used by all the rest of my *Lum.js* libraries.
8
8
 
9
9
  ## Documentation
10
10
 
11
- I am working on fleshing out the documentation in `jsdoc3` format.
12
- You can compile the unfinished version using `jsdoc -c ./jsdoc.json`
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`
13
16
  which will put the generated docs into the `./docs/api` folder.
14
17
 
15
- ### [Changelog](CHANGELOG.md)
18
+ ### [Changelog](./docs/changelogs/1.x.md)
16
19
  ### [TODO](TODO.md)
20
+ ### [Homepage](https://supernovus.github.io/)
17
21
 
18
22
  ## Official URLs
19
23
 
package/TODO.md CHANGED
@@ -1,16 +1,15 @@
1
1
  # TODO
2
2
 
3
- ## 1.0.0 Release
4
-
5
3
  - Proper tests using new [@lumjs/tests](https://github.com/supernovus/lum.tests.js) library.
6
4
  - [x] `types/js`
7
5
  - [x] `types/basics`
8
6
  - [x] `types/root`
9
- - [ ] `types/isa`
10
- - [ ] `types/needs`
11
- - [ ] `types/def`
12
- - [ ] `types/typelist`
13
- - [ ] `types/index`
7
+ - [x] `types/isa`
8
+ - [x] `types/needs`
9
+ - [x] `types/def`
10
+ - [x] `types/typelist`
11
+ - [ ] `types/stringify`
12
+ - [x] `types/index`
14
13
  - [x] `arrays`
15
14
  - [ ] `context`
16
15
  - [ ] `strings`
@@ -29,9 +28,4 @@
29
28
  - [ ] `lazy`
30
29
  - [ ] `observable`
31
30
  - [ ] `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
36
31
 
37
- - Who knows, further work on this can wait until the rest of the libraries are finished.
@@ -4,7 +4,36 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
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()`.
8
37
 
9
38
  ## [1.0.0-beta.4] - 2022-07-15
10
39
  ### Added
@@ -35,7 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
35
64
  - Updated `obj/clone` and `obj/lock` to remove use of `descriptors` magic.
36
65
  - Updated `CLONE` mode documentation to use a table format.
37
66
  - 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.
67
+ - Updated [../../TODO.md](TODO.md) with the plans for the final `1.0.0` release.
39
68
 
40
69
  ## [1.0.0-beta.3] - 2022-07-11
41
70
  ### Added
@@ -61,7 +90,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
61
90
  - Pulled a bunch of the core libraries from the old Lum.js project.
62
91
  - Refactored and reorganized the libraries a lot.
63
92
 
64
- [Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.4...HEAD
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
65
95
  [1.0.0-beta.4]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.3...v1.0.0-beta.4
66
96
  [1.0.0-beta.3]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.2...v1.0.0-beta.3
67
97
  [1.0.0-beta.2]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.1...v1.0.0-beta.2
@@ -0,0 +1,32 @@
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.1.0] - 2022-07-29
10
+ ### Added
11
+ - `types.doesDescriptorTemplate()` method.
12
+ - `obj.getProperty()` method (used to be in the `descriptors` sub-module.)
13
+ ### Changed
14
+ - Tweaked documentation for:
15
+ - `obj.getObjectPath()`
16
+ - `obj.setObjectPath()`
17
+ - `obj.getNamespace()`
18
+ - `obj.setNamespace()`
19
+ - Updated error messages in `obj.setObjectPath()`
20
+ - Made `obj.setObjectPath()` use `types.doesDescriptorTemplate()` for validation of `opts.desc` option.
21
+ - Changed `obj.getObjectPath()` and `obj.setObjectPath()` to support `function` parent objects.
22
+ - Enhanced `types.stringify()` to support `RegExp` as well as supporting custom extensions down the road.
23
+
24
+ ## [1.0.0] - 2022-07-27
25
+ ### Changed
26
+ - Initial *stable* release.
27
+ - See [1.0-beta.md](1.0-beta.md) for the beta versions of `1.0`
28
+ - See [lum.js](https://github.com/supernovus/lum.js) for the original library this is replacing.
29
+
30
+ [Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.0.0...HEAD
31
+ [1.0.0]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0
32
+
package/lib/arrays.js CHANGED
@@ -1,8 +1,14 @@
1
+ /**
2
+ * Array helper functions.
3
+ * @module @lumjs/core/arrays
4
+ */
5
+
1
6
  /**
2
7
  * See if an array contains *any* of the specified items.
3
8
  * @param {Array} array
4
9
  * @param {...any} items
5
10
  * @returns {boolean}
11
+ * @alias module:@lumjs/core/arrays.containsAny
6
12
  */
7
13
  function containsAny(array, ...items)
8
14
  {
@@ -22,9 +28,10 @@
22
28
 
23
29
  /**
24
30
  * See if an array contains *all* of the specified items.
25
- * @param {Array} array
31
+ * @param {Array} array
26
32
  * @param {...any} items
27
33
  * @returns {boolean}
34
+ * @alias module:@lumjs/core/arrays.containsAll
28
35
  */
29
36
  function containsAll(array, ...items)
30
37
  {
@@ -43,11 +50,16 @@
43
50
  exports.containsAll = containsAll;
44
51
 
45
52
  /**
46
- * Remove items from an array.
47
- * @param {Array} array
48
- * @param {...any} items
49
- * @returns {number} Number of items removed.
50
- */
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
+ */
51
63
  function removeItems(array, ...items)
52
64
  {
53
65
  let removed = 0;
@@ -63,4 +75,4 @@ function removeItems(array, ...items)
63
75
  return removed;
64
76
  }
65
77
 
66
- exports.removeItems = removeItems;
78
+ exports.removeItems = removeItems;
package/lib/context.js CHANGED
@@ -1,15 +1,28 @@
1
1
 
2
- const {root,B,F,U,O,isObj,isComplex,def} = require('./types');
3
-
4
2
  /**
5
- * Context object.
6
- *
7
- * @namespace Lum.context
3
+ * Context sub-module
8
4
  *
9
- * Offers some insight into the current JS context.
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;
@@ -28,8 +41,20 @@ cd('AMD', typeof define === F && define.amd)
28
41
  ('isSharedWorker', !ctx.CJS && rootHas('SharedWorkerGlobalScope'))
29
42
  ('isBrowser', ctx.isWindow || ctx.isWorker);
30
43
 
31
- // Does the global object/property exist?
32
- // Caches the results so we can do `context.has.Thingy` tests.
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
+ */
33
58
  function hasRoot(ns)
34
59
  {
35
60
  if (typeof hasRoot[ns] === B) return hasRoot[ns];
@@ -44,6 +69,18 @@ for (const what of ['Proxy','Promise','Reflect','fetch'])
44
69
  hasRoot(what);
45
70
  }
46
71
 
47
- cd('has', hasRoot);
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
+ }
48
85
 
49
86
  module.exports = ctx;
package/lib/enum.js CHANGED
@@ -1,7 +1,7 @@
1
- const types = require('./types');
2
- const {S,def,notNil,isObj,needObj} = 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
- if (!isObj(spec))
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 Lum.Enum object");
59
+ throw new TypeError("Non-string passed in Enum object");
65
60
  }
66
61
 
67
62
  const val
@@ -117,10 +112,29 @@ function Enum (spec, opts={})
117
112
 
118
113
  } // Enum
119
114
 
120
- // Add an is() method.
121
- def(Enum, 'is', ENUM_ID.isFunction());
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);
122
123
 
123
- // And an isEnum() method to the `types` namespace.
124
- def(types, 'isEnum', Enum.is);
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');
125
139
 
126
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,54 +1,126 @@
1
- // The core library is made up of a bunch of child modules,
2
- // as well as some standalone classes and functions.
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.
12
+ * @alias module:@lumjs/core.types
13
+ * @see module:@lumjs/core/types
6
14
  */
7
15
  const types = require('./types');
8
16
 
9
17
  /**
10
18
  * Array utility functions.
19
+ * @alias module:@lumjs/core.arrays
20
+ * @see module:@lumjs/core/arrays
11
21
  */
12
22
  const arrays = require('./arrays');
13
23
 
14
24
  /**
15
25
  * Information about the JS context we're running in.
26
+ * @alias module:@lumjs/core.context
27
+ * @see module:@lumjs/core/context
16
28
  */
17
29
  const context = require('./context');
18
30
 
19
31
  /**
20
32
  * Functions for working with strings and locales.
33
+ * @alias module:@lumjs/core.strings
34
+ * @see module:@lumjs/core/strings
21
35
  */
22
36
  const strings = require('./strings');
23
37
 
24
38
  /**
25
39
  * Functions for working with binary flags.
40
+ * @alias module:@lumjs/core.flags
41
+ * @see module:@lumjs/core/flags
26
42
  */
27
43
  const flags = require('./flags');
28
44
 
29
45
  /**
30
46
  * Functions for manipulating objects.
47
+ * @alis module:@lumjs/core.obj
48
+ * @see module:@lumjs/core/obj
31
49
  */
32
50
  const obj = require('./obj');
33
51
 
34
52
  /**
35
53
  * Functions for getting values and properties with fallback defaults.
54
+ * @alias module:@lumjs/core.opt
55
+ * @see module:@lumjs/core/opt
36
56
  */
37
57
  const opt = require('./opt');
38
58
 
39
59
  /**
40
60
  * Meta functions related to JS modules.
61
+ * @alias module:@lumjs/core.modules
62
+ * @see module:@lumjs/core/modules
41
63
  */
42
64
  const modules = require('./modules');
43
65
 
44
- // A few modules that we're going to expand into the main exports.
66
+ // ObjectID stuff is imported directly without registering a sub-module.
45
67
  const {randomNumber, InternalObjectId} = require('./objectid');
68
+
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.
46
97
  const {stacktrace,AbstractClass,Functions,NYI} = require('./meta');
47
98
 
48
- // And finally some standalone functions.
99
+ /**
100
+ * Create a magic *Enum* object.
101
+ * @alias module:@lumjs/core.Enum
102
+ * @function
103
+ * @see module:@lumjs/core/enum
104
+ */
49
105
  const Enum = require('./enum');
50
- const lazy = require('./lazy');
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
+ */
51
113
  const observable = require('./observable');
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
+ */
52
124
  const def = types.def;
53
125
 
54
126
  module.exports =
package/lib/lazy.js CHANGED
@@ -2,7 +2,7 @@
2
2
  const {S,F,TYPES:{COMPLEX},needType,needObj,def} = require('./types');
3
3
 
4
4
  /**
5
- * @callback InitFunc
5
+ * @callback module:@lumjs/core~InitFunc
6
6
  * @param {string} name - The `name` parameter passed to `lazy()`
7
7
  * @this {object} - The `obj` parameter passed to `lazy()`
8
8
  */
@@ -15,9 +15,10 @@ const {S,F,TYPES:{COMPLEX},needType,needObj,def} = require('./types');
15
15
  * This is an extension of the {@link def} method, and indeed an
16
16
  * alias called `def.lazy()` is also available.
17
17
  *
18
- * @param {object} obj - The object to add the property to.
18
+ * @param {Object} obj - The object to add the property to.
19
19
  * @param {string} name - The name of the property to add.
20
- * @param {InitFunc} initfunc - The function to initialize the property.
20
+ * @param {module:@lumjs/core~InitFunc} initfunc
21
+ * The function to initialize the property.
21
22
  * @param {*} [onset] How to handle assignment.
22
23
  *
23
24
  * If this is `true` then the new value will be assigned directly,
@@ -36,14 +37,15 @@ const {S,F,TYPES:{COMPLEX},needType,needObj,def} = require('./types');
36
37
  *
37
38
  * If this is anything else, assignment will do nothing at all.
38
39
  *
39
- * @param {object} [desc={}] Descriptor rules for the property.
40
+ * @param {Object} [desc={}] Descriptor rules for the property.
40
41
  * We only support two descriptor rules with this function, and
41
42
  * their default values are the same as the `def()` function.
42
43
  * - `configurable` → `true`
43
44
  * - `enumerable` → `false`
44
45
  * Any other descriptor properties are invalid here.
45
46
  *
46
- * @return {object} The object we defined the property on.
47
+ * @return {Object} The object we defined the property on.
48
+ * @alias module:@lumjs/core.lazy
47
49
  */
48
50
  function lazy(obj, name, initfunc, onset, desc={})
49
51
  {
package/lib/meta.js CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Meta-programming helpers.
3
+ * @module @lumjs/core/meta
4
+ */
5
+
1
6
  /**
2
7
  * Get a stacktrace. Differs from browser to browser.
3
8
  *
@@ -9,6 +14,7 @@
9
14
  * @param {string} [msg] - A message for the Error object.
10
15
  *
11
16
  * @returns {string[]} An array of stack strings.
17
+ * @alias module:@lumjs/core/meta.stacktrace
12
18
  */
13
19
  function stacktrace(msg)
14
20
  {
@@ -19,6 +25,7 @@ exports.stacktrace = stacktrace;
19
25
 
20
26
  /**
21
27
  * Abstract classes for Javascript.
28
+ * @alias module:@lumjs/core/meta.AbstractClass
22
29
  */
23
30
  class AbstractClass
24
31
  {
@@ -45,6 +52,8 @@ exports.AbstractClass = AbstractClass;
45
52
 
46
53
  /**
47
54
  * Function prototypes for async, generator, and async generator functions.
55
+ * @namespace
56
+ * @alias module:@lumjs/core/meta.Functions
48
57
  */
49
58
  const Functions =
50
59
  {
@@ -75,6 +84,7 @@ exports.Functions = Functions;
75
84
  * @param {string} [prefix=''] A prefix for the error message.
76
85
  *
77
86
  * @returns {void}
87
+ * @alias module:@lumjs/core/meta.NYI
78
88
  */
79
89
  function NYI(fatal=true, prefix='')
80
90
  {
package/lib/modules.js CHANGED
@@ -1,4 +1,7 @@
1
- // Stuff specific to mostly Node.js, but browser-shims may wrap this.
1
+ /**
2
+ * Module helpers.
3
+ * @module @lumjs/core/modules
4
+ */
2
5
 
3
6
  const path = require('path');
4
7
  const {S,isObj} = require('./types');
@@ -7,7 +10,28 @@ const replace = require('./strings').replaceItems;
7
10
  /**
8
11
  * Get the name of a module.
9
12
  *
10
- * TODO: document this.
13
+ * @param {(object|string)} module - Either a module object, or filename.
14
+ * If it is an `object`, it should be a CommonJS `module` object.
15
+ * If it is a `string`, it should be the module filename.
16
+ * @param {object} [opts] Options.
17
+ *
18
+ * @param {boolean} [opts.useAuto=true] Enable automatic name cleaning.
19
+ * If *basename* mode was **not** used, then once all other rules have been
20
+ * applied, strip any leading `.` and `/` characters, and the file extension.
21
+ *
22
+ * @param {boolean} [opts.basename=false] Use `path.basename()`
23
+ * This will strip all parent directories, and the file extension.
24
+ * If no other rules are specified in the `opts`, then this will
25
+ * be applied automatically as a fallback method. If it is set to
26
+ * `true` explicitly, then it will be applied *before* any other options.
27
+ *
28
+ * @param {object} [opts.replace] Call {@link module:@lumjs/core/strings.replaceItems}
29
+ * This uses the default `useAll` values based on the `object` format.
30
+ * @param {object} [opts.replaceOne] `replace` but `useAll` set to `false`.
31
+ * @param {object} [opts.replaceAll] `replace` but `useAll` set to `true`.
32
+ * @param {(string|string[])} [opts.strip] Sub-strings to remove entirely.
33
+ * @returns {string} The *name* of a module as per the options set.
34
+ * @alias module:@lumjs/core/modules.name
11
35
  */
12
36
  function name(module, opts={})
13
37
  {
@@ -29,7 +53,7 @@ function name(module, opts={})
29
53
  const ext = path.extname(filename);
30
54
 
31
55
  let useFallback = true;
32
- let useAuto = !opts.noAuto;
56
+ let useAuto = opts.useAuto ?? true;
33
57
 
34
58
  if (opts.basename)
35
59
  { // We want to run the basename sequence first.