Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fmt-obj

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fmt-obj

Prettifies any javascript object in your console

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
778
increased by14.58%
Maintainers
1
Weekly downloads
 
Created
Source

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

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

Screenshot

View Example

Installation

npm install --save fmt-obj

Or even better

yarn add fmt-obj

Import and Usage Example

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
  }
}))

API

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,
  annotation: chalk.red,
  property: chalk.yellow,
  literal: chalk.blue,
  number: chalk.green,
  string: chalk.bold
})

console.log(customFormat({ hello: 1.0 }))
Default color map
{
  punctuation: chalk.yellow,
  annotation: chalk.gray,
  property: chalk.green,
  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.

Author

fmt-obj © Fabian Eichenberger, Released under the MIT License.
Authored and maintained by Fabian Eichenberger with help from contributors (list).

GitHub @queckezz · Twitter @queckezz

Keywords

FAQs

Package last updated on 23 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc