Dumper.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Generated by CoffeeScript 1.12.4
  2. var Dumper, Inline, Utils;
  3. Utils = require('./Utils');
  4. Inline = require('./Inline');
  5. Dumper = (function() {
  6. function Dumper() {}
  7. Dumper.indentation = 4;
  8. Dumper.prototype.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
  9. var i, key, len, output, prefix, value, willBeInlined;
  10. if (inline == null) {
  11. inline = 0;
  12. }
  13. if (indent == null) {
  14. indent = 0;
  15. }
  16. if (exceptionOnInvalidType == null) {
  17. exceptionOnInvalidType = false;
  18. }
  19. if (objectEncoder == null) {
  20. objectEncoder = null;
  21. }
  22. output = '';
  23. prefix = (indent ? Utils.strRepeat(' ', indent) : '');
  24. if (inline <= 0 || typeof input !== 'object' || input instanceof Date || Utils.isEmpty(input)) {
  25. output += prefix + Inline.dump(input, exceptionOnInvalidType, objectEncoder);
  26. } else {
  27. if (input instanceof Array) {
  28. for (i = 0, len = input.length; i < len; i++) {
  29. value = input[i];
  30. willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
  31. output += prefix + '-' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
  32. }
  33. } else {
  34. for (key in input) {
  35. value = input[key];
  36. willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
  37. output += prefix + Inline.dump(key, exceptionOnInvalidType, objectEncoder) + ':' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
  38. }
  39. }
  40. }
  41. return output;
  42. };
  43. return Dumper;
  44. })();
  45. module.exports = Dumper;