Skip to content

Commit

Permalink
Add nocaseMagicOnly flag
Browse files Browse the repository at this point in the history
Glob is faster when comparing strings, and path-scurry handles
case-insensitive file systems anyway.
  • Loading branch information
isaacs committed Feb 13, 2023
1 parent 6b9f9b0 commit 2dd252a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ Disable "extglob" style patterns like `+(a|b)`.

Perform a case-insensitive match.

### nocaseMagicOnly

When used with `{nocase: true}`, create regular expressions that
are case-insensitive, but leave string match portions untouched.
Has no effect when used without `{nocase: true}`

Useful when some other form of case-insensitive matching is used,
or if the original string representation is useful in some other
way.

### nonull

When a match is not found by `minimatch.match`, return a list containing
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface MinimatchOptions {
partial?: boolean
dot?: boolean
nocase?: boolean
nocaseMagicOnly?: boolean
matchBase?: boolean
flipNegate?: boolean
preserveMultipleSlashes?: boolean
Expand Down Expand Up @@ -1087,7 +1088,7 @@ export class Minimatch {
}

// if it's nocase, and the lcase/uppercase don't match, it's magic
if (options.nocase && !hasMagic) {
if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
hasMagic = pattern.toUpperCase() !== pattern.toLowerCase()
}

Expand Down
19 changes: 18 additions & 1 deletion test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,25 @@ t.test('globstar re matches zero or more path portions', t => {
t.end()
})

t.test('do not create empty pattern via ..', t =>{
t.test('do not create empty pattern via ..', t => {
const m = new mm.Minimatch('*/..')
t.same(m.globParts, [['']])
t.end()
})

t.test('option to only nocase regexps, not strings', t => {
t.match(
new mm.Minimatch('test/*.js', {
nocase: true,
nocaseMagicOnly: true,
}).set,
[['test', /^(?!\.)(?=.)[^/]*?\.js$/i]]
)
t.match(
new mm.Minimatch('test/*.js', {
nocase: true,
}).set,
[[/^test$/i, /^(?!\.)(?=.)[^/]*?\.js$/i]]
)
t.end()
})

0 comments on commit 2dd252a

Please sign in to comment.