Comparing version 0.2.1 to 0.2.2
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 [![NPM version](https://img.shields.io/npm/v/match-file.svg?style=flat)](https://www.npmjs.com/package/match-file) [![NPM monthly downloads](https://img.shields.io/npm/dm/match-file.svg?style=flat)](https://npmjs.org/package/match-file) [![NPM total downloads](https://img.shields.io/npm/dt/match-file.svg?style=flat)](https://npmjs.org/package/match-file) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/match-file.svg?style=flat&label=Travis)](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
66
4771
+ Addedis-glob@^3.1.0
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@3.1.0(transitive)
- Removedparse-filepath@^1.0.1
- Removedis-absolute@1.0.0(transitive)
- Removedis-relative@1.0.0(transitive)
- Removedis-unc-path@1.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedparse-filepath@1.0.2(transitive)
- Removedpath-root@0.1.1(transitive)
- Removedpath-root-regex@0.1.2(transitive)
- Removedunc-path-regex@0.1.2(transitive)