cogs
Version:
The fast file transform pipeline.
17 lines (13 loc) • 511 B
JavaScript
import npath from 'node:path';
import toArray from '#src/to-array.js';
const doesMatch = ({ transformer, path }) => {
const only = toArray(transformer.only);
const except = toArray(transformer.except);
return (
(!only.length || only.some(pattern => npath.matchesGlob(path, pattern))) &&
(!except.length ||
!except.some(pattern => npath.matchesGlob(path, pattern)))
);
};
export default ({ transformers, path }) =>
transformers.filter(transformer => doesMatch({ transformer, path }));