Comparing version
52
index.js
@@ -10,6 +10,6 @@ /*! | ||
var path = require('path'); | ||
var isGlob = require('is-glob'); | ||
var isObject = require('isobject'); | ||
var parse = require('parse-filepath'); | ||
var mm = require('micromatch'); | ||
var path = require('path'); | ||
@@ -24,25 +24,19 @@ function matchFile(name, file) { | ||
return (name === file.key) | ||
|| (name === file.history[0]) | ||
|| (name === file.path) | ||
|| (name === file.relative) | ||
|| (name === file.basename) | ||
|| (name === file.stem) | ||
|| (path.resolve(file.path) === path.resolve(name)) | ||
|| matchOrig(name, file); | ||
return endsWith(file.history[0], name) | ||
|| endsWith(file.path, name) | ||
|| file.stem === name | ||
|| file.key === name; | ||
} | ||
function matchOrig(name, file) { | ||
var orig = parse(file.history[0]); | ||
return (name === orig.path) | ||
|| (name === orig.relative) | ||
|| (name === orig.basename) | ||
|| (name === orig.stem); | ||
} | ||
matchFile.matcher = function(pattern, options) { | ||
if (typeof pattern !== 'string' && !Array.isArray(pattern)) { | ||
throw new TypeError('expected pattern to be a string or array'); | ||
if (typeof pattern !== 'string') { | ||
throw new TypeError('expected pattern to be a string'); | ||
} | ||
if (!isGlob(pattern)) { | ||
return function(file) { | ||
return matchFile(pattern, file); | ||
}; | ||
} | ||
var isMatch = mm.matcher(pattern, options); | ||
@@ -58,6 +52,6 @@ return function(file) { | ||
|| isMatch(file.path) | ||
|| isMatch(path.resolve(file.path)) | ||
|| isMatch(file.relative) | ||
|| isMatch(file.basename) | ||
|| isMatch(file.stem) | ||
|| isMatch(path.resolve(file.path)); | ||
|| isMatch(file.stem); | ||
}; | ||
@@ -70,2 +64,16 @@ }; | ||
function endsWith(filepath, name) { | ||
if (name.slice(0, 2) === './') { | ||
name = name.slice(2); | ||
} | ||
var len = name.length; | ||
var isMatch = filepath.slice(-len) === name; | ||
if (isMatch) { | ||
var ch = filepath.slice(-(len + 1), -len); | ||
return ch === '' || ch === '/' || ch === '\\'; | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -72,0 +80,0 @@ * Expose `matchFile` |
{ | ||
"name": "match-file", | ||
"description": "Returns true when the given `name` matches any of the path properties on a vinyl file.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/jonschlinkert/match-file", | ||
@@ -23,5 +23,5 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"is-glob": "^3.1.0", | ||
"isobject": "^3.0.0", | ||
"micromatch": "^2.3.11", | ||
"parse-filepath": "^1.0.1" | ||
"micromatch": "^2.3.11" | ||
}, | ||
@@ -28,0 +28,0 @@ "devDependencies": { |
@@ -226,6 +226,6 @@ # match-file [](https://www.npmjs.com/package/match-file) [](https://npmjs.org/package/match-file) [](https://npmjs.org/package/match-file) [](https://travis-ci.org/jonschlinkert/match-file) | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
MIT | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 01, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 24, 2017._ |
12363
0.55%66
10%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed