Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ff0388

Browse files
committed
document, expose, and test 'partial:true' option
1 parent5dbd6a7 commit2ff0388

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

‎README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ Suppress the behavior of treating a leading `!` character as negation.
171171
Returns from negate expressions the same as if they were not negated.
172172
(Ie, true on a hit, false on a miss.)
173173

174+
###partial
175+
176+
Compare a partial path to a pattern. As long as the parts of the path that
177+
are present are not contradicted by the pattern, it will be treated as a
178+
match. This is useful in applications where you're walking through a
179+
folder structure, and don't yet have the full path, but want to ensure that
180+
you do not walk down paths that can never be a match.
181+
182+
For example,
183+
184+
```js
185+
minimatch('/a/b','/a/*/c/d', { partial:true })// true, might be /a/b/c/d
186+
minimatch('/a/b','/**/d', { partial:true })// true, might be /a/b/.../d
187+
minimatch('/x/y/z','/a/**/z', { partial:true })// false, because x !== a
188+
```
189+
174190
##Comparisons to other fnmatch/glob implementations
175191

176192
While strict compliance with the existing standards is a worthwhile

‎minimatch.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ function Minimatch (pattern, options) {
146146
this.negate=false
147147
this.comment=false
148148
this.empty=false
149+
this.partial=!!options.partial
149150

150151
// make the set of regexps etc.
151152
this.make()
@@ -719,13 +720,15 @@ minimatch.match = function (list, pattern, options) {
719720
returnlist
720721
}
721722

722-
Minimatch.prototype.match=functionmatch(f){
723+
Minimatch.prototype.match=functionmatch(f,partial=this.partial){
723724
this.debug('match',f,this.pattern)
724725
// short-circuit in the case of busted things.
725726
// comments, etc.
726727
if(this.comment)returnfalse
727728
if(this.empty)returnf===''
728729

730+
if(f==='/'&&partial)returntrue
731+
729732
varoptions=this.options
730733

731734
// windows: need to use /, not \
@@ -759,7 +762,7 @@ Minimatch.prototype.match = function match (f) {
759762
if(options.matchBase&&pattern.length===1){
760763
file=[filename]
761764
}
762-
varhit=this.matchOne(file,pattern,false)
765+
varhit=this.matchOne(file,pattern,partial)
763766
if(hit){
764767
if(options.flipNegate)returntrue
765768
return!this.negate

‎test/partial.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
constt=require('tap')
2+
constmm=require('../')
3+
t.equal(mm('/a/b','/*/b/x/y/z',{partial:true}),true)
4+
t.equal(mm('/a/b/c','/*/b/x/y/z',{partial:true}),false)
5+
t.equal(mm('/','x',{partial:true}),true)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp