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

undeep

v1.3.0

Published

Micro-library exposing deeply-nested members

Downloads

3

Readme

Undeep

Micro-library exposing deeply-nested members

Purpose

Attempting to access deeply nested values whose ancestors may not exist can cause undesirable errors. In many cases, it would be enough to know that the value is not defined. Undeep swallows these errors, returning the desired value or undefined.

Sometimes along the way we want to compute a key, e.g., the last index in an array, before continuing. Passing a key function allows us to do this. Key functions should be safe and side-effect-free; see caveats.

Install

$ npm install --save undeep

Usage

const undeep = require('undeep');

const target = {
  first: {
    second: [
      { bool: true },
    ],
  },
};

undeep(target);
// target
undeep(target, 'first');
// target.first
undeep(target, 'first', 'second', 0, 'bool', 'constructor', 'name');
// 'Boolean'
undeep(target, 'undef', 'cannot get properties of undefined');
// undefined
undeep(null, 'cannot get properties of null');
// undefined
undeep([0, 1, 2, 3, 4, 5], arr => arr.length >> 1);
// 3

API

undeep(target[, key1[, key2[, ...]]])

Returns deep members of a target object or undefined.

target

Starting object to be searched. Passing a non-object will search the implicit object wrapper.

key1, key2, ...

Keys to search for in order. Each returned value is searched for the following key. The function will return when keys are exhausted. If no keys are passed, the target is returned.

Keys may be computed from the preceeding value by passing a function instead of a primitive.

Caveats

Because it intentionally swallows errors, undeep should be used only for retrieving data which may not be defined. Any functions passed should be side-effect-free. Be aware that simply accessing some members can have side-effects, if they involve getter functions.

Each key should be a primitive value or function. Most objects passed as keys will be interpreted as "[object Object]" and as such will return the same member (if it is defined).

Underp

Instead of undefined, underp() logs (without throwing) any error it catches along the way. Underp should only be used for debugging.

License

ISC © N.D.Christie