I have an array of paths, let's say:
/Users/alansouza/workspace/project/src/js/components/chart/Graph.js
Also I have an entry in a configuration file with additional attributes for this path in a wildcard(glob) format, as in:
{
'**/*.js': {
runBabel: true
}
}
Question: Is there an easy way to validate if the path matches the wildcard expression?
For example:
const matches = Glob.matches(
'**/*.js',
'/Users/alansouza/workspace/project/src/js/components/chart/Graph.js'
);
if (matches) {
//do something
}
FYI: I'm using https://github.com/isaacs/node-glob
You could convert the glob to to a regex with node glob-to-regex
and then validate path strings against the regex.
https://www.npmjs.com/package/glob-to-regexp
it looks like node glob
is another option.
https://github.com/isaacs/node-glob
And node has its own glob implementation
https://github.com/isaacs/minimatch
My first thought was to see if phpjs
had implemented a glob function but it looks like they haven't :(
http://locutus.io/php/
As @chiliNUT theorized in a comment, minimatch
has this behaviour:
minimatch("file.js", "**/*.js") // true/false
minimatch.match(["file1.js", "file2.js"], "**/*.js") // array of matches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With