@lumjs/core 1.7.0 → 1.7.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/index.js +3 -3
- package/lib/modulebuilder.js +57 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -111,7 +111,7 @@ can('strings');
|
|
|
111
111
|
can('flags');
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
* Functions for manipulating objects
|
|
114
|
+
* Functions for manipulating objects «Lazy»
|
|
115
115
|
* @name module:@lumjs/core.obj
|
|
116
116
|
* @type {module:@lumjs/core/obj}
|
|
117
117
|
*/
|
|
@@ -165,12 +165,12 @@ from('objectid', 'randomNumber', 'InternalObjectId');
|
|
|
165
165
|
from('meta', 'stacktrace', 'AbstractClass', 'Functions', 'NYI');
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
* Create a magic *Enum* object
|
|
168
|
+
* Create a magic *Enum* object «Lazy»
|
|
169
169
|
* @name module:@lumjs/core.Enum
|
|
170
170
|
* @function
|
|
171
171
|
* @see module:@lumjs/core/enum
|
|
172
172
|
*/
|
|
173
|
-
can('Enum',
|
|
173
|
+
can('Enum', true);
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* Make an object support the *Observable* API «Lazy»
|
package/lib/modulebuilder.js
CHANGED
|
@@ -11,6 +11,9 @@ const clone = require('./obj/copyall').duplicateOne;
|
|
|
11
11
|
// Methods we want to export in the functional API.
|
|
12
12
|
const BUILD_METHODS = ['has', 'can', 'from', 'set'];
|
|
13
13
|
|
|
14
|
+
// Fallback locale
|
|
15
|
+
const DLOC = 'en-US';
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* A class to make building modules easier.
|
|
16
19
|
*
|
|
@@ -50,6 +53,16 @@ class ModuleBuilder
|
|
|
50
53
|
* It's always possible to set the `conf.module` parameter manually as well,
|
|
51
54
|
* which avoids the need to generate a separate parameter name.
|
|
52
55
|
*
|
|
56
|
+
* @param {(string|boolean)} [opts.withLocale=false] Use locales?
|
|
57
|
+
*
|
|
58
|
+
* If this is a `string` it's the name of the locale (e.g. `en-US`).
|
|
59
|
+
*
|
|
60
|
+
* If this is `true` we'll use the default locale as determined by
|
|
61
|
+
* [getLocale()]{@link module:@lumjs/core/strings.getLocale}.
|
|
62
|
+
*
|
|
63
|
+
* If this is `false` we won't use locales (unless the `NESTED_CAMEL`
|
|
64
|
+
* mode is in use, in which case we'll use the default locale.)
|
|
65
|
+
*
|
|
53
66
|
*/
|
|
54
67
|
constructor(targetModule, opts={})
|
|
55
68
|
{
|
|
@@ -66,14 +79,24 @@ class ModuleBuilder
|
|
|
66
79
|
|
|
67
80
|
this.nested = opts.nested ?? ModuleBuilder.NESTED_ERROR;
|
|
68
81
|
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
if (opts.withLocale)
|
|
83
|
+
{ // Initialize the strings here.
|
|
84
|
+
this.withLocale(opts.locale);
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
// Get a descriptor for a module export.
|
|
74
89
|
requireDescriptor(name, conf={})
|
|
75
90
|
{
|
|
76
|
-
if (typeof conf
|
|
91
|
+
if (typeof conf === S)
|
|
92
|
+
{ // A quick shortcut for setting module name.
|
|
93
|
+
conf = {module: conf};
|
|
94
|
+
}
|
|
95
|
+
else if (conf === true)
|
|
96
|
+
{ // Use the lowercase name as the module.
|
|
97
|
+
conf = {module: this.$lc(name)};
|
|
98
|
+
}
|
|
99
|
+
else if (typeof conf.getter === F || typeof conf.setter === F)
|
|
77
100
|
{ // It's an accessor-style descriptor already.
|
|
78
101
|
return conf;
|
|
79
102
|
}
|
|
@@ -102,6 +125,11 @@ class ModuleBuilder
|
|
|
102
125
|
return {configurable, enumerable, writable, value};
|
|
103
126
|
}
|
|
104
127
|
|
|
128
|
+
$lc(name)
|
|
129
|
+
{
|
|
130
|
+
return name.toLocaleLowerCase(this.locale ?? DLOC);
|
|
131
|
+
}
|
|
132
|
+
|
|
105
133
|
// Normalize a property name.
|
|
106
134
|
$normalizeProperty(name)
|
|
107
135
|
{
|
|
@@ -134,16 +162,29 @@ class ModuleBuilder
|
|
|
134
162
|
return name;
|
|
135
163
|
}
|
|
136
164
|
|
|
137
|
-
|
|
165
|
+
withLocale(loc)
|
|
138
166
|
{
|
|
139
167
|
if (this.strings === undefined)
|
|
140
|
-
{
|
|
168
|
+
{ // Load the strings library.
|
|
141
169
|
this.strings = require('./strings');
|
|
142
170
|
}
|
|
171
|
+
|
|
143
172
|
if (this.locale === undefined)
|
|
144
|
-
{
|
|
145
|
-
|
|
173
|
+
{ // Set the locale.
|
|
174
|
+
if (typeof loc === S)
|
|
175
|
+
{ // Use an explicitly passed value.
|
|
176
|
+
this.locale = loc;
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
{ // Use the default locale.
|
|
180
|
+
this.locale = this.strings.getLocale();
|
|
181
|
+
}
|
|
146
182
|
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
$normalizeWithCamelCase(names)
|
|
186
|
+
{
|
|
187
|
+
this.withLocale();
|
|
147
188
|
let name = names.shift().toLocaleLowerCase(this.locale);
|
|
148
189
|
for (const path in names)
|
|
149
190
|
{
|
|
@@ -157,7 +198,14 @@ class ModuleBuilder
|
|
|
157
198
|
*
|
|
158
199
|
* @param {string} name - The property name to export.
|
|
159
200
|
*
|
|
160
|
-
* @param {object} [conf] Additional export configuration options.
|
|
201
|
+
* @param {(object|string|true)} [conf] Additional export configuration options.
|
|
202
|
+
*
|
|
203
|
+
* If this is a `string` instead of an `object`, it's assumed to be the
|
|
204
|
+
* `conf.module` value.
|
|
205
|
+
*
|
|
206
|
+
* If this is `true` then the `conf` will be set with `module` being the
|
|
207
|
+
* lowercase version of `name`.
|
|
208
|
+
*
|
|
161
209
|
* @param {string} [conf.module=`./${name}`] The module to `require()`.
|
|
162
210
|
* @param {string} [conf.prop] If set, we want an exported property
|
|
163
211
|
* of this name from the loaded module.
|
|
@@ -193,7 +241,7 @@ class ModuleBuilder
|
|
|
193
241
|
* @param {object} [conf] Additional export configuration options.
|
|
194
242
|
*
|
|
195
243
|
* In addition to all the options supported by
|
|
196
|
-
* [has()]{@link module:@lumjs/core/modules
|
|
244
|
+
* [has()]{@link module:@lumjs/core/modules#has}
|
|
197
245
|
* this also supports one further option.
|
|
198
246
|
*
|
|
199
247
|
* @param {object} [conf.lazy] Advanced options for the `lazy()` call.
|