pax_global_header00006660000000000000000000000064130242647330014516gustar00rootroot0000000000000052 comment=880243f7758be2967318280ad3e599c95e832a76 glob-parent-3.1.0/000077500000000000000000000000001302426473300137315ustar00rootroot00000000000000glob-parent-3.1.0/.gitignore000066400000000000000000000000561302426473300157220ustar00rootroot00000000000000node_modules .DS_Store npm-debug.log coverage glob-parent-3.1.0/.travis.yml000066400000000000000000000001421302426473300160370ustar00rootroot00000000000000language: node_js node_js: - "7" - "6" - "5" - "4" - "0.10" script: - npm run ci-test glob-parent-3.1.0/LICENSE000066400000000000000000000013531302426473300147400ustar00rootroot00000000000000The ISC License Copyright (c) 2015 Elan Shanker Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. glob-parent-3.1.0/README.md000066400000000000000000000067611302426473300152220ustar00rootroot00000000000000glob-parent [![Build Status](https://travis-ci.org/es128/glob-parent.svg)](https://travis-ci.org/es128/glob-parent) [![Coverage Status](https://img.shields.io/coveralls/es128/glob-parent.svg)](https://coveralls.io/r/es128/glob-parent?branch=master) ====== Javascript module to extract the non-magic parent path from a glob string. [![NPM](https://nodei.co/npm/glob-parent.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/glob-parent/) [![NPM](https://nodei.co/npm-dl/glob-parent.png?height=3&months=9)](https://nodei.co/npm-dl/glob-parent/) Usage ----- ```sh npm install glob-parent --save ``` **Examples** ```js 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** ```js globParent('foo/[bar]/') // 'foo' globParent('foo/\\[bar]/') // 'foo/[bar]' ``` ## Limitations #### Braces & Brackets This library attempts a quick and imperfect method of determining which path parts have glob magic without fully parsing/lexing the pattern. There are some advanced use cases that can trip it up, such as nested braces where the outer pair is escaped and the inner one contains a path separator. If you find yourself in the unlikely circumstance of being affected by this or need to ensure higher-fidelity glob handling in your library, it is recommended that you pre-process your input with [expand-braces] and/or [expand-brackets]. #### Windows Backslashes are not valid path separators for globs. If a path with backslashes is provided anyway, for simple cases, glob-parent will replace the path separator for you and return the non-glob parent path (now with forward-slashes, which are still valid as Windows path separators). This cannot be used in conjunction with escape characters. ```js // BAD globParent('C:\\Program Files \\(x86\\)\\*.ext') // 'C:/Program Files /(x86/)' // GOOD globParent('C:/Program Files\\(x86\\)/*.ext') // 'C:/Program Files (x86)' ``` If you are using escape characters for a pattern without path parts (i.e. relative to `cwd`), prefix with `./` to avoid confusing glob-parent. ```js // BAD globParent('foo \\[bar]') // 'foo ' globParent('foo \\[bar]*') // 'foo ' // GOOD globParent('./foo \\[bar]') // 'foo [bar]' globParent('./foo \\[bar]*') // '.' ``` Change Log ---------- [See release notes page on GitHub](https://github.com/es128/glob-parent/releases) License ------- [ISC](https://raw.github.com/es128/glob-parent/master/LICENSE) [expand-braces]: https://github.com/jonschlinkert/expand-braces [expand-brackets]: https://github.com/jonschlinkert/expand-brackets glob-parent-3.1.0/appveyor.yml000066400000000000000000000010731302426473300163220ustar00rootroot00000000000000 # Test against this version of Node.js environment: matrix: - nodejs_version: "7" - nodejs_version: "6" - nodejs_version: "5" - nodejs_version: "4" - nodejs_version: "0.10" # Install scripts. (runs after repo cloning) install: # Get the latest stable version of Node.js or io.js - ps: Install-Product node $env:nodejs_version # install modules - npm install # Post-install test scripts. test_script: # Output useful info for debugging. - node --version - npm --version # run tests - npm test # Don't actually build. build: off glob-parent-3.1.0/index.js000066400000000000000000000013731302426473300154020ustar00rootroot00000000000000'use strict'; var path = require('path'); var isglob = require('is-glob'); var pathDirname = require('path-dirname'); var isWin32 = require('os').platform() === 'win32'; module.exports = function globParent(str) { // flip windows path separators if (isWin32 && str.indexOf('/') < 0) str = str.split('\\').join('/'); // special case for strings ending in enclosure containing path separator if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/'; // preserves full path in case of trailing path separator str += 'a'; // remove path parts that are globby do {str = pathDirname.posix(str)} while (isglob(str) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(str)); // remove escape chars and return result return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1'); }; glob-parent-3.1.0/package.json000066400000000000000000000017011302426473300162160ustar00rootroot00000000000000{ "name": "glob-parent", "version": "3.1.0", "description": "Strips glob magic from a string to provide the parent directory path", "main": "index.js", "scripts": { "test": "istanbul test node_modules/mocha/bin/_mocha", "ci-test": "istanbul cover _mocha && cat ./coverage/lcov.info | coveralls" }, "repository": { "type": "git", "url": "https://github.com/es128/glob-parent" }, "keywords": [ "glob", "parent", "strip", "path", "dirname", "directory", "base", "wildcard" ], "files": [ "index.js" ], "author": "Elan Shanker (https://github.com/es128)", "license": "ISC", "bugs": { "url": "https://github.com/es128/glob-parent/issues" }, "homepage": "https://github.com/es128/glob-parent", "dependencies": { "is-glob": "^3.1.0", "path-dirname": "^1.0.0" }, "devDependencies": { "coveralls": "^2.11.2", "istanbul": "^0.3.5", "mocha": "^2.1.0" } } glob-parent-3.1.0/test.js000066400000000000000000000164211302426473300152520ustar00rootroot00000000000000'use strict'; var gp = require('./'); var assert = require('assert'); var isWin32 = require('os').platform() === 'win32'; describe('glob-parent', function() { it('should strip glob magic to return parent path', function() { assert.equal(gp('.'), '.'); assert.equal(gp('.*'), '.'); assert.equal(gp('/.*'), '/'); assert.equal(gp('/.*/'), '/'); assert.equal(gp('a/.*/b'), 'a'); assert.equal(gp('a*/.*/b'), '.'); assert.equal(gp('*/a/b/c'), '.'); assert.equal(gp('*'), '.'); assert.equal(gp('*/'), '.'); assert.equal(gp('*/*'), '.'); assert.equal(gp('*/*/'), '.'); assert.equal(gp('**'), '.'); assert.equal(gp('**/'), '.'); assert.equal(gp('**/*'), '.'); assert.equal(gp('**/*/'), '.'); assert.equal(gp('/*.js'), '/'); assert.equal(gp('*.js'), '.'); assert.equal(gp('**/*.js'), '.'); assert.equal(gp('{a,b}'), '.'); assert.equal(gp('/{a,b}'), '/'); assert.equal(gp('/{a,b}/'), '/'); assert.equal(gp('(a|b)'), '.'); assert.equal(gp('/(a|b)'), '/'); assert.equal(gp('./(a|b)'), '.'); assert.equal(gp('a/(b c)'), 'a', 'not an extglob'); assert.equal(gp('a/(b c)/'), 'a/(b c)', 'not an extglob'); assert.equal(gp('a/(b c)/d'), 'a/(b c)', 'not an extglob'); assert.equal(gp('path/to/*.js'), 'path/to'); assert.equal(gp('/root/path/to/*.js'), '/root/path/to'); assert.equal(gp('chapter/foo [bar]/'), 'chapter'); assert.equal(gp('path/[a-z]'), 'path'); assert.equal(gp('[a-z]'), '.'); assert.equal(gp('path/{to,from}'), 'path'); assert.equal(gp('path/(to|from)'), 'path'); assert.equal(gp('path/(foo bar)/subdir/foo.*'), 'path/(foo bar)/subdir'); assert.equal(gp('path/!(to|from)'), 'path'); assert.equal(gp('path/?(to|from)'), 'path'); assert.equal(gp('path/+(to|from)'), 'path'); assert.equal(gp('path/*(to|from)'), 'path'); assert.equal(gp('path/@(to|from)'), 'path'); assert.equal(gp('path/!/foo'), 'path/!'); assert.equal(gp('path/?/foo'), 'path', 'qmarks must be escaped'); assert.equal(gp('path/+/foo'), 'path/+'); assert.equal(gp('path/*/foo'), 'path'); assert.equal(gp('path/@/foo'), 'path/@'); assert.equal(gp('path/!/foo/'), 'path/!/foo'); assert.equal(gp('path/?/foo/'), 'path', 'qmarks must be escaped'); assert.equal(gp('path/+/foo/'), 'path/+/foo'); assert.equal(gp('path/*/foo/'), 'path'); assert.equal(gp('path/@/foo/'), 'path/@/foo'); assert.equal(gp('path/**/*'), 'path'); assert.equal(gp('path/**/subdir/foo.*'), 'path'); assert.equal(gp('path/subdir/**/foo.js'), 'path/subdir'); assert.equal(gp('path/!subdir/foo.js'), 'path/!subdir'); assert.equal(gp('path/{foo,bar}/'), 'path'); }); it('should respect escaped characters', function() { assert.equal(gp('path/\\*\\*/subdir/foo.*'), 'path/**/subdir'); assert.equal(gp('path/\\[\\*\\]/subdir/foo.*'), 'path/[*]/subdir'); assert.equal(gp('path/\\*(a|b)/subdir/foo.*'), 'path'); assert.equal(gp('path/\\*/(a|b)/subdir/foo.*'), 'path/*'); assert.equal(gp('path/\\*\\(a\\|b\\)/subdir/foo.*'), 'path/*(a|b)/subdir'); assert.equal(gp('path/\\[foo bar\\]/subdir/foo.*'), 'path/[foo bar]/subdir'); assert.equal(gp('path/\\[bar]/'), 'path/[bar]'); assert.equal(gp('path/\\[bar]'), 'path/[bar]'); assert.equal(gp('[bar]'), '.'); assert.equal(gp('[bar]/'), '.'); assert.equal(gp('./\\[bar]'), './[bar]'); assert.equal(gp('\\[bar]/'), '[bar]'); assert.equal(gp('[bar\\]/'), '.'); assert.equal(gp('path/foo \\[bar]/'), 'path/foo [bar]'); assert.equal(gp('path/\\{foo,bar}/'), 'path/{foo,bar}'); assert.equal(gp('\\{foo,bar}/'), '{foo,bar}'); assert.equal(gp('\\{foo,bar\\}/'), '{foo,bar}'); assert.equal(gp('{foo,bar\\}/'), '.'); if (!isWin32) { assert.equal(gp('\\[bar]'), '[bar]'); assert.equal(gp('[bar\\]'), '.'); assert.equal(gp('\\{foo,bar\\}'), '{foo,bar}'); assert.equal(gp('{foo,bar\\}'), '.'); } }); it('should respect glob enclosures with embedded separators', function() { assert.equal(gp('path/{,/,bar/baz,qux}/'), 'path'); assert.equal(gp('path/\\{,/,bar/baz,qux}/'), 'path/{,/,bar/baz,qux}'); assert.equal(gp('path/\\{,/,bar/baz,qux\\}/'), 'path/{,/,bar/baz,qux}'); assert.equal(gp('/{,/,bar/baz,qux}/'), '/'); assert.equal(gp('/\\{,/,bar/baz,qux}/'), '/{,/,bar/baz,qux}'); assert.equal(gp('{,/,bar/baz,qux}'), '.'); assert.equal(gp('\\{,/,bar/baz,qux\\}'), '{,/,bar/baz,qux}'); assert.equal(gp('\\{,/,bar/baz,qux}/'), '{,/,bar/baz,qux}'); assert.equal(gp('path/foo[a\\\/]/'), 'path'); assert.equal(gp('path/foo\\[a\\\/]/'), 'path/foo[a\\\/]'); assert.equal(gp('foo[a\\\/]'), '.'); assert.equal(gp('foo\\[a\\\/]'), 'foo[a\\\/]'); assert.equal(gp('path/(foo/bar|baz)'), 'path'); assert.equal(gp('path/(foo/bar|baz)/'), 'path'); assert.equal(gp('path/\\(foo/bar|baz)/'), 'path/(foo/bar|baz)'); }); it('should handle nested braces', function() { assert.equal(gp('path/{../,./,{bar,/baz\\},qux\\}/'), 'path'); assert.equal(gp('path/{../,./,\\{bar,/baz},qux}/'), 'path'); assert.equal(gp('path/\\{../,./,\\{bar,/baz\\},qux\\}/'), 'path/{../,./,{bar,/baz},qux}'); assert.equal(gp('{../,./,{bar,/baz\\},qux\\}/'), '.'); assert.equal(gp('{../,./,{bar,/baz\\},qux\\}'), '.'); assert.equal(gp('path/{,/,bar/{baz,qux\\}}/'), 'path'); assert.equal(gp('path/{,/,bar/{baz,qux}\\}/'), 'path'); //assert.equal(gp('path/\\{../,./,{bar,/baz},qux}/'), 'path'); }); it('should return parent dirname from non-glob paths', function() { assert.equal(gp('path'), '.'); assert.equal(gp('path/foo'), 'path'); assert.equal(gp('path/foo/'), 'path/foo'); assert.equal(gp('path/foo/bar.js'), 'path/foo'); }); }); describe('glob2base test patterns', function() { it('should get a base name', function() { assert.equal(gp('js/*.js'), 'js'); }); it('should get a base name from a nested glob', function() { assert.equal(gp('js/**/test/*.js'), 'js'); }); it('should get a base name from a flat file', function() { assert.equal(gp('js/test/wow.js'), 'js/test'); assert.equal(gp('js/test/wow.js'), 'js/test'); }); it('should get a base name from character class pattern', function() { assert.equal(gp('js/t[a-z]st}/*.js'), 'js'); }); it('should get a base name from brace , expansion', function() { assert.equal(gp('js/{src,test}/*.js'), 'js'); }); it('should get a base name from brace .. expansion', function() { assert.equal(gp('js/test{0..9}/*.js'), 'js'); }); it('should get a base name from extglob', function() { assert.equal(gp('js/t+(wo|est)/*.js'), 'js'); }); it('should get a base name from a path with non-exglob parens', function() { assert.equal(gp('js/t(wo|est)/*.js'), 'js'); assert.equal(gp('js/t/(wo|est)/*.js'), 'js/t'); }); it('should get a base name from a complex brace glob', function() { assert.equal(gp('lib/{components,pages}/**/{test,another}/*.txt'), 'lib'); assert.equal(gp('js/test/**/{images,components}/*.js'), 'js/test'); assert.equal(gp('ooga/{booga,sooga}/**/dooga/{eooga,fooga}'), 'ooga'); }); }); if (isWin32) { describe('technically invalid windows globs', function() { it('should manage simple globs with backslash path separator', function() { assert.equal(gp('C:\\path\\*.js'), 'C:/path') }); }); }