Convert extname into regexp.
npm install ext-to-regexp
const extToRegexp = require('ext-to-regexp');
extToRegexp({
extname: ['js', 'jsx']
});
// /\.(js|jsx)$/
extToRegexp({
suffix: ['min'],
extname: ['jpg', 'png']
});
// /\.min\.(jpg|png)$/
const foo = extToRegexp({ extname: ['css'] });
const bar = foo.add('sass', 'scss').add('less');
const baz = bar.remove('sass').remove('scss');
console.log(foo); // /\.css$/
console.log(bar); // /\.(css|less|sass|scss)$/
console.log(baz); // /\.(css|less)$/