npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fmt-obj

v2.0.0

Published

Prettifies any javascript object in your console

Downloads

4,520

Readme

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