waibu 2.4.1 → 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
@@ -301,7 +301,7 @@ async function factory (pkgName) {
301
301
  }
302
302
 
303
303
  /**
304
- * Get origin of fastify's request object
304
+ * Get origin from fastify's request object
305
305
  *
306
306
  * @method
307
307
  * @param {Object} req
@@ -314,6 +314,16 @@ async function factory (pkgName) {
314
314
  return `${req.protocol}://${host}`
315
315
  }
316
316
 
317
+ /**
318
+ * Get hostname from fastify's request object
319
+ *
320
+ * @param {Object} req
321
+ * @returns {string}
322
+ */
323
+ getHostname = (req) => {
324
+ return req.hostname.split(':')[0]
325
+ }
326
+
317
327
  /**
318
328
  * Get plugin by prefix
319
329
  *
@@ -558,6 +568,54 @@ async function factory (pkgName) {
558
568
  })
559
569
  return text
560
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
+ }
561
619
  }
562
620
 
563
621
  return Waibu
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.4.1",
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,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-02-18
4
+
5
+ - [2.6.0] Move attribute functions from ```waibu-mpa```
6
+
7
+ ## 2026-02-17
8
+
9
+ - [2.5.0] Add ```getHostname()```
10
+
3
11
  ## 2026-02-16
4
12
 
5
13
  - [2.4.1] Bug fix on page with features