boxwood 0.69.1 → 0.70.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/index.js +35 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -230,27 +230,21 @@ raw.load = function () {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
const tag = (a, b, c) => {
|
|
233
|
-
if (
|
|
233
|
+
if (typeof b === "string" || typeof b === "number" || Array.isArray(b)) {
|
|
234
234
|
const name = a
|
|
235
|
-
const
|
|
236
|
-
const children = c
|
|
235
|
+
const children = b
|
|
237
236
|
return {
|
|
238
237
|
name,
|
|
239
|
-
children,
|
|
240
|
-
attributes,
|
|
238
|
+
children: children,
|
|
241
239
|
}
|
|
242
240
|
}
|
|
243
241
|
const name = a
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
name,
|
|
248
|
-
attributes: children,
|
|
249
|
-
}
|
|
250
|
-
}
|
|
242
|
+
const attributes = b
|
|
243
|
+
const children = c || []
|
|
251
244
|
return {
|
|
252
245
|
name,
|
|
253
246
|
children,
|
|
247
|
+
attributes,
|
|
254
248
|
}
|
|
255
249
|
}
|
|
256
250
|
|
|
@@ -285,7 +279,8 @@ function css(inputs) {
|
|
|
285
279
|
|
|
286
280
|
css.load = function () {
|
|
287
281
|
const path = join(...arguments)
|
|
288
|
-
const
|
|
282
|
+
const file = path.endsWith(".css") ? path : join(path, "index.css")
|
|
283
|
+
const content = readFileSync(file, "utf8")
|
|
289
284
|
return css`
|
|
290
285
|
${content}
|
|
291
286
|
`
|
|
@@ -309,7 +304,8 @@ function js(inputs) {
|
|
|
309
304
|
|
|
310
305
|
js.load = function () {
|
|
311
306
|
const path = join(...arguments)
|
|
312
|
-
const
|
|
307
|
+
const file = path.endsWith(".js") ? path : join(path, "index.js")
|
|
308
|
+
const content = readFileSync(file, "utf8")
|
|
313
309
|
return js`${content}`
|
|
314
310
|
}
|
|
315
311
|
|
|
@@ -456,6 +452,7 @@ function classes() {
|
|
|
456
452
|
const yaml = {
|
|
457
453
|
load() {
|
|
458
454
|
const path = join(...arguments)
|
|
455
|
+
const file = path.endsWith(".yaml") ? path : join(path, "index.yaml")
|
|
459
456
|
const content = readFileSync(path, "utf8")
|
|
460
457
|
return YAML.parse(content)
|
|
461
458
|
},
|
|
@@ -464,7 +461,8 @@ const yaml = {
|
|
|
464
461
|
const json = {
|
|
465
462
|
load() {
|
|
466
463
|
const path = join(...arguments)
|
|
467
|
-
const
|
|
464
|
+
const file = path.endsWith(".json") ? path : join(path, "index.json")
|
|
465
|
+
const content = readFileSync(file, "utf8")
|
|
468
466
|
return JSON.parse(content)
|
|
469
467
|
},
|
|
470
468
|
}
|
|
@@ -479,18 +477,37 @@ i18n.load = function () {
|
|
|
479
477
|
const path = join(...arguments)
|
|
480
478
|
const data = path.endsWith(".yaml") ? yaml.load(path) : json.load(path)
|
|
481
479
|
return function translate(language, key) {
|
|
482
|
-
|
|
480
|
+
if (!language) {
|
|
481
|
+
throw new Error("TranslationError[method]: language is undefined")
|
|
482
|
+
}
|
|
483
|
+
const translation = data[key][language]
|
|
484
|
+
if (!translation) {
|
|
485
|
+
throw new Error(
|
|
486
|
+
`TranslationError[method]: translation for [${key}][${language}] is undefined`
|
|
487
|
+
)
|
|
488
|
+
}
|
|
489
|
+
return translation
|
|
483
490
|
}
|
|
484
491
|
}
|
|
485
492
|
|
|
486
493
|
function component(fn, { styles, i18n } = {}) {
|
|
487
494
|
function execute(a, b) {
|
|
488
|
-
if (typeof a === "string" || Array.isArray(a)) {
|
|
495
|
+
if (typeof a === "string" || typeof a === "number" || Array.isArray(a)) {
|
|
489
496
|
return fn({}, a)
|
|
490
497
|
}
|
|
491
498
|
if (i18n) {
|
|
499
|
+
const { language } = a
|
|
492
500
|
function translate(key) {
|
|
493
|
-
|
|
501
|
+
if (!language) {
|
|
502
|
+
throw new Error("TranslationError[component]: language is undefined")
|
|
503
|
+
}
|
|
504
|
+
const translation = i18n[key][language]
|
|
505
|
+
if (!translation) {
|
|
506
|
+
throw new Error(
|
|
507
|
+
`TranslationError[component]: translation for [${key}][${language}] is undefined`
|
|
508
|
+
)
|
|
509
|
+
}
|
|
510
|
+
return translation
|
|
494
511
|
}
|
|
495
512
|
return fn({ ...a, translate }, b || [])
|
|
496
513
|
}
|