Skip to content

Commit

Permalink
fix: setting some custom options should not overwrite default values …
Browse files Browse the repository at this point in the history
…in others
  • Loading branch information
pensierinmusica committed May 22, 2018
1 parent d0e3ef8 commit d9231f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

const fs = require('fs');

const defOpts = {
encoding: 'utf8',
lineEnding: '\n'
};

module.exports = (path, opts = defOpts) => {
module.exports = (path, usrOpts) => {
const opts = {
encoding: 'utf8',
lineEnding: '\n'
};
Object.assign(opts, usrOpts);
return new Promise((resolve, reject) => {
const rs = fs.createReadStream(path, {encoding: opts.encoding});
let acc = '';
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ describe('firstline', () => {
.then(() => firstline(filePath).should.eventually.equal(''))
);

it(
'should work with a different encoding when specified correctly',
() => promisify(fs.writeFile, [filePath, 'abc\ndef\nghi', { encoding: 'ascii' }])
.then(() => firstline(filePath, { encoding: 'ascii' }).should.eventually.equal('abc'))
);

it(
'should work with a different line ending when specified correctly',
() => promisify(fs.writeFile, [filePath, 'abc\rdef\rghi'])
Expand Down

0 comments on commit d9231f6

Please sign in to comment.