[tested on Node 10, 12, 14, LTS and Latest Stable]
Glance
Glance is a Node library for simplifying objects. It allows you to cut off arrays after a certain number and to cap objects after a certain depth is reached.
Glance has no dependencies and is only about 100 loc.
I use it for debugging big JSON responses mainly, but it‘s very general so there are definitely other usecases.
// It can make this a: 1 2 3 4 5 ... 500 b: c: d: hello: 'world' e: 123 // Look like this a: 123 '497 more...' b: c: '{...}' e: '[...]'
You control the depth and how much glance removes from arrays.
Installation
npm install glancejs --save-dev
Usage
Node
// Node 13+. I for one welcome our ESM overlords. // Alt. if using CommonJS (CJS) modules// const { glance } = require('glance') const obj = a: b: c: 'c' ;console // You can also pass in an optional options object as a second parameter.
Browser
Take a look at browser.example.html
Reference
The glance function takes an object
or array
as it‘s first parameter and then an optional options object as it‘s second parameter.
Examples
All of the following are perfectly valid ways to call glance.
Contributing
Anyone is welcome to contribute. Please open a github issue for bugs, improvements and new features.
If you are opening a PR please run npx standard --fix
and make sure all the tests are passing before opening a PR.