fmt.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. var util = require('util');
  12. // --------------------------------------------------------------------------------------------------------------------
  13. var sep = '===============================================================================';
  14. var line = '-------------------------------------------------------------------------------';
  15. var field = ' ';
  16. // --------------------------------------------------------------------------------------------------------------------
  17. // separator
  18. module.exports.separator = function() {
  19. console.log(sep);
  20. };
  21. // alias the above
  22. module.exports.sep = module.exports.separator;
  23. // line
  24. module.exports.line = function() {
  25. console.log(line);
  26. };
  27. // title
  28. module.exports.title = function(title) {
  29. var out = '--- ' + title + ' ';
  30. out += line.substr(out.length);
  31. console.log(out);
  32. };
  33. // field
  34. module.exports.field = function(key, value) {
  35. console.log('' + key + field.substr(key.length) + ' : ' + value);
  36. };
  37. // subfield
  38. module.exports.subfield = function(key, value) {
  39. console.log('- ' + key + field.substr(key.length + 2) + ' : ' + value);
  40. };
  41. // list item
  42. module.exports.li = function(msg) {
  43. console.log('* ' + msg);
  44. };
  45. // dump
  46. module.exports.dump = function(data, name) {
  47. if ( name ) {
  48. console.log(name + ' :', util.inspect(data, false, null, true));
  49. }
  50. else {
  51. console.log(util.inspect(data, false, null, true));
  52. }
  53. };
  54. // msg
  55. module.exports.msg = function(msg) {
  56. console.log(msg);
  57. };
  58. // --------------------------------------------------------------------------------------------------------------------