*-wildcard
style glob to R.E
glob-to-regexp
helps us in converting *-wildcard style glob to RE, as in "*.min.js"
to /^.*\.min\.js$/
.
Get it: npm install glob-to-regexp
Sample usage:
1
| const globToRegExp = require('glob-to-regexp');
|
1
2
3
4
| let re = globToRegExp("p*uck");
re.test("pot luck"); // true
re.test("pluck"); // true
re.test("puck"); // true
|
1
2
3
| re = globToRegExp("*.min.js");
re.test("http://example.com/jquery.min.js"); // true
re.test("http://example.com/jquery.min.js.map"); // false
|
1
2
3
| re = globToRegExp("*/www/*.js");
re.test("http://example.com/www/app.js"); // true
re.test("http://example.com/www/lib/factory-proxy-model-observer.js"); // true
|
1
2
3
4
| // Extended globs
re = globToRegExp("*/www/{*.js,*.html}", { extended: true });
re.test("http://example.com/www/app.js"); // true
re.test("http://example.com/www/index.html"); // true
|
GIF FTW!