-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from madcapsoftware/collapse-spaces-normalize-…
…newlines Normalize newlines
- Loading branch information
Showing
7 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(function(){ | ||
|
||
"use strict"; | ||
|
||
module.exports = function normalizeNewlines(str) { | ||
// First replace all CR+LF newlines then replace CR newlines | ||
return str.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); | ||
}; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var assert = require('assert'); | ||
var normalizeNewlines = require('../lib/normalize_newlines'); | ||
|
||
describe('normalize_newlines', function () { | ||
it('should transform CR+LF to LF', function() { | ||
var input = '\r\n'; | ||
var expected = '\n'; | ||
assert.equal(normalizeNewlines(input), expected); | ||
}); | ||
|
||
it('should transform CR to LF', function() { | ||
var input = '\r'; | ||
var expected = '\n'; | ||
assert.equal(normalizeNewlines(input), expected); | ||
}); | ||
|
||
it('should transform mixed CR+LF and LF to LF', function() { | ||
var input = '\n\r\n\n\r\n\n'; | ||
var expected = '\n\n\n\n\n'; | ||
assert.equal(normalizeNewlines(input), expected); | ||
}); | ||
|
||
it('should transform mixed CR+LF and CR to LF', function() { | ||
var input = '\r\n\r\n\r \r\n\r'; | ||
var expected = '\n\n\n \n\n'; | ||
assert.equal(normalizeNewlines(input), expected); | ||
}); | ||
|
||
it('should transform mixed CR and LF to LF', function() { | ||
var input = '\n\n\r \n\r'; | ||
var expected = '\n\n\n \n\n'; | ||
assert.equal(normalizeNewlines(input), expected); | ||
}); | ||
|
||
it('should transform mixed CR+LF and CR and LF to LF', function() { | ||
var input = '\n\r\n\r\n\n\r \n\r\n\r'; | ||
var expected = '\n\n\n\n\n \n\n\n'; | ||
assert.equal(normalizeNewlines(input), expected); | ||
}); | ||
}); |