diff --git a/README.md b/README.md index 3d76a142..a8399e9a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index cceedcf6..ee0f7738 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "minimatch", - "version": "6.1.10", + "version": "6.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "minimatch", - "version": "6.1.10", + "version": "6.2.0", "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" diff --git a/package.json b/package.json index d90d6ebd..58f289ad 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Isaac Z. Schlueter (http://blog.izs.me)", "name": "minimatch", "description": "a glob matcher in javascript", - "version": "6.1.10", + "version": "6.2.0", "repository": { "type": "git", "url": "git://github.com/isaacs/minimatch.git" diff --git a/src/index.ts b/src/index.ts index 8f4084c8..d62c897d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ export interface MinimatchOptions { partial?: boolean dot?: boolean nocase?: boolean + nocaseMagicOnly?: boolean matchBase?: boolean flipNegate?: boolean preserveMultipleSlashes?: boolean @@ -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() } diff --git a/test/basic.js b/test/basic.js index 5b3e9940..ff44d71a 100644 --- a/test/basic.js +++ b/test/basic.js @@ -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() +})