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

  • 2.0.0
  • latest
  • 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

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

Screenshot

View Example

Also check out the CLI version made by @Kikobeats

Features

  • Circular reference support :sparkles:
  • Allows for custom formatting
  • Supports any arbitrary javascript token (functions, strings, numbers, arrays, you name it!)

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

format(obj, depth = Infinity)

Prettifies obj with optional depth.

obj

Any arbitrary javascript object.

depth (optional)

Colapses all properties deeper than specified by depth.

createFormatter({ offset = 2, formatter = identityFormatter })

Create a custom format function if you need more control of how you want to format the tokens.

opts.formatter (optional)

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 or undefined
  • 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
  }
})
opts.offset (optional)

The amount of left whitespace between the property key and all of it's sub-properties.

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 22 May 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