npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

prettier-inspect

1.0.0 • Public • Published

prettier-inspect NPM version NPM monthly downloads NPM total downloads Linux Build Status

Better inspect formatting, using prettier for arrays, objects and functions, and util.inspect for everything else.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Table of Contents

Details

Install

Install with npm:

$ npm install --save prettier-inspect

Usage

var inspect = require('prettier-inspect');
console.log(inspect(value[, options]));

Params

  • value - any javascript value
  • options - options to pass to prettier

Examples

The following examples are based on the default options.

Arrays

function fn( a, b ){return a + b}
console.log(inspect([{a: 'b', c: 'd', e: 'f', fn: fn}]));

Prints:

[
  {
    a: 'b',
    c: 'd',
    e: 'f',
    fn: function fn(a, b) {
      return a + b;
    }
  }
];

Buffers

console.log(inspect(new Buffer('foo')));
//=> <Buffer 66 6f 6f>

Dates

console.log(inspect(new Date()));
//=> 2017-12-01T21:33:21.938Z

Errors

console.log(inspect(new Error('this is an error!')));

Prints:

Error: this is an error!
    at Object.<anonymous> (/Users/foo/bar/examples.js:26:21)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Function.Module.runMain (module.js:682:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:613:3

Functions

function fn( a, b ){return a + b}
console.log(inspect(fn));

Prints:

function fn(a, b) {
  return a + b;
}

Numbers

console.log(inspect(9));
//=> 9

Objects

console.log(inspect({
  obj: {
  a: [ { foo: 'bar', baz: { qux: 'fez'}      }],
  c: 'd', e: 'f',
  g: function  (one, two){return one + two},
  h: {a: 'b', c: 'd'},
  regex: /^foo(?=bar)/g }
}));

Prints:

{
  obj: {
    a: [
      {
        foo: 'bar',
        baz: { qux: 'fez' }
      }
    ],
    c: 'd',
    e: 'f',
    g: function(one, two) {
      return one + two;
    },
    h: {
      a: 'b',
      c: 'd'
    },
    regex: /^foo(?=bar)/g
  }
};

Regular expressions

console.log(inspect(/^foo$/));
//=> /^foo$/

Strings

console.log(inspect('foo\nbar'));
//=> 'foo\nbar'

RegExp.exec and String.match arguments

console.log(inspect(/foo/.exec('foo')));
//=> [ 'foo', index: 0, input: 'foo' ]

Release history

See the changelog for updates.

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on December 01, 2017.

install

npm i prettier-inspect

Downloadsweekly downloads

6

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability