Skip to content

best-shot/ext-to-regexp

Repository files navigation

ext-to-regexp

Convert extname into regexp.

npm github node

Installation

npm install ext-to-regexp

Usage

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)$/