fitzgen / glob-to-regexp Goto Github PK
View Code? Open in Web Editor NEWConvert a glob to a regular expression
Convert a glob to a regular expression
# Bad behavior.
> globToRegExp('fo[oO*]bar', {extended: true})
/^fo[oO.*]bar$/
# Expected result:
/^fo[oO*]bar$/
Thanks for your work! Can you please include a License file?
First of all, thanks for this great package!
It would be nice if there was an official changelog or maybe release notes for each release so that we know for sure what kind of changes are included and whether an upgrade is the right thing to do. :)
Now that the correct SPDX identifier has been set in package.json, thanks to dd7b8a0 it would be nice if that could be released on NPM. It would help (at least me) with license validation automation.
Thanks!
adding a \
before a glob character should treat it as a plain character. the current behavior ignores it completely.
# Bad behavior.
> globToRegExp('foo\\*bar')
/^foo\.*bar$/
# Expected result:
/^foo\*bar$/
This library doesn't support negation globs, here are the docs about it
For example calling globToRegExp('!*.js')
returns /^\!.*\.js$/
, which matches strings that start with the character !
.
It should return a negative regex (lookahead?) instead.
The idea of converting globs to regexes is a good one. However, the conversion done by this code is not correct. Using /^..min.js$/ as the regex for ".min.js" is wrong. The dot asterisk (.*) after the carrot will match all characters including forward slashes. That is not how globs are supposed to work. Wikipedia (and other sources) says that a glob asterisk does not match any forward slashes.
Note that
re = globToRegExp("*.min.js");
re.test("http://example.com/jquery.min.js"); // true
is wrong. The asterisk should match "jquery" but not "example/jquery". A globstar (two asterisks) does match slashes, but not a single asterisk. The full rules for a globstar are more complex than I have stated here.
Curly braces are not handled
> globToRegExp('./resources/lang/{en,fr}/*.json')
Expected:
/^\.\/resources\/lang\/(en|fr)\/.*\.json$/
or (minimatch produces this):
/^(?:\.\/resources\/lang\/en\.json|\.\/resources\/lang\/fr\.json)$/
Actual:
/^\.\/resources\/lang\/\{en\,fr\}\/.*\.json$/
Hey Nick,
Nice job...
I would suggest, you can make a second version of this, for front-end (browsers js).
I know it's just removing the export...
but would be nice to have.
Also a minified version of both ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.