Comparing version 1.1.0 to 1.1.1
@@ -15,5 +15,8 @@ var fs = require('fs'); | ||
var ran = false; | ||
var tentativePreviousString; | ||
var tentativeEndingType; | ||
reader.on('data', function(buffer) { | ||
if (!ran) { | ||
var matched = buffer.toString().match(/\r\n|\r|\n/); | ||
var str = (tentativePreviousString || '') + buffer.toString(); | ||
var matched = str.match(/\r\n|\r|\n/); | ||
var returned = { | ||
@@ -24,2 +27,9 @@ '\r': 'CR', | ||
}[matched]; | ||
if (matched && returned === 'CR') { // handle case where current buffer ends between CR and LF of CRLF | ||
if (!str.match(/\r./)) { // make sure CR is followed by something other than end of string | ||
tentativePreviousString = str; | ||
tentativeEndingType = 'CR'; | ||
return; | ||
} | ||
} | ||
if (matched) { | ||
@@ -35,3 +45,3 @@ ran = true; | ||
ran = true; | ||
callback(null, 'NA'); | ||
callback(null, tentativeEndingType || 'NA'); | ||
} | ||
@@ -38,0 +48,0 @@ }); |
{ | ||
"name": "crlf", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "detect and change newline endings", | ||
@@ -16,2 +16,3 @@ "main": "index.js", | ||
"license": "MIT", | ||
"repository": "kolodny/crlf", | ||
"devDependencies": { | ||
@@ -18,0 +19,0 @@ "coveralls": "^2.11.2", |
@@ -13,4 +13,4 @@ crlf | ||
The cli is probably the one your looking for, first `npm install -g crlf` | ||
usage is something like this: | ||
The cli is probably the one you're looking for, first `npm install -g crlf`. | ||
Usage is something like this: | ||
@@ -17,0 +17,0 @@ ```bash |
@@ -16,2 +16,8 @@ var crlf = require('..'); | ||
afterEach(cleanup); | ||
var longLine = ""; | ||
var bufferLength = 1024 * 64; // fs.createReadStream buffer length | ||
while (longLine.length < bufferLength) { | ||
longLine += "LongLine"; | ||
} | ||
longLine = longLine.substr(0, bufferLength - 1); | ||
@@ -50,2 +56,19 @@ describe('get()', function() { | ||
}); | ||
it('can handle files where buffer ends between \\r and \\n of \\r\\n', function(done) { | ||
var betweenLines = [longLine, longLine.substr(0, -1)].concat(lines); // this will cause two buffers ending between CR and LF in a row | ||
fs.writeFileSync(fileLocation, betweenLines.join('\r\n')); | ||
crlf.get(fileLocation, null, function(err, ending) { | ||
assert.equal(ending, 'CRLF'); | ||
done(); | ||
}); | ||
}); | ||
it('can handle files where buffer ends between \\r and EOF', function(done) { | ||
fs.writeFileSync(fileLocation, [longLine, ''].join('\r')); | ||
crlf.get(fileLocation, null, function(err, ending) { | ||
assert.equal(ending, 'CR'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -52,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10812
11
209