@mattduffy/banner 1.0.0 → 1.0.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/package.json +1 -1
- package/src/index.js +29 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -20,7 +20,10 @@ export class Banner {
|
|
|
20
20
|
#appName
|
|
21
21
|
#arch
|
|
22
22
|
#bannerText
|
|
23
|
-
#
|
|
23
|
+
#borderGlyphGET = '#'
|
|
24
|
+
#borderGlyphPUT = '&'
|
|
25
|
+
#borderGlyphPOST = '@'
|
|
26
|
+
#borderGlyphDELETE = '*'
|
|
24
27
|
#lineStarts = []
|
|
25
28
|
#lines = []
|
|
26
29
|
#local
|
|
@@ -56,7 +59,7 @@ export class Banner {
|
|
|
56
59
|
|
|
57
60
|
if (strings) {
|
|
58
61
|
this.#appName = strings.name
|
|
59
|
-
this.#
|
|
62
|
+
this.#borderGlyphGET = strings?.borderGlyph ?? this.#borderGlyphGET
|
|
60
63
|
this.#localPort = strings?.localPort ?? null
|
|
61
64
|
this.#local = `${strings.local}${(this.#localPort) ? ':' + this.#localPort : ''}`
|
|
62
65
|
this.#public = strings.public
|
|
@@ -116,7 +119,7 @@ export class Banner {
|
|
|
116
119
|
+ this.archLine.length, ' ')
|
|
117
120
|
this.#lines[4] = this.archLine
|
|
118
121
|
|
|
119
|
-
const g = this.#
|
|
122
|
+
const g = this.#borderGlyphGET
|
|
120
123
|
this.#bannerText =
|
|
121
124
|
`${g}${g.padEnd(this.longestLine + 5, g)}${g}\n`
|
|
122
125
|
+ `${g} ${' '.padEnd(this.longestLine + 2, ' ')} ${g}\n`
|
|
@@ -203,7 +206,7 @@ export class Banner {
|
|
|
203
206
|
* @param { string } glyph - The border glyph character of the banner.
|
|
204
207
|
*/
|
|
205
208
|
set borderGlyph(glyph) {
|
|
206
|
-
this.#
|
|
209
|
+
this.#borderGlyphGET = glyph
|
|
207
210
|
if (this.#appName && this.#local && this.#public) {
|
|
208
211
|
this.#compose()
|
|
209
212
|
}
|
|
@@ -256,11 +259,31 @@ export class Banner {
|
|
|
256
259
|
const _log = log ?? console.log
|
|
257
260
|
const _error = error ?? console.error
|
|
258
261
|
_log('adding request banner to the app.')
|
|
259
|
-
const
|
|
262
|
+
const gGET = this.#borderGlyphGET
|
|
263
|
+
const gPUT = this.#borderGlyphPUT
|
|
264
|
+
const gPOST = this.#borderGlyphPOST
|
|
265
|
+
const gDEL = this.#borderGlyphDELETE
|
|
260
266
|
const n = this.#appName
|
|
261
267
|
return async function banner(ctx, next){
|
|
262
268
|
try {
|
|
263
|
-
const _g = (/post/i.test(ctx.request.method)) ? '@' : g
|
|
269
|
+
// const _g = (/post/i.test(ctx.request.method)) ? '@' : g
|
|
270
|
+
let _g
|
|
271
|
+
switch(ctx.request.method.toLowerCase()) {
|
|
272
|
+
case 'get':
|
|
273
|
+
_g = gGET
|
|
274
|
+
break
|
|
275
|
+
case 'post':
|
|
276
|
+
_g = gPOST
|
|
277
|
+
break
|
|
278
|
+
case 'put':
|
|
279
|
+
_g = gPUT
|
|
280
|
+
break
|
|
281
|
+
case 'delete':
|
|
282
|
+
_g = gDEL
|
|
283
|
+
break
|
|
284
|
+
default:
|
|
285
|
+
_g = gGET
|
|
286
|
+
}
|
|
264
287
|
const _urlLabel = `${ctx.request.method}:`
|
|
265
288
|
const _url = `${ctx.request.header.host}${ctx.request.url}`
|
|
266
289
|
const _urlLine = `${_urlLabel} ${_url}`
|