@lumjs/core 1.0.0-beta.1 → 1.0.0-beta.2
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/CHANGELOG.md +8 -0
- package/TODO.md +1 -0
- package/{src → lib}/context.js +0 -0
- package/{src → lib}/descriptors.js +0 -0
- package/{src → lib}/enum.js +0 -0
- package/{src → lib}/flags.js +0 -0
- package/{index.js → lib/index.js} +20 -15
- package/{src → lib}/lazy.js +0 -0
- package/{src → lib}/meta.js +0 -0
- package/lib/modules.js +77 -0
- package/{src → lib}/obj/clone.js +0 -0
- package/{src → lib}/obj/copyall.js +0 -0
- package/{src → lib}/obj/copyprops.js +0 -0
- package/{src → lib}/obj/index.js +0 -0
- package/{src → lib}/obj/lock.js +0 -0
- package/{src → lib}/obj/merge.js +0 -0
- package/{src → lib}/obj/ns.js +0 -0
- package/{src → lib}/objectid.js +0 -0
- package/{src → lib}/observable.js +0 -0
- package/{src → lib}/opt.js +0 -0
- package/{src → lib}/prop.js +0 -0
- package/{src → lib}/strings.js +78 -1
- package/{src → lib}/types.js +0 -0
- package/package.json +2 -2
- package/test/types.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.0.0-beta.2] - 2022-07-08
|
|
10
|
+
## Changed
|
|
11
|
+
- Renamed `src` to `lib` as we're not compiling/transpiling this code.
|
|
12
|
+
- Moved `index.js` into `lib` with the rest of the module files.
|
|
13
|
+
- Added `modules.js` with a method for generating a name/id for a module.
|
|
14
|
+
- Added `isSearch()`,`isReplacement()`, and `replaceItems()` to `strings.js`.
|
|
15
|
+
|
|
9
16
|
## [1.0.0-beta.1] - 2022-07-07
|
|
10
17
|
### Added
|
|
11
18
|
- Initial release.
|
|
@@ -13,5 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
13
20
|
- Refactored and reorganized the libraries a lot.
|
|
14
21
|
|
|
15
22
|
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.1...HEAD
|
|
23
|
+
[1.0.0-beta.2]: https://github.com/supernovus/lum.core.js/compare/v1.0.0-beta.1...v1.0.0-beta.2
|
|
16
24
|
[1.0.0-beta.1]: https://github.com/supernovus/lum.core.js/releases/tag/v1.0.0-beta.1
|
|
17
25
|
|
package/TODO.md
CHANGED
package/{src → lib}/context.js
RENAMED
|
File without changes
|
|
File without changes
|
package/{src → lib}/enum.js
RENAMED
|
File without changes
|
package/{src → lib}/flags.js
RENAMED
|
File without changes
|
|
@@ -5,32 +5,32 @@
|
|
|
5
5
|
* Constants and functions for basic type checking.
|
|
6
6
|
* @namespace types
|
|
7
7
|
*/
|
|
8
|
-
const types = require('./
|
|
8
|
+
const types = require('./types');
|
|
9
9
|
const def = types.def;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Information about the JS context we're running in.
|
|
13
13
|
* @namespace context
|
|
14
14
|
*/
|
|
15
|
-
const context = require('./
|
|
15
|
+
const context = require('./context');
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Functions for working with strings and locales.
|
|
19
19
|
* @namespace strings
|
|
20
20
|
*/
|
|
21
|
-
const strings = require('./
|
|
21
|
+
const strings = require('./strings');
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Functions for working with binary flags.
|
|
25
25
|
* @namespace flags
|
|
26
26
|
*/
|
|
27
|
-
const flags = require('./
|
|
27
|
+
const flags = require('./flags');
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Functions and Enums for working with Descriptors.
|
|
31
31
|
* @namespace descriptors
|
|
32
32
|
*/
|
|
33
|
-
const descriptors = require('./
|
|
33
|
+
const descriptors = require('./descriptors');
|
|
34
34
|
// The *primary* export from descriptors is DESC.
|
|
35
35
|
const DESC = descriptors.DESC;
|
|
36
36
|
|
|
@@ -38,27 +38,32 @@ const DESC = descriptors.DESC;
|
|
|
38
38
|
* Functions for manipulating objects.
|
|
39
39
|
* @namespace obj
|
|
40
40
|
*/
|
|
41
|
-
const obj = require('./
|
|
41
|
+
const obj = require('./obj');
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Functions for getting values and properties with fallback defaults.
|
|
45
45
|
* @namespace opt
|
|
46
46
|
*/
|
|
47
|
-
const opt = require('./
|
|
47
|
+
const opt = require('./opt');
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Meta functions related to JS modules.
|
|
51
|
+
*/
|
|
52
|
+
const modules = require('./modules');
|
|
48
53
|
|
|
49
54
|
// A few modules that we're going to expand into the main exports.
|
|
50
|
-
const {randomNumber, InternalObjectId} = require('./
|
|
51
|
-
const {stacktrace,AbstractClass,Functions} = require('./
|
|
55
|
+
const {randomNumber, InternalObjectId} = require('./objectid');
|
|
56
|
+
const {stacktrace,AbstractClass,Functions} = require('./meta');
|
|
52
57
|
|
|
53
58
|
// And finally some standalone functions.
|
|
54
|
-
const Enum = require('./
|
|
55
|
-
const prop = require('./
|
|
56
|
-
const lazy = require('./
|
|
57
|
-
const observable = require('./
|
|
59
|
+
const Enum = require('./enum');
|
|
60
|
+
const prop = require('./prop');
|
|
61
|
+
const lazy = require('./lazy');
|
|
62
|
+
const observable = require('./observable');
|
|
58
63
|
|
|
59
64
|
module.exports =
|
|
60
65
|
{
|
|
61
66
|
types, context, strings, flags, descriptors, obj, opt,
|
|
62
67
|
randomNumber, InternalObjectId, Enum, prop, lazy, observable,
|
|
63
|
-
stacktrace, AbstractClass, Functions, def, DESC,
|
|
68
|
+
stacktrace, AbstractClass, Functions, def, DESC, modules,
|
|
64
69
|
}
|
package/{src → lib}/lazy.js
RENAMED
|
File without changes
|
package/{src → lib}/meta.js
RENAMED
|
File without changes
|
package/lib/modules.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Stuff specific to mostly Node.js, but browser-shims may wrap this.
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const {S,needObj,needType,isObj} = require('./types');
|
|
5
|
+
const replace = require('./strings').replaceItems;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get the name of a module.
|
|
9
|
+
*
|
|
10
|
+
* TODO: document this.
|
|
11
|
+
*/
|
|
12
|
+
function name(module, opts={})
|
|
13
|
+
{
|
|
14
|
+
needObj(module);
|
|
15
|
+
needType(S, module.filename);
|
|
16
|
+
|
|
17
|
+
let filename = module.filename;
|
|
18
|
+
const ext = path.extname(filename);
|
|
19
|
+
|
|
20
|
+
let useFallback = true;
|
|
21
|
+
let useAuto = !opts.noAuto;
|
|
22
|
+
|
|
23
|
+
if (opts.basename)
|
|
24
|
+
{ // We want to run the basename sequence first.
|
|
25
|
+
filename = path.basename(filename, ext);
|
|
26
|
+
useFallback = false;
|
|
27
|
+
useAuto = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (isObj(opts.replace))
|
|
31
|
+
{ // Replacements using replace() or replaceAll() based on parameter format.
|
|
32
|
+
useFallback = false;
|
|
33
|
+
filename = replace(filename, opts.replace);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isObj(opts.replaceOne))
|
|
37
|
+
{ // Replacements using replace() regardless of parameter format.
|
|
38
|
+
useFallback = false;
|
|
39
|
+
filename = replace(filename, opts.replaceOne, false);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isObj(opts.replaceAll))
|
|
43
|
+
{ // Replacements using replaceAll() regardless of parameter format.
|
|
44
|
+
useFallback = false;
|
|
45
|
+
filename = replace(filename, opts.replaceAll, true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (typeof opts.strip === S)
|
|
49
|
+
{ // A prefix. This always uses replace(), never replaceAll().
|
|
50
|
+
filename = filename.replace(opts.strip, '');
|
|
51
|
+
useFallback = false;
|
|
52
|
+
}
|
|
53
|
+
else if (Array.isArray(opts.strip))
|
|
54
|
+
{ // A list of strings or regexps to strip. Ditto on the use of replace().
|
|
55
|
+
for (const strip of opts.strip)
|
|
56
|
+
{
|
|
57
|
+
filename = filename.replace(strip, '');
|
|
58
|
+
}
|
|
59
|
+
useFallback = false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (useFallback)
|
|
63
|
+
{ // We're going to use the basename, either as a fallback
|
|
64
|
+
filename = path.basename(filename, ext);
|
|
65
|
+
useAuto = false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (useAuto)
|
|
69
|
+
{ // A few automatic rules that normally apply if the fallback was not used.
|
|
70
|
+
filename = filename
|
|
71
|
+
.replace(/^[./]+/, '')
|
|
72
|
+
.replace(RegExp(ext+'$'), '');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.name = name;
|
package/{src → lib}/obj/clone.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{src → lib}/obj/index.js
RENAMED
|
File without changes
|
package/{src → lib}/obj/lock.js
RENAMED
|
File without changes
|
package/{src → lib}/obj/merge.js
RENAMED
|
File without changes
|
package/{src → lib}/obj/ns.js
RENAMED
|
File without changes
|
package/{src → lib}/objectid.js
RENAMED
|
File without changes
|
|
File without changes
|
package/{src → lib}/opt.js
RENAMED
|
File without changes
|
package/{src → lib}/prop.js
RENAMED
|
File without changes
|
package/{src → lib}/strings.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// String methods.
|
|
2
|
-
const {isObj,root} = require('./types')
|
|
2
|
+
const {S,B,F,isObj,root,isArray,needType,needObj} = require('./types')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Get the locale/language string.
|
|
@@ -74,3 +74,80 @@ function ucwords(string, unicode = false, lcrest = false, locale = getLocale())
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
exports.ucwords = ucwords;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Is the passed in value a valid `String.replace` search value.
|
|
80
|
+
*/
|
|
81
|
+
function isSearch(value)
|
|
82
|
+
{
|
|
83
|
+
return (typeof value === S || value instanceof RegExp);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
exports.isSearch = isSearch;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Is the passed in value a valid `String.replace` replacement value.
|
|
90
|
+
*/
|
|
91
|
+
function isReplacement(value)
|
|
92
|
+
{
|
|
93
|
+
return (typeof value === S || typeof value === F);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
exports.isReplacement = isReplacement;
|
|
97
|
+
|
|
98
|
+
function replaceItems(string, replacements, useAll)
|
|
99
|
+
{
|
|
100
|
+
needType(S, string);
|
|
101
|
+
needObj(replacements);
|
|
102
|
+
|
|
103
|
+
// This will call the appropriate method.
|
|
104
|
+
function replace()
|
|
105
|
+
{
|
|
106
|
+
if (useAll)
|
|
107
|
+
string = string.replaceAll(...arguments);
|
|
108
|
+
else
|
|
109
|
+
string = string.replace(...arguments);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (isArray(replacements))
|
|
113
|
+
{ // An array of arrays of replace/replaceAll parameters.
|
|
114
|
+
useAll = useAll ?? false; // Defaults to false here if it wasn't set.
|
|
115
|
+
for (const replacement of replacements)
|
|
116
|
+
{
|
|
117
|
+
if (isArray(replacement) && replacement.length == 2
|
|
118
|
+
&& isSearch(replacement[0]) && isReplacement(replacement[1]))
|
|
119
|
+
{ // A set of parameters for the function.
|
|
120
|
+
replace(...replacement);
|
|
121
|
+
}
|
|
122
|
+
else if (typeof replacement === B)
|
|
123
|
+
{ // A boolean will override the current useAll value.
|
|
124
|
+
useAll = replacement;
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
{ // That's not valid.
|
|
128
|
+
console.error("Invalid replacement value", replacement);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
{ // Any other object is a map of find strings to replacement values.
|
|
134
|
+
useAll = useAll ?? true; // Defaults to true here if it wasn't set.
|
|
135
|
+
for (const find in replacements)
|
|
136
|
+
{
|
|
137
|
+
const value = replacements[find];
|
|
138
|
+
if (isReplacement(value))
|
|
139
|
+
{
|
|
140
|
+
replace(find, value);
|
|
141
|
+
}
|
|
142
|
+
else
|
|
143
|
+
{
|
|
144
|
+
console.error("Invalid replacement value", value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
exports.replaceItems = replaceItems;
|
|
153
|
+
|
package/{src → lib}/types.js
RENAMED
|
File without changes
|
package/package.json
CHANGED
package/test/types.js
CHANGED
|
@@ -3,7 +3,7 @@ const plan = 91;
|
|
|
3
3
|
// A new test instance.
|
|
4
4
|
const t = require('@lumjs/tests').new({module, plan});
|
|
5
5
|
// The types core module
|
|
6
|
-
const types = require('../
|
|
6
|
+
const types = require('../lib/types');
|
|
7
7
|
|
|
8
8
|
// And a quick reference to the type names.
|
|
9
9
|
const TYP = types.TYPES;
|