keypath

0.0.1 • Public • Published

Keypath

Easily access properties in nested objects and arrays using a dot notation syntax.

Installation

Install with NPM: $ npm install keypath

keypath(keypath, object/array[, callback/re-throw]);

Keypath only exposes one function, so require it and use it.

var keypath = require('keypath');
keypath('foo.bar.baz', object);

Keypath takes 2 or 3 arguments.

  • keypath: a string representing the value you want to access.

  • object: the object in which this value resides.

  • callback/rethrow: an optional argument that can be either a function or true. If you give it a function, this function will be called if an error occurs. The error itself will be the callbacks only argument.

    If you pass true any error will be re-thrown and you can catch it yourself.

    If left out keypath() will just return undefined.

Roadmap

I'd like to add setting, that'd be convinient, right? Also adding@avg and the like would be cool. If you don't know what that is read this excellent blogpost about that feature in Cocoa.

License

See LICENSE.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    25
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    25

Package Sidebar

Install

npm i keypath

Weekly Downloads

25

Version

0.0.1

License

ISC

Last publish

Collaborators

  • simme