javascriptglobminimatch

Glob pattern to ignore certain .dot.js files


I am looking for a glob pattern that excludes certain parts of the file name. For example, I want to get all *.js files but exclude all *.map.js files.

/hello/world.js // match
/hello/world.map.js // no match
/hello/world.test.js // match

I thought using a not pattern such as this /**/*!(.map).js would work but it still matches all three of the paths above.

I'm curious if this is possible without using an ignore pattern option. Thanks!


Solution

  • Here is what I've come up with:

    **/!(*.map.js|!(*.js))
    

    enter image description here

    Here is the link to the playground:

    https://www.digitalocean.com/community/tools/glob?comments=true&glob=%2A%2A%2F%21%28%2A.map.js%7C%21%28%2A.js%29%29&matches=false&tests=%2Fhello%2Fworld.js&tests=%2Fhello%2Fworld-test.js&tests=test.js&tests=%2Ffoo%2Fbar.txt&tests=foo.map.js&tests=%2Fhello%2Fworld.map.js&tests=%2Ffoo%2F