bajo 2.13.0 → 2.14.0
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 +20 -11
- package/package.json +1 -1
- package/wiki/CHANGES.md +14 -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
|
}
|
|
@@ -852,7 +850,7 @@ class Bajo extends Plugin {
|
|
|
852
850
|
const { parseObject } = this.app.lib
|
|
853
851
|
const { defaultsDeep } = this.app.lib.aneka
|
|
854
852
|
const { uniq, isString, isArray, findIndex, isPlainObject, merge } = this.app.lib._
|
|
855
|
-
let { ns, baseNs, extend, checkOverride, merge: merged, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
853
|
+
let { ns, baseNs, extend, checkOverride, merge: merged, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {}, handler } = options
|
|
856
854
|
|
|
857
855
|
const getParseOptsArgs = (opts, orig) => {
|
|
858
856
|
opts.parserOpts = opts.parserOpts ?? {}
|
|
@@ -866,7 +864,10 @@ class Bajo extends Plugin {
|
|
|
866
864
|
|
|
867
865
|
const output = async (obj) => {
|
|
868
866
|
let orig = parseObject(obj)
|
|
869
|
-
if (!baseNs || extend === false)
|
|
867
|
+
if (!baseNs || extend === false) {
|
|
868
|
+
await this.runHook('bajo:afterReadConfig', file, orig, options)
|
|
869
|
+
return orig
|
|
870
|
+
}
|
|
870
871
|
const { suffix = '', keys = [] } = options
|
|
871
872
|
let bases = this.app.getAllNs()
|
|
872
873
|
if (isString(extend)) extend = extend.split(',').map(i => i.trim)
|
|
@@ -884,24 +885,32 @@ class Bajo extends Plugin {
|
|
|
884
885
|
if (checkOverride) {
|
|
885
886
|
getParseOptsArgs(opts, orig)
|
|
886
887
|
const fileExt = `${this.app.main.dir.pkg}/extend/${baseNs}/override/${ns}${suffix}/${_path}`
|
|
888
|
+
await this.runHook('bajo.override:beforeReadConfig', fileExt, options)
|
|
887
889
|
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, checkOverride: false, merge: false }))
|
|
890
|
+
await this.runHook('bajo.override:afterReadConfig', fileExt, result, options)
|
|
888
891
|
if (!isEmpty(result)) orig = result
|
|
889
892
|
}
|
|
890
893
|
getParseOptsArgs(opts, orig)
|
|
891
894
|
const binder = merged ? merge : defaultsDeep
|
|
892
895
|
for (const base of bases) {
|
|
893
896
|
if (!this.app[base]) continue
|
|
897
|
+
options.sourceNs = base
|
|
894
898
|
const fileExt = `${this.app[base].dir.pkg}/extend/${baseNs}/extend/${ns}${suffix}/${_path}`
|
|
899
|
+
await this.runHook('bajo.extend:beforeReadConfig', fileExt, options)
|
|
895
900
|
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, merge: false }))
|
|
901
|
+
await this.runHook('bajo.extend:afterReadConfig', fileExt, result, options)
|
|
896
902
|
if (isEmpty(result)) continue
|
|
897
903
|
if (isArray(result)) ext = [...result, ...ext]
|
|
898
904
|
else ext = binder({}, result, ext)
|
|
899
905
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
906
|
+
delete options.sourceNs
|
|
907
|
+
let result = isArray(orig) ? [...orig, ...ext] : binder({}, keys.length > 0 ? pick(ext, keys) : ext, orig)
|
|
908
|
+
if (handler) result = await this.callHandler(this.app[ns], handler, result)
|
|
909
|
+
await this.runHook('bajo:afterReadConfig', file, result, options)
|
|
910
|
+
return result
|
|
903
911
|
}
|
|
904
912
|
|
|
913
|
+
await this.runHook('bajo:beforeReadConfig', file, options)
|
|
905
914
|
parserOpts.readFromFile = true
|
|
906
915
|
if (!ns) ns = this.ns
|
|
907
916
|
file = resolvePath(this.getPluginFile(file))
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-05-16
|
|
4
|
+
|
|
5
|
+
- [2.14.0] Add ```bajo:beforeReadConfig()``` hook
|
|
6
|
+
- [2.14.0] Add ```bajo.override:beforeReadConfig()``` hook
|
|
7
|
+
- [2.14.0] Add ```bajo.extend:beforeReadConfig()``` hook
|
|
8
|
+
- [2.14.0] Add ```bajo:afterReadConfig()``` hook
|
|
9
|
+
- [2.14.0] Add ```bajo.override:afterReadConfig()``` hook
|
|
10
|
+
- [2.14.0] Add ```bajo.extend:afterReadConfig()``` hook
|
|
11
|
+
|
|
12
|
+
## 2026-05-02
|
|
13
|
+
|
|
14
|
+
- [2.13.1] Bug fix in ```app.t()```
|
|
15
|
+
- [2.13.1] Bug fix in ```bajo.join()```
|
|
16
|
+
|
|
3
17
|
## 2026-04-28
|
|
4
18
|
|
|
5
19
|
- [2.13.0] Add ```options.merge``` to ```readConfig()```
|