From d26b174c89865707a30032328bac8d6c7c67ffed Mon Sep 17 00:00:00 2001 From: Dragomir Ivanov Date: Sun, 24 Nov 2019 11:33:02 -0800 Subject: [PATCH] Use more from `lodash`. Apply props to js array, much like the original `omitBy`. --- src/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 75f6cf2..93e4fd9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,7 @@ const omit = require("lodash/omit"); +const isNil = require("lodash/isNil"); +const isPlainObject = require("lodash/isPlainObject"); +const isFunction = require("lodash/isFunction"); module.exports = function omitDeepLodash(input, props) { function omitDeepOnOwnProps(obj) { @@ -6,7 +9,7 @@ module.exports = function omitDeepLodash(input, props) { return input; } - if (!Array.isArray(obj) && !isObject(obj)) { + if (!Array.isArray(obj) && !isPlainObject(obj)) { return obj; } @@ -27,16 +30,15 @@ module.exports = function omitDeepLodash(input, props) { } if (Array.isArray(input)) { - return input.map(omitDeepOnOwnProps); + return input + .filter((v, k) => { + if (isFunction(props)) { + return !props(v, k); + } + return v; + }) + .map(omitDeepOnOwnProps); } return omitDeepOnOwnProps(input); }; - -function isNil(value) { - return value === null || value === undefined; -} - -function isObject(obj) { - return Object.prototype.toString.call(obj) === "[object Object]"; -}