invoice-fs
Version:
Nostalgic command-line invoicing application producing plain text invoices and JSON data structures. Uses the file system as a database
80 lines (71 loc) • 2.09 kB
JavaScript
var colors = require('colors');
/**
* To differentiate between an accidental and actual use of console log
*
* @param {*} output
*/
exports.write = function(output) {
console.log(output);
};
exports.error = function(output) {
exports.write("\n" + exports.divider("=", 60).red);
exports.write("ERROR: ".red + output.toString().red);
exports.write(exports.divider("=", 60).red + "\n");
};
exports.notification = function(output) {
exports.write("\n" + exports.divider("=", 60).yellow);
exports.write(exports.centeredColumn(output.toString().yellow, 67));
exports.write(exports.divider("=", 60).yellow + "\n");
};
exports.writeCliTitle = function(title) {
exports.write("\n"+title+"\n".bold + exports.divider("=", 60).dim.grey);
};
exports.writeCliDivider = function() {
exports.write(exports.divider("=", 60).dim.grey + "\n");
};
/**
* Creates a left aligned column at a specified width
*
* @param {String} text
* @param {Integer} width
* @returns {string}
*/
exports.leftColumn = function(text, width) {
return text + new Array(width - text.length + 1).join(' ');
};
/**
* Creates a right aligned column at a specified width
*
* @param {String} text
* @param {Integer} width
* @returns {string}
*/
exports.rightColumn = function(text, width) {
var columnPad = width - text.length + 1;
if (columnPad < 0) {
return text.slice(0, columnPad);
} else {
return new Array(width - text.length + 1).join(' ') + text;
}
};
/**
* Creates a center aligned column at a specified width
*
* @param {String} text
* @param {Integer} width
* @returns {string}
*/
exports.centeredColumn = function(text, width) {
var offset = new Array(parseInt((width - text.length + 2) / 2, 10)).join(' ');
return offset + text + offset + (text.length < width && text.length % 2 ? " " : "");
};
/**
* Create a divider of char at a specified width
*
* @param {String} char
* @param {Integer} width
* @returns {String}
*/
exports.divider = function(char, width) {
return new Array(width + 1).join(char);
};