• Stars
    star
    441
  • Rank 95,653 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Stringifies any javascript object in your console for CLI inspection ✨

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

πŸ’„ 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 ✨
  • 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

More Repositories

1

koa-views

Template rendering middleware for koa (hbs, swig, pug, anything! ✨)
JavaScript
713
star
2

elementx

⚑ Functionally create DOM elements and compose them to a tree quickly
JavaScript
63
star
3

preact-hyperscript

Hyperscript-like syntax for creating Preact elements
JavaScript
31
star
4

veel

Base react styling components using fela with a design system
JavaScript
26
star
5

watch-run

[Deprecated] Re-execute a given command everytime something changes in a specific directory
JavaScript
23
star
6

inspect-json

πŸ”¦ Robust manipulation and inspection of JSON data using the already familiar Chromium Devtools
JavaScript
14
star
7

co-walk

walk a file tree and return a list of files
JavaScript
8
star
8

hscript

Cli for converting html to hyperscript and the other way around.
JavaScript
8
star
9

pwdx

A simple, stateless and reproducable password generator made for developers
TypeScript
7
star
10

parse-hyperscript

Parse hyperscript-like syntax for creating dom or virtual-dom nodes
JavaScript
6
star
11

hyperapp-to-html

Serialize hyperapp virtual nodes to html strings
JavaScript
5
star
12

preact-element

A simpler element creation function (h) for preact
JavaScript
5
star
13

untar-memory

Untar a tarball to an in-memory filesystem
JavaScript
5
star
14

json-tokenize

Splits a JSON string into an annotated list of tokens
JavaScript
5
star
15

simplex-noise-playground

[Experiment] [W.I.P] Random terrain generation using simplex noise
JavaScript
4
star
16

react-nanobar

Nanobar wrapped up as a React component
JavaScript
4
star
17

co-sse-events

Stream Server-Sent Events from an emitter
JavaScript
4
star
18

expand-spacings

Expands `margin` and `padding` css properties to their long form
JavaScript
4
star
19

pull-promise

Pull the value from a promise using pull-streams
JavaScript
4
star
20

folder-clean

Analyzes and potentially deletes all files and folders which are older than a given date
JavaScript
4
star
21

weight-plate-calculator

Webapp for calculating the weight plates you need for the barbell or weight belt
JavaScript
4
star
22

object-flatten

Flatten a nested object based on a predicate function
JavaScript
3
star
23

fs-from-object

Create files and folders in the filesystem directly from an object
JavaScript
3
star
24

uniq-with

Remove duplicates based on a predicate function
JavaScript
3
star
25

bbb-resources

This repository contains documentation and self-made versions of the assignments given at the BBB
Java
3
star
26

global-undom

Run browser-specific code in node using undom
JavaScript
3
star
27

koa-random-sse

Sends random sse events, mainly for testing applications or modules
JavaScript
2
star
28

ripple-router

Router for ripplejs
JavaScript
2
star
29

error-stack

extracts useful information from an error stack and allows you to skip certain steps
JavaScript
1
star
30

compose

Compose two or more functions together
JavaScript
1
star
31

ms-parse

Parse milliseconds to an object containing corresponding milliseconds, seconds, hours and days
Julia
1
star
32

elm-from-scratch

Elm London Meetup 11.07.2016 Hacker News Reader
Elm
1
star
33

component-roole

Use the awesome roole css pre-processor in your components
JavaScript
1
star
34

grid

Simple responsive css grid based on flexbox
CSS
1
star
35

reset

Minimal reset for modern web apps that gives you a clean consistent state.
CSS
1
star
36

builder-css-whitespace

css-whitespace plugin for component-builder2.js
JavaScript
1
star
37

koa-views-issue-57

koa-views example repo for issue #57
JavaScript
1
star
38

transducer-protocol

Official protocol for transducers
JavaScript
1
star
39

ms-pretty

Parse milliseconds to something more human-readable
Julia
1
star
40

get-windows-env

Get a list of system or user environment variables on windows
JavaScript
1
star