value-inspector

Get a string representation of a value or an object. Pretty much like they look in Chrome DevTools.


Keywords
object, inspect, stringify, inspector, util.inspect, prettify
License
MIT
Install
npm install value-inspector@1.0.0

Documentation

value-inspector

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Get a string representation of a value or an object. Pretty much like they look in Chrome DevTools.

paypal coinbase twitter

Installation

npm install value-inspector

Usage

import inspect from "value-inspector";

const obj = {
  primitiveNull: null,

  valueUndefined: undefined,

  booleanTrue: true,

  textString: "a string",
  textRegExp: new RegExp("$ 🐈"),

  numberZero: 0,
  numberOne: 1,

  obj: {
    zero: 0,
    one: { two: 2, three: { four: 4 } },
  },

  fun() {},

  array: [0, 1],
  arrayTyped: Float32Array.of(0, 1),

  collectionMap: new Map([
    [0, "zero"],
    [1, "one"],
  ]),
  collectionSet: new Set([0, 1]),
  [Symbol("bar")]: "symbol-bar-value",

  promise: Promise.resolve(),
};

inspect(obj);

// =>
// {
//   array: (2)[0, 1]
//   arrayTyped: Float32Array(2)[0, 1]
//   booleanTrue: true
//   circularArray: [Circular]
//   circularObject: [Circular]
//   collectionMap: [object Map]
//   collectionSet: [object Set]
//   fun: [Function: fun]
//   numberOne: 1
//   numberZero: 0
//   obj: {
//     one: {
//       three: [object Object],
//       two: 2
//     },
//     zero: 0
//   }
//   primitiveNull: null
//   promise: Promise {}
//   textRegExp: /\$ 🐈/
//   textString: "a string"
//   valueUndefined: undefined
//   Symbol(bar): "symbol-bar-value"
// }

API

Functions

inspect(value, [options])string

Inspect a value.

Typedefs

Options : object

inspect(value, [options]) ⇒ string

Inspect a value.

Kind: global function Returns: string - A string representation of a value or an object.

Param Type
value *
[options] Options

Options : object

Kind: global typedef Properties

Name Type Default Description
[depth] number 2 Specify levels to expand arrays and objects.
[stringLength] number Number.POSITIVE_INFINITY Length to truncate strings.
[collectionLength] number Number.POSITIVE_INFINITY Length to slice arrays, Map and Set.
[objectLength] number Number.POSITIVE_INFINITY Length to truncate object keys.

License

MIT. See license file.