1 | import minimatch from 'minimatch';
|
2 | import _ from 'underscore';
|
3 |
|
4 | import toArray from './to-array.js';
|
5 |
|
6 | const doesMatch = ({ transformer, path }) => {
|
7 | const only = toArray(transformer.only);
|
8 | const except = toArray(transformer.except);
|
9 | const match = _.partial(minimatch, path);
|
10 | return (
|
11 | (!only.length || _.any(only, match)) &&
|
12 | (!except.length || !_.any(except, match))
|
13 | );
|
14 | };
|
15 |
|
16 | export default ({ transformers, path }) =>
|
17 | _.filter(transformers, transformer => doesMatch({ transformer, path }));
|