putout
Version:
the pluggable code transformer
31 lines (21 loc) • 679 B
JavaScript
;
const {normalize} = require('path');
const picomatch = require('picomatch');
let patterns = [];
const rmDuplicates = (a) => Array.from(new Set(a));
module.exports.add = (array) => {
patterns = rmDuplicates(patterns.concat(array));
};
module.exports.isSupported = (name) => {
for (const pattern of patterns) {
const isMatch = picomatch(patterns, {
dot: true,
matchBase: true,
});
if (isMatch(name))
return true;
}
return false;
};
module.exports.getSupportedGlob = (file) => normalize(`${file}/**/{${patterns.join(',')}}`);
module.exports.getPatterns = () => patterns;