Skip to content

Commit

Permalink
using an options object rather than a single string option
Browse files Browse the repository at this point in the history
  • Loading branch information
catdad committed Sep 1, 2021
1 parent c68f9d6 commit 5d4b54b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions index.js
Expand Up @@ -8,14 +8,12 @@ var allowedEol = {
'\r\n': true
};

module.exports = function lfcrClean(eol) {
if (!eol) {
// Set a default
eol = '\n';
}
module.exports = function lfcrClean(options) {
options = options || {};
var eol = options.eol || '\n';

if (!allowedEol[eol]) {
throw new Error('Invalid EOL: "' + eol + '"');
throw new Error('Invalid `eol` option: "' + eol + '"');
}

var crlf = /\r\n|\n\r|\n|\r/g;
Expand Down
10 changes: 5 additions & 5 deletions test/index.test.js
Expand Up @@ -75,7 +75,7 @@ describe('[index]', function () {
it('accepts \\r\\n as a custom line ending', function (done) {
es.readArray([
'chunk\nchunk\rchunk\r\nchunk\r', '\nchunk', '\n',
]).pipe(mod('\r\n')).pipe(es.wait(function (err, data) {
]).pipe(mod({ eol: '\r\n' })).pipe(es.wait(function (err, data) {
data = data.toString();

expect(data).to.equal('chunk\r\nchunk\r\nchunk\r\nchunk\r\nchunk\r\n');
Expand All @@ -87,7 +87,7 @@ describe('[index]', function () {
it('accepts \\r as a custom line ending', function (done) {
es.readArray([
'chunk\nchunk\rchunk\r\nchunk\r', '\nchunk', '\n',
]).pipe(mod('\r')).pipe(es.wait(function (err, data) {
]).pipe(mod({ eol: '\r' })).pipe(es.wait(function (err, data) {
data = data.toString();

expect(data).to.equal('chunk\rchunk\rchunk\rchunk\rchunk\r');
Expand All @@ -99,7 +99,7 @@ describe('[index]', function () {
it('accepts \\n as a custom line ending', function (done) {
es.readArray([
'chunk\nchunk\rchunk\r\nchunk\r', '\nchunk', '\n',
]).pipe(mod('\n')).pipe(es.wait(function (err, data) {
]).pipe(mod({ eol: '\n' })).pipe(es.wait(function (err, data) {
data = data.toString();

expect(data).to.equal('chunk\nchunk\nchunk\nchunk\nchunk\n');
Expand All @@ -110,8 +110,8 @@ describe('[index]', function () {

it('throws if an unknown custom line ending is used', function () {
expect(function () {
mod('wat');
}).to.throw(Error, 'Invalid EOL: "wat"');
mod({ eol: 'wat' });
}).to.throw(Error, 'Invalid `eol` option: "wat"');
});
});
});

0 comments on commit 5d4b54b

Please sign in to comment.