@@ -26,13 +26,14 @@ module.exports.deepMerge = deepMerge;
2626 *
2727 * @param {object|Array } source - source object
2828 * @param {object|Array } target - target object
29+ * @param {Array<string> } [requiredFields] - fields to leave in diff object
2930 * @returns {object }
3031 */
31- function deepDiff ( source , target ) {
32+ function deepDiff ( source , target , requiredFields = [ ] ) {
3233 if ( typeOf ( target ) === 'array' ) {
3334 return arrayDiff ( source , target ) ;
3435 } else if ( typeOf ( target ) === 'object' ) {
35- return objectDiff ( source , target ) ;
36+ return objectDiff ( source , target , requiredFields ) ;
3637 } else if ( source !== target ) {
3738 return target ;
3839 } else {
@@ -62,10 +63,11 @@ function arrayDiff(source, target) {
6263 *
6364 * @param {object } objectA - first object for comparing
6465 * @param {object } objectB - second object for comparing
66+ * @param {Array<string> } requiredFields - fields to leave
6567 *
6668 * @returns {object }
6769 */
68- function objectDiff ( objectA , objectB ) {
70+ function objectDiff ( objectA , objectB , requiredFields = [ ] ) {
6971 const diffObject = { } ;
7072
7173 /**
@@ -93,6 +95,10 @@ function objectDiff(objectA, objectB) {
9395 }
9496
9597 if ( objectAItem === objectBItem ) {
98+ if ( requiredFields . includes ( prop ) ) {
99+ diffObject [ prop ] = objectAItem ;
100+ }
101+
96102 return ;
97103 }
98104
0 commit comments