npm

Share private packages across your team with npm Orgs, now with simplified billing via the aws marketplace!Learn more »

just-safe-get

2.0.0 • Public • Published

just-safe-get

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

Try it now

import get from 'just-safe-get';
 
const obj = {a: {aa: {aaa: 2}}, b: 4};
 
get(obj, 'a.aa.aaa'); // 2
get(obj, ['a', 'aa', 'aaa']); // 2
 
get(obj, 'b.bb.bbb'); // undefined
get(obj, ['b', 'bb', 'bbb']); // undefined
 
get(obj.a, 'aa.aaa'); // 2
get(obj.a, ['aa', 'aaa']); // 2
 
get(obj.b, 'bb.bbb'); // undefined
get(obj.b, ['bb', 'bbb']); // undefined
 
get(obj.b, 'bb.bbb', 5); // 5
get(obj.b, ['bb', 'bbb'], true); // true
 
get(null, 'a'); // undefined
get(undefined, ['a']); // undefined
 
get(null, 'a', 42); // 42
get(undefined, ['a'], 42); // 42
 
const obj = {a: {}};
const sym = Symbol();
obj.a[sym] = 4;
get(obj.a, sym); // 4

install

npm i just-safe-get

Downloadsweekly downloads

1,111

version

2.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability