1- require ( 'colors' ) ;
1+ var chalk = require ( 'chalk' ) ,
2+ inverseGreen = chalk . green . inverse ,
3+ inverseRed = chalk . red . inverse ,
4+ grey = chalk . grey ;
25
36/**
47 * @typedef {Object } Diff
@@ -31,24 +34,24 @@ function getDiffText(diff, options) {
3134 diff . forEach ( function ( part ) {
3235 var index = diff . indexOf ( part ) ,
3336 partValue = part . value ,
34- color = 'grey' ;
37+ diffColor ;
3538
36- if ( part . added ) color = 'green' ;
37- if ( part . removed ) color = 'red' ;
39+ if ( part . added ) diffColor = inverseGreen ;
40+ if ( part . removed ) diffColor = inverseRed ;
3841
39- if ( color !== 'grey' ) {
40- output += ( ! index ? '\n' : '' ) + partValue . inverse [ color ] ;
42+ if ( diffColor ) {
43+ output += ( index === 0 ? '\n' : '' ) + diffColor ( partValue ) ;
4144
4245 return ;
4346 }
4447
4548 if ( partValue . length < charsAroundDiff * 2 ) {
46- output += ( index ? '' : '\n' ) + partValue . grey ;
49+ output += ( index !== 0 ? '' : '\n' ) + grey ( partValue ) ;
4750 } else {
48- index && ( output += partValue . substr ( 0 , charsAroundDiff ) . grey ) ;
51+ index !== 0 && ( output += grey ( partValue . substr ( 0 , charsAroundDiff ) ) ) ;
4952
5053 if ( index < diff . length - 1 ) {
51- output += '\n...\n' + partValue . substr ( partValue . length - charsAroundDiff , charsAroundDiff ) . grey ;
54+ output += '\n...\n' + grey ( partValue . substr ( partValue . length - charsAroundDiff ) ) ;
5255 }
5356 }
5457 } ) ;
@@ -57,7 +60,7 @@ function getDiffText(diff, options) {
5760}
5861
5962/**
60- * Logs diff of the given HTML docs to the console
63+ * Logs the diff of the given HTML docs to the console
6164 * @param {Object[] } diff
6265 * @param {Object } [options]
6366 * @param {Number } [options.charsAroundDiff=40]
@@ -66,7 +69,7 @@ function logDiffText(diff, options) {
6669 var diffText = getDiffText ( diff , options ) ;
6770
6871 if ( diffText ) {
69- console . log ( '+ expected' . inverse . green , '- actual' . inverse . red , '\n' , diffText ) ;
72+ console . log ( inverseGreen ( '+ expected' ) , inverseRed ( '- actual' ) , '\n' , diffText ) ;
7073 }
7174}
7275
0 commit comments