2.0 KiB
2.0 KiB
glob-parent
Javascript module to extract the non-magic parent path from a glob string.
Usage
npm install glob-parent --save
Examples
var globParent = require('glob-parent');
globParent('path/to/*.js'); // 'path/to'
globParent('/root/path/to/*.js'); // '/root/path/to'
globParent('/*.js'); // '/'
globParent('*.js'); // '.'
globParent('**/*.js'); // '.'
globParent('path/{to,from}'); // 'path'
globParent('path/!(to|from)'); // 'path'
globParent('path/?(to|from)'); // 'path'
globParent('path/+(to|from)'); // 'path'
globParent('path/*(to|from)'); // 'path'
globParent('path/@(to|from)'); // 'path'
globParent('path/**/*'); // 'path'
// if provided a non-glob path, returns the nearest dir
globParent('path/foo/bar.js'); // 'path/foo'
globParent('path/foo/'); // 'path/foo'
globParent('path/foo'); // 'path' (see issue #3 for details)
Escaping
The following characters have special significance in glob patterns and must be escaped if you want them to be treated as regular path characters:
?
(question mark)*
(star)|
(pipe)(
(opening parenthesis))
(closing parenthesis){
(opening curly brace)}
(closing curly brace)[
(opening bracket)]
(closing bracket)
Example
globParent('foo/[bar]/') // 'foo'
globParent('foo/\\[bar]/') // 'foo/[bar]'
Change Log
See release notes page on GitHub