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

propget

v1.1.0

Published

Use dot notation to get properties from deeply nested object and array structures.

Downloads

11,050

Readme

propget

Propget is a small helper utility for finding values/keys in deeply nested objects without having to worry about undefined properties and what not. It uses a human readable dot based notation to find items in your object or array.

Installation

Just install it through npm, like you do with the all your code:

npm install --save propget

It doesn't use any fancy node.js magic or ES6 so it should be good to go for browser usage as well using something as browserify.

Usage

Using the module is super simple. We export the propget method as default function:

var propget = require('propget');

The function accepts the following arguments:

  • object, data structure that we need to walk.
  • string, dot notated string for deeply nested object access.
  • .., rest arguments that will be used for optional function calls.

So accessing a complex data structure can be as easy as this:

'use strict';

var prop = require('propget')
  , data = { hello: 'world', yo: { deeply: ['nested', 'arrays'] } };

prop(data, 'hello'); // world
prop(data, 'yo.deeply.1'); // arrays
prop(data, 'yo.deeply.nested.unknown.keys'); // undefined

Function execution

Of one the unique functions of this module is that it allows you to execute functions that are inside data structure. We can then re-use the result of the function and walk it further.

data = { 
  hello: { 
    world: function () { 
      return { 
        hi: 'hello'
      };
    }
  }
};

prop(data, 'hello.world().hi') // hello

But in addition to simple function execution we can also call these functions with arguments. We automatically use the additionally supplied arguments to the propget method for this.

data = { 
  hello: { 
    world: function (arg) { 
      return { 
        hi: arg
      };
    }
  }
};

prop(data, 'hello.world(what).hi', 'additional') // additional

License

MIT