Skip to content

Commit c5811b4

Browse files
committed
Merge pull request #70 from bem/issue69
Move to option 'ignoreWhitespaces'
2 parents c3cfc51 + abf9040 commit c5811b4

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

lib/diff-logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function getDiffText(diff, options) {
1313
};
1414

1515
if (options.showCharacters) {
16-
console.log('Option \'showCharacters\' is deprecated, please, use \'charsAroundDiff\'');
16+
console.log('WARNING! Option \'showCharacters\' is deprecated, please, use \'charsAroundDiff\''.red);
1717
options.charsAroundDiff = options.showCharacters;
1818
}
1919

lib/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var utils = require('./utils'),
2+
23
diff = require('diff'),
34
htmlParser = require('htmlparser2'),
45
AST2Html = require('htmlparser-to-html'),
@@ -34,7 +35,7 @@ function modifyASTTree(tree, options) {
3435
var delComments = [];
3536

3637
_.forEach(tree, function(node) {
37-
if (options.ignoreWhitespace && node.type === 'text') {
38+
if (options.ignoreWhitespaces && node.type === 'text') {
3839

3940
node.data = node.data
4041
.replace(/(\n|\r|\t|\v|\f)+/g, '')
@@ -96,7 +97,7 @@ function modifyASTTree(tree, options) {
9697
* @param {String[]} [options.ignoreHtmlAttrs]
9798
* @param {String[]} [options.compareHtmlAttrsAsJSON]
9899
* @param {Boolean} [options.verbose]
99-
* @param {Boolean} [options.ignoreWhitespace=true]
100+
* @param {Boolean} [options.ignoreWhitespaces=true]
100101
* @param {Boolean} [options.bem=false]
101102
* @constructor
102103
*/
@@ -135,7 +136,7 @@ HtmlDiff.prototype.tokenize = function(value) {
135136
* @param {String[]} [options.ignoreHtmlAttrs]
136137
* @param {String[]} [options.compareHtmlAttrsAsJSON]
137138
* @param {Boolean} [options.verbose]
138-
* @param {Boolean} [options.ignoreWhitespace=true]
139+
* @param {Boolean} [options.ignoreWhitespaces=true]
139140
* @param {Boolean} [options.bem=false]
140141
* @constructor
141142
*/
@@ -159,7 +160,7 @@ var HtmlDiffer = function(options) {
159160
*/
160161
HtmlDiffer.prototype.diffHtml = function(html1, html2, options) {
161162
if (options) {
162-
console.warn('WARNING! The third param of \'diffHtml\' method is deprecated!');
163+
console.warn('WARNING! The third param of \'diffHtml\' method is deprecated!'.bold.red);
163164
}
164165

165166
options = _.defaults(this.options, options);
@@ -178,7 +179,7 @@ HtmlDiffer.prototype.diffHtml = function(html1, html2, options) {
178179
*/
179180
HtmlDiffer.prototype.isEqual = function(html1, html2, options) {
180181
if (options) {
181-
console.warn('WARNING! The third param of \'isEqual\' method is deprecated!');
182+
console.warn('WARNING! The third param of \'isEqual\' method is deprecated!'.bold.red);
182183
}
183184

184185
options = _.defaults(this.options, options);
@@ -195,7 +196,7 @@ HtmlDiffer.prototype.isEqual = function(html1, html2, options) {
195196
* @param {String} html2
196197
*/
197198
function bemDiff(html1, html2) {
198-
console.warn('WARNING! You use deprecated method \'bemDiff\'!');
199+
console.warn('WARNING! You use deprecated method \'bemDiff\'!'.bold.red);
199200

200201
var logger = require('./diff-logger'),
201202
options = {

lib/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var _ = require('lodash');
22

3+
require('colors');
4+
35
/**
46
* Recursively sorts the given object by key
57
* @param {Object} obj
@@ -54,11 +56,18 @@ exports.sortCssClasses = function(cssClasses) {
5456
* @returns {Object}
5557
*/
5658
exports.defaults = function(options) {
59+
if (options && options.hasOwnProperty('ignoreWhitespace')) {
60+
console.log('WARNING! Option \'ignoreWhitespace\' is deprecated, please, use \'ignoreWhitespaces\''.bold.red);
61+
options.ignoreWhitespaces = options.ignoreWhitespace;
62+
63+
delete options.ignoreWhitespace;
64+
}
65+
5766
return _.defaults(options || {}, {
5867
ignoreHtmlAttrs: [],
5968
compareHtmlAttrsAsJSON: [],
6069

61-
ignoreWhitespace: true,
70+
ignoreWhitespaces: true,
6271
ignoreHtmlComments: true,
6372

6473
bem: false

test/diffHtml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function readFiles(f1, f2) {
1313
describe('\'diffHtml\'', function () {
1414

1515
it('must set options', function () {
16-
var htmlDiffer = new HtmlDiffer({ ignoreHtmlAttrs: ['id', 'for'], ignoreWhitespace: true }),
16+
var htmlDiffer = new HtmlDiffer({ ignoreHtmlAttrs: ['id', 'for'], ignoreWhitespaces: true }),
1717
files = readFiles('3.html', '_3.html'),
1818
res = [ {
1919
value: '<html><head><title>Test</title></head><body><label for="">label for input</label><input id=""></body></html>',

test/isEqual.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,79 +14,69 @@ describe('\'isEqual\'', function () {
1414

1515
it('must be equal', function () {
1616
var htmlDiffer = new HtmlDiffer(),
17-
1817
files = readFiles('1.html', '_1.html');
1918

2019
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
2120
});
2221

2322
it('must be not equal', function () {
2423
var htmlDiffer = new HtmlDiffer(),
25-
2624
files = readFiles('2.html', '_2.html');
2725

2826
htmlDiffer.isEqual(files.html1, files.html2).must.be.false();
2927
});
3028

3129
it('must ignore html attrs', function () {
3230
var htmlDiffer = new HtmlDiffer({ ignoreHtmlAttrs: ['id', 'for'] }),
33-
3431
files = readFiles('3.html', '_3.html');
3532

3633
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
3734
});
3835

3936
it('must sort classes', function () {
4037
var htmlDiffer = new HtmlDiffer(),
41-
4238
files = readFiles('4.html', '_4.html');
4339

4440
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
4541
});
4642

4743
it('must sort attrs', function () {
4844
var htmlDiffer = new HtmlDiffer(),
49-
5045
files = readFiles('5.html', '_5.html');
5146

5247
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
5348
});
5449

5550
it('must sort content of attrs', function () {
5651
var htmlDiffer = new HtmlDiffer({ compareHtmlAttrsAsJSON: [ 'a', 'b' ] }),
57-
5852
files = readFiles('6.html', '_6.html');
5953

6054
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
6155
});
6256

6357
it('must ignore space characters', function () {
64-
var htmlDiffer = new HtmlDiffer({ ignoreWhitespace: true }),
65-
58+
var htmlDiffer = new HtmlDiffer({ ignoreWhitespaces: true }),
6659
files = readFiles('7.html', '_7.html');
6760

6861
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
6962
});
7063

7164
it('must sort \'onclick\' and \'ondblclick\' attrs content', function () {
7265
var htmlDiffer = new HtmlDiffer({ compareHtmlAttrsAsJSON: [ 'onclick', 'ondblclick' ] }),
73-
7466
files = readFiles('8.html', '_8.html');
7567

7668
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
7769
});
7870

7971
it('must work \'bem\' option', function() {
8072
var htmlDiffer = new HtmlDiffer({ bem: true }),
81-
8273
files = readFiles('9.html', '_9.html');
8374

8475
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
8576
});
8677

8778
it('must ignore html comments', function() {
8879
var htmlDiffer = new HtmlDiffer(),
89-
9080
files = readFiles('10.html', '_10.html');
9181

9282
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();

0 commit comments

Comments
 (0)