added helpers lib

This commit is contained in:
Martín M
2019-06-26 21:49:09 -03:00
parent 9d655c93eb
commit a5e338d1ef

10
lib/helpers.js Normal file
View File

@@ -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 };