Prettifies any javascript object in your console. Make it look awesome! 💄

fmt-obj Build status NPM version Dependency Status License Js Standard Style

Prettifies any javascript object in your console. Make it look awesome! 💄


View Example


npm install --save fmt-obj

Or even better

yarn add fmt-obj

Import and Usage Example

const format = require('fmt-obj')

  message: 'hello world',
  dev: true,
  awesomeness: 9.99,
  body: {
    these: null,
    are: 'string',
    some: 12,
    props: false


fmtObj(obj, depth = Infinity, formatter = defaultFormatter, offset = 2)

Prettifies obj given a formatter map with optional depth.

depth (optional)

Objects deeper than depth will get collapsed and hide their sub properties.

formatter (optional)

fmt-obj uses chalk behind the scenes. You can tweak the color mapping by the following tokens:

  • punctuation - The characters sorrounding your data: : and "
  • literal - Either true, false, null or undefined
  • annotation - Type annotation for errors, functions and circular references like [Function {name}]
  • property
  • string
  • number

Here is an example of using a custom color map:

const format = require('fmt-obj')
const chalk = require('chalk')

const customFormat = (...args) => format(...args, {
  punctuation: chalk.cyan,
  property: chalk.yellow,
  string: chalk.bold

console.log(customFormat({ hello: 1.0 }))
Default color map
  punctuation: chalk.yellow,
  annotation: chalk.gray,
  literal: chalk.magenta,
  number: chalk.cyan,
  string: chalk.bold

offset (optional)

The amount of whitespace after the object gets displayed.

Similar packages

(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).

GitHub @queckezz · Twitter @queckezz