value-inspector
v1.0.2
Published
Get a string representation of a value or an object. Pretty much like they look in Chrome DevTools.
Downloads
4
Maintainers
Readme
value-inspector
Get a string representation of a value or an object. Pretty much like they look in Chrome DevTools.
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
Typedefs
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 | Description | | ----- | ------------------- | -------------------------------------------- | | depth | number | Specify levels to expand arrays and objects. |
License
MIT. See license file.