mirror of
https://github.com/vvsviridov/enm-cli.git
synced 2025-10-23 00:12:23 +00:00
34 lines
1.0 KiB
JavaScript
Executable File
34 lines
1.0 KiB
JavaScript
Executable File
const chalk = require('chalk')
|
|
|
|
|
|
function transformAttributes(element) {
|
|
if (Array.isArray(element)) {
|
|
return element.map(item => transformAttributes(item))
|
|
}
|
|
if (Array.isArray(element.value)) {
|
|
return { [element.key]: transformAttributes(element.value) }
|
|
}
|
|
return element.key ? { [element.key]: element.value } : element
|
|
}
|
|
|
|
|
|
function colorize(attributes) {
|
|
const sorted = attributes.sort ? attributes.sort((a, b) => a.key < b.key ? -1 : 1) : attributes
|
|
return JSON.stringify(transformAttributes(sorted), null, 1)
|
|
.replace(/["(){}\[\]]/mg, '')
|
|
.replace(/^\s*,*\n/mg, '')
|
|
.replace(/,$/mg, '')
|
|
.replace(/^(\s{2}\w+):/mg, chalk.green('$1:'))
|
|
.replace(/^(\s{4}\w+):/mg, chalk.yellow('$1:'))
|
|
.replace(/^(\s{5}\w+):/mg, chalk.cyan('$1:'))
|
|
}
|
|
|
|
|
|
function logAttributes(fdn, attributes) {
|
|
const output = `
|
|
${chalk.yellow.bold('FDN')}: ${chalk.bold(fdn.replace(/\((\w+)\)/g, ''))}
|
|
${colorize(attributes)}`
|
|
console.log(output)
|
|
}
|
|
|
|
module.exports = logAttributes |