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

glancejs

v1.0.1

Published

A module for inspecting tricky objects.

Downloads

10

Readme

Build Status [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: [1,2,3]
  }
}

// Look like this
{
  a: [1,2,3, '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.
import { glance } from 'glance'

// Alt. if using CommonJS (CJS) modules
// const { glance } = require('glance')

const obj = {
  a: {
    b: {
      c: 'c'
    }
  }
};
console.log(glance(obj))

// You can also pass in an optional options object as a second parameter.
glance(obj, { depth: 2, arrayMax: 3 })

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.

glance(obj, {
  depth: 1                // Defaults to 1. How deep do you want to dig?
  arrayMax: undefined     // Not required. Max nr of items in arrays. Rest
                          // are sliced off. Adds a string to end of array
                          // telling you how many items were sliced off.
})

Examples

All of the following are perfectly valid ways to call glance.

glance({ a: 'a' })
glance([1, 2, 3])
glance([1, 2, 3], { arrayMax: 1 })
glance({ a: { b: { c: 'c' }}}, { depth: 0 })
glance({ a: [1, 2, 3] }, { depth: 4, arrayMax: 2 })

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.

License

ISC