Skip to content

Commit

Permalink
Remove detailed option from readdir, fixes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkeller committed Aug 20, 2019
1 parent 32b5b57 commit c9c1309
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 56 deletions.
2 changes: 1 addition & 1 deletion dist/indian-ocean.browser.es6.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions dist/indian-ocean.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/indian-ocean.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/indian-ocean.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/indian-ocean.min.js

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions src/readers/readdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ export default function readdir (modeInfo, dirPath, opts_, cb) {

function filterByType (file, cb) {
// We need the full path so convert it if it isn't already
var filePath = file
if (opts_.detailed === true) {
filePath = joinPath(file.basePath, file.fileName)
} else if (!opts_.fullPath) {
filePath = joinPath(dirPath, file)
}
var filePath = (opts_.fullPath) ? file : joinPath(dirPath, file)

if (isAsync === true) {
fs.stat(filePath, function (err, stats) {
Expand Down Expand Up @@ -107,21 +102,12 @@ export default function readdir (modeInfo, dirPath, opts_, cb) {
return true
})

if (opts_.fullPath === true && opts_.detailed === true) {
throw new Error('[indian-ocean] Both `fullPath` and `detailed` are `true`. You can only set one or the other.')
}
// Prefix with the full path if that's what we asked for
if (opts_.fullPath === true) {
return filtered.map(function (fileName) {
return joinPath(dirPath, fileName)
})
}
// Or return detailed format
if (opts_.detailed === true) {
return filtered.map(function (fileName) {
return { basePath: dirPath, fileName: fileName }
})
}

return filtered
}
Expand Down
23 changes: 1 addition & 22 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/* global describe, it */

var fs = require('fs')
Expand Down Expand Up @@ -1716,28 +1717,6 @@ describe('readers', function () {
})
})

describe('detailed readdir results', function () {
it('should match expected output', function () {
var dir = path.join(__dirname, 'data', 'csv')
var files = io.readdirFilterSync(dir, {include: 'csv', detailed: true})
assert.deepEqual(files, [
{basePath: dir, fileName: 'basic.csv'},
{basePath: dir, fileName: 'empty.csv'}
])
})
})

describe('detailed readdir results', function () {
it('should match expected output', function () {
var dir = path.join(__dirname, 'data', 'csv') + '/'
var files = io.readdirFilterSync(dir, {include: 'csv', detailed: true})
assert.deepEqual(files, [
{basePath: dir, fileName: 'basic.csv'},
{basePath: dir, fileName: 'empty.csv'}
])
})
})

describe('use regex', function () {
it('should match expected output', function () {
var dir = path.join(__dirname, 'data', 'mixed')
Expand Down

0 comments on commit c9c1309

Please sign in to comment.