@@ -2,6 +2,32 @@ const sortArrays = require('./sortArrays');
22const detailedDiff = require ( 'deep-object-diff' ) . detailedDiff ;
33const flatten = require ( 'flat' ) ;
44
5+ const runCompare = ( li , ri , comparison ) => {
6+ let left = li ;
7+ let right = ri ;
8+ const splitCompare = comparison . split ( '($)' ) . filter ( x => x ) ;
9+
10+ for ( const substr of splitCompare ) { // eslint-disable-line
11+ if ( ! substr . includes ( '*' ) ) {
12+ throw new Error ( 'missing * in customCompare' ) ;
13+ }
14+ const [ l , r ] = substr . split ( '*' ) ;
15+ const lm = left . substr ( 0 , left . indexOf ( l ) ) ;
16+ const rm = right . substr ( 0 , right . indexOf ( l ) ) ;
17+ if ( lm !== rm ) {
18+ return false ;
19+ }
20+ left = left . substr ( left . indexOf ( r ) ) ;
21+ right = right . substr ( right . indexOf ( r ) ) ;
22+ }
23+
24+ if ( left !== right ) {
25+ return false ;
26+ }
27+
28+ return true ;
29+ } ;
30+
531module . exports = async ( lj , rj , options , arr = [ ] ) => {
632 const diffTable = arr ;
733 let leftJSON = sortArrays ( lj , options ) ;
@@ -60,6 +86,15 @@ module.exports = async (lj, rj, options, arr = []) => {
6086 if ( ignore . includes ( key ) ) return ;
6187 const leftValue = leftFlatJSON [ key ] ;
6288 const rightValue = updated [ key ] ;
89+ if ( options . customDiff && options . customDiff [ key ] ) {
90+ const re = new RegExp ( options . customDiff [ key ] ) ;
91+ if ( re . test ( leftValue ) && re . test ( rightValue ) ) {
92+ return ;
93+ }
94+ }
95+ if ( options . customCompare && options . customCompare [ key ] ) {
96+ if ( runCompare ( leftValue , rightValue , options . customCompare [ key ] ) ) return ;
97+ }
6398 diffTable . push ( {
6499 key,
65100 left : leftValue ,
0 commit comments