Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/node-red/node_modules/command-line-usage/lib/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const Table = require('table-layout')
const ansi = require('ansi-escape-sequences')
const t = require('typical')
class Content {
constructor (content) {
this._content = content
}
lines () {
const content = this._content
const defaultPadding = { left: ' ', right: ' ' }
if (content) {
/* string content */
if (t.isString(content)) {
const table = new Table({ column: ansi.format(content) }, {
padding: defaultPadding,
maxWidth: 80
})
return table.renderLines()
/* array of strings */
} else if (Array.isArray(content) && content.every(t.isString)) {
const rows = content.map(string => ({ column: ansi.format(string) }))
const table = new Table(rows, {
padding: defaultPadding,
maxWidth: 80
})
return table.renderLines()
/* array of objects (use table-layout) */
} else if (Array.isArray(content) && content.every(t.isPlainObject)) {
const table = new Table(content.map(row => ansiFormatRow(row)), {
padding: defaultPadding
})
return table.renderLines()
/* { options: object, data: object[] } */
} else if (t.isPlainObject(content)) {
if (!content.options || !content.data) {
throw new Error('must have an "options" or "data" property\n' + JSON.stringify(content))
}
const options = Object.assign(
{ padding: defaultPadding },
content.options
)
/* convert nowrap to noWrap to avoid breaking compatibility */
if (options.columns) {
options.columns = options.columns.map(column => {
if (column.nowrap) {
column.noWrap = column.nowrap
delete column.nowrap
}
return column
})
}
const table = new Table(
content.data.map(row => ansiFormatRow(row)),
options
)
return table.renderLines()
} else {
const message = `invalid input - 'content' must be a string, array of strings, or array of plain objects:\n\n${JSON.stringify(content)}`
throw new Error(message)
}
}
}
}
function ansiFormatRow (row) {
for (const key in row) {
row[key] = ansi.format(row[key])
}
return row
}
module.exports = Content
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0074 ]-- |