@lumjs/core 1.30.0 → 1.31.1

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/lib/obj/flip.js CHANGED
@@ -59,6 +59,7 @@ function flip(obj, opts={})
59
59
  * @throws {ReferenceError} If `fatalDup` is `true`
60
60
  * and a duplicate value is found.
61
61
  *
62
+ * @alias module:@lumjs/core/obj.flipKeyVal
62
63
  */
63
64
  function flipKeyVal(inObj, opts={})
64
65
  {
@@ -148,6 +149,7 @@ function flipKeyVal(inObj, opts={})
148
149
  * - If both `opts.valid.map` and `opts.valid.fatal` are `true`,
149
150
  * and the validation tests against the `inMap` object fail.
150
151
  *
152
+ * @alias module:@lumjs/core/obj.flipMap
151
153
  */
152
154
  function flipMap(inMap, opts={})
153
155
  {
package/lib/obj/index.js CHANGED
@@ -13,6 +13,7 @@ const getProperty = require('./getproperty');
13
13
  const {lock,addLock} = require('./lock');
14
14
  const {mergeNested,syncNested} = require('./merge');
15
15
  const ns = require('./ns');
16
+ const cp = require('./cp');
16
17
 
17
18
  const
18
19
  {
@@ -22,7 +23,7 @@ const
22
23
 
23
24
  module.exports =
24
25
  {
25
- CLONE, clone, addClone, cloneIfLocked, lock, addLock,
26
+ cp, CLONE, clone, addClone, cloneIfLocked, lock, addLock,
26
27
  mergeNested, syncNested, copyProps, copyAll, ns,
27
28
  getObjectPath, setObjectPath, getNamespace, setNamespace,
28
29
  getProperty, duplicateAll, duplicateOne, getMethods, signatureOf,
package/lib/objectid.js CHANGED
@@ -43,6 +43,13 @@ exports.randomNumber = randomNumber;
43
43
 
44
44
  const validBase = base => (typeof base === N && base > 1 && base < 37);
45
45
 
46
+ /**
47
+ * A class for generating unique ids for objects.
48
+ *
49
+ * TODO: document all the methods, etc.
50
+ *
51
+ * @alias module:@lumjs/core.UniqueObjectIds
52
+ */
46
53
  class UniqueObjectIds
47
54
  {
48
55
  constructor(opts={})
package/lib/state.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ const {S,isObj} = require('./types')
4
+ const ctx = require('./context')
5
+ const stateSym = Symbol('@lumjs/core/state')
6
+ const stateData = {[stateSym]: false}
7
+ const stateKey = 'LUM_JS_STATE'
8
+ const stateOpts = {}
9
+
10
+ module.exports =
11
+ {
12
+ get(opts={})
13
+ {
14
+ if (opts.refresh || !stateData[stateSym])
15
+ {
16
+ let json;
17
+ if (ctx.isNode)
18
+ {
19
+ json = process.env[stateKey];
20
+ }
21
+ else if (ctx.isBrowser)
22
+ {
23
+ json = localStorage.getItem(stateKey);
24
+ }
25
+
26
+ if (typeof json === S)
27
+ {
28
+ const revive = opts.jsonRevive ?? stateOpts.jsonRevive;
29
+ const storedData = JSON.parse(json, revive);
30
+ if (isObj(storedData))
31
+ {
32
+ Object.assign(stateData, storedData);
33
+ stateData[stateSym] = true;
34
+ }
35
+ }
36
+ }
37
+ return stateData;
38
+ },
39
+
40
+ save(opts={})
41
+ {
42
+ if (!stateData[stateSym]) return false;
43
+
44
+ const replace = opts.jsonReplace ?? stateOpts.jsonReplace;
45
+ const json = JSON.stringify(stateData, replace);
46
+
47
+ if (ctx.isBrowser)
48
+ {
49
+ localStorage.setItem(stateKey, json);
50
+ }
51
+ else if (ctx.isNode)
52
+ {
53
+ console.log("export ", stateKey, "=", json);
54
+ }
55
+ },
56
+
57
+ opts: stateOpts,
58
+
59
+ [stateSym]: stateData,
60
+ $$: stateSym,
61
+ }
@@ -3,21 +3,13 @@
3
3
  /**
4
4
  * Basic types sub-module.
5
5
  *
6
- * Provides simple type tests, and a few one or two character constants
7
- * One or two character identifiers for the core JS type names.
6
+ * Provides a whole assortment of simple type test functions,
7
+ * as well as all of the constants found in its `JS` property.
8
+ * Which means `basics.S === basics.JS.S`.
8
9
  *
9
- * These are only the strings returned by the `typeof` operator.
10
- * See {@link module:@lumjs/core/types.TYPES} for a list
11
- * that includes special types and compound pseudo-types, etc.
12
- *
13
- * @prop {string} O - object
14
- * @prop {string} F - function
15
- * @prop {string} S - string
16
- * @prop {string} B - boolean
17
- * @prop {string} N - number
18
- * @prop {string} U - undefined
19
- * @prop {string} SY - symbol
20
- * @prop {string} BI - bigint
10
+ * Unlike the `JS` object, this sub-module is NOT frozen/locked,
11
+ * although the JS constants are assigned as _non-configurable_ so
12
+ * they cannot be overwritten by different values.
21
13
  *
22
14
  * @module @lumjs/core/types/basics
23
15
  */
package/lib/types/dt.js CHANGED
@@ -49,11 +49,11 @@ const P = Object.freeze(
49
49
  * Similar magic properties may be added to bound instances of `def`;
50
50
  * I'll add further docs for that later. Look at the tests for examples.
51
51
  *
52
- * @class
53
- * @alias module:@lumjs/core/types~DescriptorTemplate
54
- *
55
52
  * The constructor function is also available via `def.DT`,
56
53
  * but using the built-in properties is easier.
54
+ *
55
+ * @class
56
+ * @alias module:@lumjs/core/types~DescriptorTemplate
57
57
  */
58
58
  function DescriptorTemplate(opts={})
59
59
  {
@@ -6,9 +6,6 @@
6
6
  * As `@lumjs/core` is the foundation for all my JS libraries,
7
7
  * this module is the foundation for `@lumjs/core`.
8
8
  *
9
- * Re-exports everything from the {@link @lumjs/core/types/basics}
10
- * sub-module with the same names, and adds a whole lot more!
11
- *
12
9
  * @module @lumjs/core/types
13
10
  */
14
11
 
package/lib/types/js.js CHANGED
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
2
 
3
- // A package-private collection of constants.
4
- // Exported as a part of `basics` and `index`.
3
+ /**
4
+ * An absolutely minimal map of one or two letter string constants
5
+ * representing all of the fundamental JS types.
6
+ *
7
+ * This object is *frozen* and cannot be modified in any way!
8
+ *
9
+ * These are only the strings returned by the `typeof` operator.
10
+ * See {@link module:@lumjs/core/types.TYPES} for a much more complete
11
+ * list that includes special types and compound pseudo-types, etc.
12
+ *
13
+ * @prop {string} O - object
14
+ * @prop {string} F - function
15
+ * @prop {string} S - string
16
+ * @prop {string} B - boolean
17
+ * @prop {string} N - number
18
+ * @prop {string} U - undefined
19
+ * @prop {string} SY - symbol
20
+ * @prop {string} BI - bigint
21
+ *
22
+ * @memberof module:@lumjs/core/types/basics
23
+ */
5
24
  const JS =
6
25
  {
7
26
  O: 'object',
@@ -9,12 +9,14 @@ const
9
9
  /**
10
10
  * A map of **Types**, including *special* and *union* types.
11
11
  *
12
- * Contains the same `O, F, S, B, N, U, SY, BI` properties as also
13
- * found in the top-level {@link module:@lumjs/core/types} module.
14
- * While most of the core JS types simply use `typeof` as their
12
+ * Contains the constants from {@link module:@lumjs/core/types/basics.JS},
13
+ * plus a whole bunch of _special types_ that require tests other than
14
+ * `typeof` to determine if a given value matches that type.
15
+ *
16
+ * Also, while MOST of the core JS types simply use `typeof` as their
15
17
  * test, this maps the `O` (`object`) type to the `isObj` test.
16
18
  *
17
- * Will also contain a few helper functions, and a map of tests
19
+ * It also contain a few helper functions, and a map of tests
18
20
  * that are used by `isType`, `isa`, `needType`, and `needs`.
19
21
  * Any one of these properties may be passed to those functions as
20
22
  * the desired *type* a desired value must be.
package/lum.build.js ADDED
@@ -0,0 +1,11 @@
1
+ module.exports = function(rb)
2
+ {
3
+ rb.readme
4
+ .add('docs/TODO.md')
5
+ .chdir('docs/changelogs')
6
+ .add('index.md')
7
+ .add('1.0-beta.md')
8
+ .add('1.x.md')
9
+ .add('2.x.md')
10
+ //.set('debug', true)
11
+ }
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@lumjs/core",
3
- "version": "1.30.0",
3
+ "version": "1.31.1",
4
4
  "main": "lib/index.js",
5
- "exports":
5
+ "exports":
6
6
  {
7
7
  ".": "./lib/index.js",
8
-
9
8
  "./arrays": "./lib/arrays/index.js",
10
9
  "./console": "./lib/console.js",
11
10
  "./context": "./lib/context.js",
12
11
  "./enum": "./lib/enum.js",
12
+ "./events": "./lib/events/index.js",
13
13
  "./flags": "./lib/flags.js",
14
14
  "./maps": "./lib/maps.js",
15
15
  "./meta": "./lib/meta.js",
16
16
  "./modules": "./lib/modules.js",
17
17
  "./obj": "./lib/obj/index.js",
18
+ "./obj/cp": "./lib/obj/cp.js",
18
19
  "./observable": "./lib/observable.js",
19
20
  "./opt": "./lib/opt/index.js",
20
21
  "./opt/args": "./lib/opt/args.js",
@@ -23,23 +24,28 @@
23
24
  "./types": "./lib/types/index.js",
24
25
  "./types/basics": "./lib/types/basics.js",
25
26
  "./types/def": "./lib/types/def.js",
26
-
27
27
  "./package.json": "./package.json"
28
28
  },
29
- "license": "MIT",
30
- "repository":
29
+ "dependencies":
31
30
  {
32
- "type": "git",
33
- "url": "https://github.com/supernovus/lum.core.js.git"
31
+ "@lumjs/opts": "^1.0.0"
34
32
  },
35
- "devDependencies":
33
+ "devDependencies":
36
34
  {
37
- "@lumjs/opts": "^1.0.0",
35
+ "@lumjs/build": "^1.1.0",
38
36
  "@lumjs/tests": "^2.0.0"
39
37
  },
40
- "scripts":
38
+ "scripts":
41
39
  {
42
40
  "test": "lumtest.js",
43
- "build-docs": "jsdoc -c ./jsdoc.json"
44
- }
41
+ "build-meta": "lum-build",
42
+ "build-jsdoc": "jsdoc -c ./jsdoc.js",
43
+ "build-docs": "npm run build-meta && npm run build-jsdoc"
44
+ },
45
+ "repository":
46
+ {
47
+ "type": "git",
48
+ "url": "https://github.com/supernovus/lum.core.js.git"
49
+ },
50
+ "license": "MIT"
45
51
  }
package/TODO.md DELETED
@@ -1,76 +0,0 @@
1
- # TODO
2
-
3
- ## v2.x
4
-
5
- I'm thinking it's getting close to time to do a big cleanup of the codebase,
6
- and refactor a few things that have gotten rather crufty. While there may be
7
- a few more releases in the `1.x` series, I think focusing on a clean break
8
- for the future would be a good idea. A few of the things I want to do:
9
-
10
- - Remove all deprecated code:
11
- - `obj.{copyAll,duplicateOne,duplicateAll}`
12
- - `types.instanceOf` and related options in `types.isa`
13
- - `<meta>.AbstractClass`
14
- - Implement a new `obj.copy` API function/class
15
- - Will completely replace `obj.{clone,copyProps,mergeNested}`
16
- - Offer an extended version of the declarative API from `copyProps`
17
- - Cut anything that seems superfluous or rarely used
18
- - Add ability to copy `Symbol` properties
19
- - Replace `obj.syncNested` with `obj.sync` using the new `obj.copy` API
20
- - Move `opt.Opts` into its own separate package
21
- - Give `observable` some TLC
22
-
23
- I will likely update this list a bit before I get around to starting the
24
- new branch that will eventually become the `2.0.0` release.
25
-
26
- I also want to make a new version of the [@lumjs/compat] package that
27
- will be more helpful for major updates in the future, so it will have
28
- a corresponding `v2.x` release at the same time as this package.
29
-
30
- ## Tests
31
-
32
- Write proper tests using [@lumjs/tests] library.
33
- This list of files is out of date and needs updating.
34
-
35
- - [x] `types/js`
36
- - [x] `types/basics`
37
- - [x] `types/root`
38
- - [x] `types/isa`
39
- - [x] `types/needs`
40
- - [x] `types/def`
41
- - [x] `types/typelist`
42
- - [ ] `types/stringify`
43
- - [x] `types/index`
44
- - [x] `arrays`
45
- - [ ] `context`
46
- - [ ] `strings`
47
- - [ ] `flags`
48
- - [ ] `obj/copyall`
49
- - [ ] `obj/copyprops`
50
- - [ ] `obj/clone`
51
- - [ ] `obj/lock`
52
- - [ ] `obj/merge`
53
- - [ ] `obj/ns`
54
- - [ ] `obj/index`
55
- - [ ] `opt`
56
- - [ ] `objectid`
57
- - [ ] `meta`
58
- - [ ] `enum`
59
- - [ ] `lazy`
60
- - [ ] `observable`
61
- - [ ] `index`
62
-
63
- Would be nice to have the tests finished for the planned `2.x` release.
64
-
65
- ## Documentation
66
-
67
- Go through all the DocBlocks and ensure the documentation is up-to-date and
68
- good enough to actually be useful.
69
-
70
- This would also be nice to have finished for the planned `2.x` release.
71
-
72
- ---
73
-
74
- [@lumjs/tests]: https://github.com/supernovus/lum.tests.js
75
- [@lumjs/compat]: https://github.com/supernovus/lum.compat.js
76
-
package/jsdoc.json DELETED
@@ -1,33 +0,0 @@
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
- }