This code provides a minimatch
function that allows you to match filenames against simplified glob-like patterns by converting them into regular expressions. It handles brace expansions, splits patterns into segments, parses them into regexps, and efficiently tests filename matches against the resulting expression.
npm run import -- "minimatch"
var importer = require('../Core')
var expand = importer.import("expand")
var parse = importer.import("mini parser")
function regExpEscape (s) {
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\${OUTPUT}amp;')
}
// convert minimatch expression to regular expression
function minimatch (filename, pattern) {
// expand braces
var set = expand(pattern)
// matching patterns.
.map(function (s) {
return s.split(/\/+/)
})
// glob --> regexps
.map(function (s, si, set) {
return s.map(parse)
})
// filter out everything that didn't compile properly.
.filter(function (s) {
return s.indexOf(false) === -1
})
// convert the sets to regular expressions
.map(function (pattern) {
return pattern.map(function (p) {
return (typeof p.glob === 'boolean')
? '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
: (typeof p === 'string') ? regExpEscape(p)
: p._src
}).join('\\\/')
}).join('|')
try {
var re = new RegExp('^(?:' + set + ')