waibu 2.5.0 → 2.6.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/index.js CHANGED
@@ -568,6 +568,54 @@ async function factory (pkgName) {
568
568
  })
569
569
  return text
570
570
  }
571
+
572
+ arrayToAttr = (array = [], delimiter = ' ') => {
573
+ const { isPlainObject } = this.app.lib._
574
+ return array.map(item => {
575
+ if (isPlainObject(item)) return this.objectToAttr(item)
576
+ return item
577
+ }).join(delimiter)
578
+ }
579
+
580
+ attrToArray = (text = '', delimiter = ' ') => {
581
+ const { map, trim, without, isArray } = this.app.lib._
582
+ if (text === true) text = ''
583
+ if (isArray(text)) text = text.join(delimiter)
584
+ return without(map(text.split(delimiter), i => trim(i)), '', undefined, null).map(item => {
585
+ return item
586
+ })
587
+ }
588
+
589
+ attrToObject = (text = '', delimiter = ';', kvDelimiter = ':') => {
590
+ const { camelCase, isPlainObject } = this.app.lib._
591
+ const result = {}
592
+ if (isPlainObject(text)) text = this.objectToAttr(text)
593
+ if (typeof text !== 'string') return text
594
+ if (text.slice(1, 3) === '%=') return text
595
+ const array = this.attrToArray(text, delimiter)
596
+ array.forEach(item => {
597
+ const [key, val] = this.attrToArray(item, kvDelimiter)
598
+ result[camelCase(key)] = val
599
+ })
600
+ return result
601
+ }
602
+
603
+ base64JsonDecode = (data = 'e30=') => {
604
+ return JSON.parse(Buffer.from(data, 'base64'))
605
+ }
606
+
607
+ base64JsonEncode = (data) => {
608
+ return Buffer.from(JSON.stringify(data)).toString('base64')
609
+ }
610
+
611
+ objectToAttr = (obj = {}, delimiter = ';', kvDelimiter = ':') => {
612
+ const { forOwn, kebabCase } = this.app.lib._
613
+ const result = []
614
+ forOwn(obj, (v, k) => {
615
+ result.push(`${kebabCase(k)}${kvDelimiter}${v ?? ''}`)
616
+ })
617
+ return result.join(delimiter)
618
+ }
571
619
  }
572
620
 
573
621
  return Waibu
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-02-18
4
+
5
+ - [2.6.0] Move attribute functions from ```waibu-mpa```
6
+
3
7
  ## 2026-02-17
4
8
 
5
9
  - [2.5.0] Add ```getHostname()```