UNPKG

2.09 kBJavaScriptView Raw
1// --------------------------------------------------------------------------------------------------------------------
2//
3// fmt.js - Command line output formatting.
4//
5// Copyright (c) 2012 Andrew Chilton - http://chilts.org/
6// Written by Andrew Chilton <andychilton@gmail.com>
7//
8// License: http://opensource.org/licenses/MIT
9//
10// --------------------------------------------------------------------------------------------------------------------
11
12var util = require('util');
13
14// --------------------------------------------------------------------------------------------------------------------
15
16var sep = '===============================================================================';
17var line = '-------------------------------------------------------------------------------';
18var field = ' ';
19
20// --------------------------------------------------------------------------------------------------------------------
21
22// separator
23module.exports.separator = function() {
24 console.log(sep);
25};
26
27// alias the above
28module.exports.sep = module.exports.separator;
29
30// line
31module.exports.line = function() {
32 console.log(line);
33};
34
35// title
36module.exports.title = function(title) {
37 var out = '--- ' + title + ' ';
38 out += line.substr(out.length);
39 console.log(out);
40};
41
42// field
43module.exports.field = function(key, value) {
44 console.log('' + key + field.substr(key.length) + ' : ' + value);
45};
46
47// subfield
48module.exports.subfield = function(key, value) {
49 console.log('- ' + key + field.substr(key.length + 2) + ' : ' + value);
50};
51
52// list item
53module.exports.li = function(msg) {
54 console.log('* ' + msg);
55};
56
57// dump
58module.exports.dump = function(data, name) {
59 if ( name ) {
60 console.log(name + ' :', util.inspect(data, false, null, true));
61 }
62 else {
63 console.log(util.inspect(data, false, null, true));
64 }
65};
66
67// msg
68module.exports.msg = function(msg) {
69 console.log(msg);
70};
71
72// --------------------------------------------------------------------------------------------------------------------