bajo 2.12.1 → 2.13.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/class/app.js +7 -0
- package/class/bajo.js +13 -12
- package/class/plugin/err.js +4 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +10 -0
package/class/app.js
CHANGED
|
@@ -382,8 +382,15 @@ class App {
|
|
|
382
382
|
*/
|
|
383
383
|
t = (ns, text, ...params) => {
|
|
384
384
|
const { formatText, isSet } = this.lib.aneka
|
|
385
|
+
const { isArray, last } = this.lib._
|
|
386
|
+
const { join } = this.bajo
|
|
385
387
|
let { text: newText, trans, params: args } = this._prepTrans(ns, text, params)
|
|
386
388
|
if (!isSet(trans)) trans = newText
|
|
389
|
+
const lang = isPlainObject(last(args)) ? last(args).lang : undefined
|
|
390
|
+
for (const idx in args) {
|
|
391
|
+
const arg = args[idx]
|
|
392
|
+
if (isArray(arg)) args[idx] = join(arg, { lang })
|
|
393
|
+
}
|
|
387
394
|
return formatText(trans, ...args)
|
|
388
395
|
}
|
|
389
396
|
|
package/class/bajo.js
CHANGED
|
@@ -800,12 +800,10 @@ class Bajo extends Plugin {
|
|
|
800
800
|
* @param {string} [options.lastSeparator=and] - Text to use as the last separator
|
|
801
801
|
* @returns {string}
|
|
802
802
|
*/
|
|
803
|
-
join = (
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
let lang
|
|
807
|
-
if (isString(options)) separator = options
|
|
808
|
-
else ({ separator, lastSeparator, lang } = options)
|
|
803
|
+
join = (input = [], options = {}) => {
|
|
804
|
+
const array = [...input]
|
|
805
|
+
if (isString(options)) options = { separator: options }
|
|
806
|
+
let { separator = ', ', lastSeparator = 'and', lang } = options
|
|
809
807
|
const translate = (val) => {
|
|
810
808
|
return this.t(val, { lang }).toLowerCase()
|
|
811
809
|
}
|
|
@@ -851,8 +849,8 @@ class Bajo extends Plugin {
|
|
|
851
849
|
readConfig = async (file, options = {}) => {
|
|
852
850
|
const { parseObject } = this.app.lib
|
|
853
851
|
const { defaultsDeep } = this.app.lib.aneka
|
|
854
|
-
const { uniq, isString, isArray, findIndex, isPlainObject } = this.app.lib._
|
|
855
|
-
let { ns, baseNs, extend, checkOverride, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
852
|
+
const { uniq, isString, isArray, findIndex, isPlainObject, merge } = this.app.lib._
|
|
853
|
+
let { ns, baseNs, extend, checkOverride, merge: merged, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
856
854
|
|
|
857
855
|
const getParseOptsArgs = (opts, orig) => {
|
|
858
856
|
opts.parserOpts = opts.parserOpts ?? {}
|
|
@@ -884,19 +882,22 @@ class Bajo extends Plugin {
|
|
|
884
882
|
if (checkOverride) {
|
|
885
883
|
getParseOptsArgs(opts, orig)
|
|
886
884
|
const fileExt = `${this.app.main.dir.pkg}/extend/${baseNs}/override/${ns}${suffix}/${_path}`
|
|
887
|
-
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, checkOverride: false }))
|
|
885
|
+
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, checkOverride: false, merge: false }))
|
|
888
886
|
if (!isEmpty(result)) orig = result
|
|
889
887
|
}
|
|
890
888
|
getParseOptsArgs(opts, orig)
|
|
889
|
+
const binder = merged ? merge : defaultsDeep
|
|
891
890
|
for (const base of bases) {
|
|
892
891
|
if (!this.app[base]) continue
|
|
893
892
|
const fileExt = `${this.app[base].dir.pkg}/extend/${baseNs}/extend/${ns}${suffix}/${_path}`
|
|
894
|
-
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false }))
|
|
893
|
+
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, merge: false }))
|
|
895
894
|
if (isEmpty(result)) continue
|
|
896
895
|
if (isArray(result)) ext = [...result, ...ext]
|
|
897
|
-
else ext =
|
|
896
|
+
else ext = binder({}, result, ext)
|
|
898
897
|
}
|
|
899
|
-
|
|
898
|
+
if (isArray(orig)) return [...orig, ...ext]
|
|
899
|
+
const item = keys.length > 0 ? pick(ext, keys) : ext
|
|
900
|
+
return binder({}, item, orig)
|
|
900
901
|
}
|
|
901
902
|
|
|
902
903
|
parserOpts.readFromFile = true
|
package/class/plugin/err.js
CHANGED
|
@@ -103,7 +103,10 @@ class Err extends Tools {
|
|
|
103
103
|
const detailsMessage = []
|
|
104
104
|
each(value, (v, i) => {
|
|
105
105
|
if (isString(v)) v = { error: v }
|
|
106
|
-
if (!v.context)
|
|
106
|
+
if (!v.context) {
|
|
107
|
+
v.error = me.plugin.t(v.error)
|
|
108
|
+
return undefined
|
|
109
|
+
}
|
|
107
110
|
v.context.message = v.message
|
|
108
111
|
if (v.type === 'any.only') {
|
|
109
112
|
const items = without(get(v, 'context.valids', []))
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-05-02
|
|
4
|
+
|
|
5
|
+
- [2.13.1] Bug fix in ```app.t()```
|
|
6
|
+
- [2.13.1] Bug fix in ```bajo.join()```
|
|
7
|
+
|
|
8
|
+
## 2026-04-28
|
|
9
|
+
|
|
10
|
+
- [2.13.0] Add ```options.merge``` to ```readConfig()```
|
|
11
|
+
- [2.13.0] Bug fix in ```err.js```
|
|
12
|
+
|
|
3
13
|
## 2026-04-25
|
|
4
14
|
|
|
5
15
|
- [2.12.1] Bug fix in ```readConfig()```
|