Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. const util = require('util');
  2. const assert = require('assert');
  3.  
  4. let complexObject = {complex: {object: {that: {is: ['really', 'deeply', {nested: ':('}]}}}};
  5.  
  6. debugger;
  7.  
  8. assert(complexObject !== null)
  9.  
  10. try{
  11. assert(complexObject === 1)
  12. }
  13. catch (error){
  14. console.log(error)
  15. }
  16.  
  17. console.log('stringify', JSON.stringify(complexObject, null, 2))
  18. let showHidden = true;
  19. let depth = 2;
  20. console.log('inspect - depth 2', util.inspect(complexObject, showHidden, depth))
  21. console.log('inspect - depth infinite', util.inspect(complexObject, {
  22. showHidden: true,
  23. depth : null
  24. }))
  25.  
  26.  
  27. /*
  28. Custom inspect function
  29. */
  30. class Box {
  31. constructor(value) {
  32. this.value = value;
  33. }
  34.  
  35. inspect(depth, options) {
  36. if (depth < 0) {
  37. return options.stylize('[Box]', 'special');
  38. }
  39.  
  40. const newOptions = Object.assign({}, options, {
  41. depth: options.depth === null ? null : options.depth - 1
  42. });
  43.  
  44. // Five space padding because that's the size of "Box< ".
  45. const padding = ' '.repeat(5);
  46. const inner = util.inspect(this.value, newOptions).replace(/\n/g, '\n' + padding);
  47. return options.stylize('Box', 'special') + '< ' + inner + ' >';
  48. }
  49. }
  50.  
  51.  
  52. const box = new Box(true);
  53.  
  54. console.log('Box object', util.inspect(box));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement