just-safe-get
Advanced tools
Comparing version 1.3.0 to 1.3.1
20
index.js
@@ -24,13 +24,19 @@ module.exports = get; | ||
function get(obj, props) { | ||
function get(obj, propsArg) { | ||
if (!obj) { | ||
return obj; | ||
} | ||
if (typeof props == 'string') { | ||
props = props.split('.'); | ||
var props, prop; | ||
if (Array.isArray(propsArg)) { | ||
props = propsArg.slice(0); | ||
} | ||
if (typeof props == 'symbol') { | ||
props = [props]; | ||
if (typeof propsArg == 'string') { | ||
props = propsArg.split('.'); | ||
} | ||
var prop; | ||
if (typeof propsArg == 'symbol') { | ||
props = [propsArg]; | ||
} | ||
if (!Array.isArray(props)) { | ||
throw new Error('props arg must be an array, a string or a symbol'); | ||
} | ||
while (props.length) { | ||
@@ -40,3 +46,3 @@ prop = props.shift(); | ||
if (!obj) { | ||
return obj; | ||
return void 0; | ||
} | ||
@@ -43,0 +49,0 @@ } |
{ | ||
"name": "just-safe-get", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "get value at property, don't throw if parent is undefined", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3264
42