Comparing version 0.1.0 to 0.2.0
43
index.js
@@ -10,10 +10,11 @@ /*! | ||
var mm = require('micromatch'); | ||
var path = require('path'); | ||
module.exports = function matchFile(name, file) { | ||
function matchFile(name, file) { | ||
if (typeof name !== 'string') { | ||
throw new TypeError('expected a string'); | ||
throw new TypeError('expected name to be a string'); | ||
} | ||
if (!isObject(file)) { | ||
throw new TypeError('expected an object'); | ||
throw new TypeError('expected file to be an object'); | ||
} | ||
@@ -27,6 +28,42 @@ | ||
|| (path.resolve(file.path) === path.resolve(name)); | ||
} | ||
matchFile.matcher = function(pattern, options) { | ||
if (typeof pattern !== 'string' && !Array.isArray(pattern)) { | ||
throw new TypeError('expected pattern to be a string or array'); | ||
} | ||
var isMatch = mm.matcher(pattern, options); | ||
return function(file) { | ||
if (typeof file === 'string') { | ||
return isMatch(file); | ||
} | ||
return (pattern === file.key) | ||
|| (pattern === file.path) | ||
|| (pattern === file.relative) | ||
|| (pattern === file.basename) | ||
|| (pattern === file.stem) | ||
|| (path.resolve(file.path) === path.resolve(pattern)) | ||
|| isMatch(file.key) | ||
|| isMatch(file.path) | ||
|| isMatch(file.relative) | ||
|| isMatch(file.basename) | ||
|| isMatch(file.stem) | ||
|| isMatch(path.resolve(file.path)); | ||
}; | ||
}; | ||
matchFile.isMatch = function(patterns, file, options) { | ||
return matchFile.matcher(patterns, options)(file); | ||
}; | ||
function isObject(val) { | ||
return val && typeof val === 'object'; | ||
} | ||
/** | ||
* Expose `matchFile` | ||
*/ | ||
module.exports = matchFile; |
{ | ||
"name": "match-file", | ||
"description": "Returns true when the given `name` matches any of the path properties on a vinyl file", | ||
"version": "0.1.0", | ||
"description": "Returns true when the given `name` matches any of the path properties on a vinyl file.", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/jonschlinkert/match-file", | ||
@@ -22,6 +22,14 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"micromatch": "^2.3.8" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^0.1.5", | ||
"mocha": "^2.3.4", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^2.0.0", | ||
"gulp-format-md": "^0.1.9", | ||
"gulp-istanbul": "^0.10.4", | ||
"gulp-mocha": "^2.2.0", | ||
"lazy-cache": "^1.0.4", | ||
"mocha": "^2.4.5", | ||
"through2": "^2.0.1", | ||
"vinyl": "^1.1.1" | ||
@@ -40,3 +48,2 @@ }, | ||
"verb": { | ||
"layout": "default", | ||
"plugins": [ | ||
@@ -48,9 +55,22 @@ "gulp-format-md" | ||
"assemble", | ||
"verb", | ||
"templates", | ||
"gulp", | ||
"vinyl" | ||
"generate", | ||
"get-view", | ||
"micromatch", | ||
"verb" | ||
] | ||
} | ||
}, | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
}, | ||
"reflinks": [ | ||
"micromatch", | ||
"gulp", | ||
"verb" | ||
] | ||
} | ||
} |
11012
56
234
1
9
+ Addedmicromatch@^2.3.8
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)