From a5e338d1ef8de4b9a91222b5727deef316804a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20M?= Date: Wed, 26 Jun 2019 21:49:09 -0300 Subject: [PATCH] added helpers lib --- lib/helpers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/helpers.js 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 };