Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const util = require('util');
- const assert = require('assert');
- let complexObject = {complex: {object: {that: {is: ['really', 'deeply', {nested: ':('}]}}}};
- debugger;
- assert(complexObject !== null)
- try{
- assert(complexObject === 1)
- }
- catch (error){
- console.log(error)
- }
- console.log('stringify', JSON.stringify(complexObject, null, 2))
- let showHidden = true;
- let depth = 2;
- console.log('inspect - depth 2', util.inspect(complexObject, showHidden, depth))
- console.log('inspect - depth infinite', util.inspect(complexObject, {
- showHidden: true,
- depth : null
- }))
- /*
- Custom inspect function
- */
- class Box {
- constructor(value) {
- this.value = value;
- }
- inspect(depth, options) {
- if (depth < 0) {
- return options.stylize('[Box]', 'special');
- }
- const newOptions = Object.assign({}, options, {
- depth: options.depth === null ? null : options.depth - 1
- });
- // Five space padding because that's the size of "Box< ".
- const padding = ' '.repeat(5);
- const inner = util.inspect(this.value, newOptions).replace(/\n/g, '\n' + padding);
- return options.stylize('Box', 'special') + '< ' + inner + ' >';
- }
- }
- const box = new Box(true);
- console.log('Box object', util.inspect(box));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement