UNPKG

509 BJavaScriptView Raw
1import minimatch from 'minimatch';
2import _ from 'underscore';
3
4import toArray from './to-array.js';
5
6const 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
16export default ({ transformers, path }) =>
17 _.filter(transformers, transformer => doesMatch({ transformer, path }));