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

args2object

v0.1.2

Published

Node/JavaScript library to access an item in an object structure given function arguments as path.

Downloads

4

Readme

args2object

Node/JavaScript library to access an item in an object structure given function arguments as path.

Install in Node

$ npm install args2object

Manual installation for Browser apps

Take the browserified file at dist/args2object.bundle.js and include it in your HTML:

<script src='js/args2object.bundle.js'></script>

The browserified file exports the window.args2object function.

Usage

var args2object = require('args2object');  // if Node

var myObject = {
  a: true,
  b: false,
  c: 'hello',
  d: {
    d1: 'foo',
    d2: [1,2,3,4]
  },
  true: {
    false: 0,
    bar: null
  }
};


var getter = args2object(myObject);

getter('a');             // => true
getter('b');             // => false
getter('c');             // => 'hello'
getter('d','d1');        // => 'foo'
getter('d','d2');        // => [1,2,3,4]
getter(true,false);      // => 0
getter(true,'bar');      // => null

getter('a','a1');        // => undefined
getter('a','a1','a11');  // => undefined
getter('e');             // => undefined
getter('e','e1');        // => undefined
getter(null,true,false); // => undefined

getter();                // => the full object


var getter = args2object(myObject, {failOnNotFound: true});

getter('a','a1');        // => throws an Error exception
getter('a','a1','a11');  // => throws an Error exception
getter('e');             // => throws an Error exception
getter('e','e1');        // => throws an Error exception
getter(false);           // => throws an Error exception

API

getter = args2object(object, options)

  • param {Object|Function} object: The object to handle.
  • param {Object} options (optional):
    • {Boolean} failOnNotFound: Whether to throw an Error if the searched path does not exist in the object structure (default: false).

Returns a getter function.

getter(a,b,c)

Retrieve the value at object[a][b][c].

If the path does not exist it returns undefined (or throws an Error if options.failOnNotFound is set).

Release History

0.1.1 (2014-11-20)

  • Make it much more robust and allow retrieving the full object.

0.1.0 (2014-11-14)

  • First release.

License

Copyright (c) 2014 Iñaki Baz Castillo Licensed under the MIT license.