colorprint
Version:
Print ansi-colored message to stdout/stderr.
26 lines (20 loc) • 480 B
JavaScript
/**
* Add indent.
* @function indentMsg
* @param {string} msg - Message format.
* @param {number} depth - Depth to indent.
* @returns {string} - Indented message.
*/
const os = require('os')
const { EOL } = os
const TAB = ' '
/** @lends indentMsg */
function indentMsg (msg, depth) {
let indent = ''
for (let i = 0; i < depth; i++) {
indent += TAB
}
return indent + msg.replace(new RegExp(EOL, 'g'), EOL + indent)
}
module.exports = indentMsg