count-lines
Advanced tools
Comparing version 0.1.0 to 0.1.2
@@ -14,2 +14,8 @@ /*! | ||
function count (str) { | ||
if (typeof str !== 'string') { | ||
throw new Error('count-lines expects a string.'); | ||
} | ||
if (!str.length) { | ||
return 0; | ||
} | ||
return str.split(/\r?\n/g).length; | ||
@@ -16,0 +22,0 @@ } |
{ | ||
"name": "count-lines", | ||
"description": "Count the lines in a string, works with windows carriage returns or unix style newlines.", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/jonschlinkert/count-lines", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -14,2 +14,8 @@ /*! | ||
describe('count', function () { | ||
it('should return zero when the string is empty.', function () { | ||
var actual = count(''); | ||
assert.equal(actual, 0); | ||
assert.notEqual(actual, 4); | ||
}); | ||
it('should count lines', function () { | ||
@@ -21,3 +27,9 @@ var actual = count('a\nb\nc'); | ||
it('should count lines with carriage returns', function () { | ||
it('should include trailing newlines', function () { | ||
var actual = count('a\nb\nc\n'); | ||
assert.equal(actual, 4); | ||
assert.notEqual(actual, 5); | ||
}); | ||
it('should work with carriage returns', function () { | ||
var actual = count('a\r\nb\r\nc'); | ||
@@ -27,2 +39,8 @@ assert.equal(actual, 3); | ||
}); | ||
it('should include trailing carriage returns', function () { | ||
var actual = count('a\r\nb\r\nc\r\n'); | ||
assert.equal(actual, 4); | ||
assert.notEqual(actual, 5); | ||
}); | ||
}); |
6355
11
71