0.0.1 • Published 12 years ago
jasonkuhrt-get v0.0.1
get
Safely, succinctly, access hash data
Installation
npm install jasonkuhrt-getAPI
get(path, object)
path
- May be a
Stringor[String].
object
- Any object.
return
- If
pathlookup fails, the last found value. - If
pathlookup totally fails (not a single found key frompathinobject), the givenobject. - If given
objectis not actually an object,{}.
Examples
Access object properties in String or Array style:
var o = {a: { b: c: 'c' } };
get('a.b.c', o) === get(['a','b','c'], o); // trueget is curried to allow creation of accessors on the fly:
var ids = users.map(get('id')); // e.g. [1, 45, 82, 8392, ...etc]For mroe see tests.
0.0.1
12 years ago