diff options
Diffstat (limited to 'node_modules/glob2base')
-rwxr-xr-x | node_modules/glob2base/LICENSE | 20 | ||||
-rw-r--r-- | node_modules/glob2base/README.md | 51 | ||||
-rw-r--r-- | node_modules/glob2base/index.js | 59 | ||||
-rw-r--r-- | node_modules/glob2base/package.json | 43 |
4 files changed, 173 insertions, 0 deletions
diff --git a/node_modules/glob2base/LICENSE b/node_modules/glob2base/LICENSE new file mode 100755 index 000000000..7cbe012c6 --- /dev/null +++ b/node_modules/glob2base/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2014 Fractal <contact@wearefractal.com> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/glob2base/README.md b/node_modules/glob2base/README.md new file mode 100644 index 000000000..c14fa38c3 --- /dev/null +++ b/node_modules/glob2base/README.md @@ -0,0 +1,51 @@ +# glob2base [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Support us][gittip-image]][gittip-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] + + +## Information + +<table> +<tr> +<td>Package</td><td>glob2base</td> +</tr> +<tr> +<td>Description</td> +<td>Extracts a base path from a node-glob instance</td> +</tr> +<tr> +<td>Node Version</td> +<td>>= 0.10</td> +</tr> +</table> + +## Usage + +The module is a function that takes in a node-glob instance and returns a string. Basically it just gives you everything before any globbing/matching happens. + +```javascript +var glob2base = require('glob2base'); +var glob = require('glob'); + +// js/ +glob2base(new glob.Glob('js/**/*.js')); + +// css/test/ +glob2base(new glob.Glob('css/test/{a,b}/*.css')); + +// pages/whatever/ +glob2base(new glob.Glob('pages/whatever/index.html')); +``` + +## Like what we do? + +[gittip-url]: https://www.gittip.com/WeAreFractal/ +[gittip-image]: http://img.shields.io/gittip/WeAreFractal.svg + +[downloads-image]: http://img.shields.io/npm/dm/glob2base.svg +[npm-url]: https://npmjs.org/package/glob2base +[npm-image]: http://img.shields.io/npm/v/glob2base.svg + +[travis-url]: https://travis-ci.org/wearefractal/glob2base +[travis-image]: http://img.shields.io/travis/wearefractal/glob2base.svg + +[coveralls-url]: https://coveralls.io/r/wearefractal/glob2base +[coveralls-image]: http://img.shields.io/coveralls/wearefractal/glob2base/master.svg diff --git a/node_modules/glob2base/index.js b/node_modules/glob2base/index.js new file mode 100644 index 000000000..307e3f27c --- /dev/null +++ b/node_modules/glob2base/index.js @@ -0,0 +1,59 @@ +'use strict'; + +var path = require('path'); +var findIndex = require('find-index'); + +var flattenGlob = function(arr){ + var out = []; + var flat = true; + for(var i = 0; i < arr.length; i++) { + if (typeof arr[i] !== 'string') { + flat = false; + break; + } + out.push(arr[i]); + } + + // last one is a file or specific dir + // so we pop it off + if (flat) { + out.pop(); + } + return out; +}; + +var flattenExpansion = function(set) { + var first = set[0]; + var toCompare = set.slice(1); + + // find index where the diff is + var idx = findIndex(first, function(v, idx){ + if (typeof v !== 'string') { + return true; + } + + var matched = toCompare.every(function(arr){ + return v === arr[idx]; + }); + + return !matched; + }); + + return first.slice(0, idx); +}; + +var setToBase = function(set) { + // normal something/*.js + if (set.length <= 1) { + return flattenGlob(set[0]); + } + // has expansion + return flattenExpansion(set); +}; + +module.exports = function(glob) { + var set = glob.minimatch.set; + var baseParts = setToBase(set); + var basePath = path.normalize(baseParts.join(path.sep))+path.sep; + return basePath; +}; diff --git a/node_modules/glob2base/package.json b/node_modules/glob2base/package.json new file mode 100644 index 000000000..1b7b9dd2f --- /dev/null +++ b/node_modules/glob2base/package.json @@ -0,0 +1,43 @@ +{ + "name": "glob2base", + "description": "Extracts a base path from a node-glob instance", + "version": "0.0.12", + "homepage": "http://github.com/wearefractal/glob2base", + "repository": { + "type": "git", + "url": "git://github.com/wearefractal/glob2base.git" + }, + "author": "Fractal <contact@wearefractal.com> (http://wearefractal.com/)", + "main": "./index.js", + "files": [ + "index.js", + "lib" + ], + "dependencies": { + "find-index": "^0.1.1" + }, + "devDependencies": { + "coveralls": "^2.6.1", + "istanbul": "^0.3.2", + "jshint": "^2.4.1", + "jshint-stylish": "^1.0.0", + "mocha": "^2.0.0", + "mocha-lcov-reporter": "^0.0.1", + "glob": "^4.0.0", + "should": "^4.0.0" + }, + "scripts": { + "lint": "jshint index.js --reporter node_modules/jshint-stylish/stylish.js --exclude node_modules", + "test": "npm run-script lint && mocha --reporter spec", + "coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" + }, + "engines": { + "node": ">= 0.10" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://github.com/wearefractal/glob2base/raw/master/LICENSE" + } + ] +} |