glob lets you convert glob patterns into regular expressions. It has no dependencies and is 1120 bytes, or 471 bytes gzipped. It works in all browsers and all versions of Node.
glob is a code-golfing fork of the amazing globrex.
Usage
Add glob to your project:
npm install @jsxtools/glob
Use glob to convert glob patterns into regular expressions:
glob = // match JS files either within "path/to/" or a subdirectory of "path/to/"match1 = // these paths will matchmatch1match1 // these paths will NOT matchmatch1match1match1 // match paths that start with "p" followed by any letter followed by "ck"match2 = // these will matchmatch2match2 // these will NOT matchmatch2match2match2
glob supports single character matching.
// true // true // true // true // FALSE // FALSE
glob supports matching ranges of characters.
// true // true // true // FALSE // FALSE
glob supports group matching.
// true // true // true // FALSE
glob supports globstar patterns.
// true // true // FALSE // FALSE // FALSE // FALSE
glob supports posix-style paths and does not support windows-style paths.
I recommend you detect the windows environment and manage this conversion yourself:
// whether the environment is windowsconst isWin = processplatform === 'win32' // returns a windows-style path converted into a posix-style pathconst win2pos = win32path // returns any path conditionally converted into a posix-style pathconst all2pos = isWin ? : anypath // becomes "/Users/THX1138/images/../files" // becomes "/C/Users/THX1138/images/../files"