-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgetOmitDeep.js
52 lines (47 loc) · 1.26 KB
/
getOmitDeep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
var getFilterDeep = require('./getFilterDeep.js');
var getPathMatches = require('./getPathMatches.js');
function getOmitDeep(_) {
var pathMatches = getPathMatches(_);
var filterDeep = getFilterDeep(_);
function omitDeep(obj, paths, options) {
options = _.merge(
{
invert: false,
},
options || {}
);
var isOmit = !options.invert;
options = _.merge(
{
onMatch: {
cloneDeep: false,
skipChildren: false,
keepIfEmpty: !isOmit,
},
onNotMatch: {
cloneDeep: false,
skipChildren: false,
keepIfEmpty: isOmit,
},
},
options
);
options.leavesOnly = false;
options.childrenPath = undefined;
options.includeRoot = undefined;
options.pathFormat = 'array';
options.onTrue = options.invert ? options.onMatch : options.onNotMatch;
options.onFalse = options.invert ? options.onNotMatch : options.onMatch;
var test = function (value, key, parent, context) {
if (pathMatches(context.path, paths) !== false) {
return options.invert;
} else {
return !options.invert;
}
};
return filterDeep(obj, test, options);
}
return omitDeep;
}
module.exports = getOmitDeep;