💄 Prettifies any javascript object in your console. Make it look awesome!
Screenshot
Also check out the
CLI version
made by @Kikobeats
- Circular reference support ✨
- Allows for custom formatting
- Supports any arbitrary javascript token (functions, strings, numbers, arrays, you name it!)
npm install --save fmt-obj
Or even better
yarn add fmt-obj
const format = require('fmt-obj')
console.log(format({
message: 'hello world',
dev: true,
awesomeness: 9.99,
body: {
these: null,
are: 'string',
some: 12,
props: false
}
}))
Prettifies obj
with optional depth
.
Any arbitrary javascript object.
Colapses all properties deeper than specified by depth
.
Create a custom format function if you need more control of how you want to format the tokens.
fmt-obj
uses chalk
for it's default format function. A formatter is mostly used for colors but can be used to manipulate anything.
Example with rounding numbers
const format = createFormatter({ number: Math.round })
format({ num: 12.49 }) // -> num: 12
The following tokens are available:
- punctuation - The characters sorrounding your data:
:
and"
- literal - Either
true
,false
,null
orundefined
- annotation - Type annotation for errors, functions and circular references like
[Function {name}]
- property
- string
- number
Example with a custom color map
const { createFormatter } = require('fmt-obj')
const format = createFormatter({
offset: 4,
formatter: {
punctuation: chalk.cyan,
annotation: chalk.red,
property: chalk.yellow,
literal: chalk.blue,
number: chalk.green,
string: chalk.bold
}
})
The amount of left whitespace between the property key and all of it's sub-properties.
(Because package discovery is hard)
pretty-format
by @thejameskyle for additional ES6 type support (WeakMap, WeakSet, Symbol etc.) and more consistent output.
fmt-obj © Fabian Eichenberger, Released under the MIT License.
Authored and maintained by Fabian Eichenberger with help from contributors (list).