diff --git a/lib/helpers.js b/lib/helpers.js new file mode 100644 index 0000000..d8c3e5d --- /dev/null +++ b/lib/helpers.js @@ -0,0 +1,10 @@ +const _get = (obj, path, defaultValue = null) => + String.prototype.split + .call(path, /[,[\].]+?/) + .filter(Boolean) + .reduce( + (a, c) => (Object.hasOwnProperty.call(a, c) ? a[c] : defaultValue), + obj + ); + +module.exports = { _get };