Skip to content

Filter out junk files#284

Merged
sindresorhus merged 3 commits intoimagemin:masterfrom
tprobinson:add-junk-filter
Jun 30, 2019
Merged

Filter out junk files#284
sindresorhus merged 3 commits intoimagemin:masterfrom
tprobinson:add-junk-filter

Conversation

@tprobinson
Copy link
Copy Markdown
Contributor

@tprobinson tprobinson commented Jun 6, 2018

Fixes #247. A test is included, not sure if I did it right.

index.js Outdated

return globby(input, {nodir: true}).then(paths => Promise.all(paths.map(x => handleFile(x, output, opts))));
return globby(input, {nodir: true})
.then(paths => Promise.resolve(paths.filter(path => junk.not(path))))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Promise.resolve call is moot and you can just put the filter logic in the same .then as the Promise.all call.

@tprobinson
Copy link
Copy Markdown
Contributor Author

Sorry it took me so long to get back to this! It's all synced up with master, and I rewrote the test to actually do something useful.

index.js Outdated

return globby(input, {onlyFiles: true}).then(paths => Promise.all(paths.map(x => handleFile(x, output, options))));
return globby(input, {onlyFiles: true})
.then(paths => Promise.all(paths.reduce((acc, x) => junk.is(path.basename(x)) ? acc : acc.concat(handleFile(x, output, options)), [])));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using reduce here just makes the code much less readable. Would be better to use filter.

@sindresorhus sindresorhus changed the title Add a junk filter to input files. Filter out junk files Jun 29, 2019
@sindresorhus sindresorhus merged commit 6745ce3 into imagemin:master Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with Thumbs.db on Windows

2 participants