anymatch icon indicating copy to clipboard operation
anymatch copied to clipboard

dot in testString as pathname or filename, can't match

Open Alucelx opened this issue 4 years ago • 0 comments

use case is that, first new a matcher in anymatch, 2nd use the matcher to match teststring. if teststring is path string and some path or file has dot symbol, will match failed, the example at flow:

const matcher = anymatch(["**/node_modules/**"]);
const str = "abs/node_modules/.path/file.js";
const str2 = "abs/node_modules/.file.js";
const result = matcher(str); // false
const result2 = matcher(str2); // false

then i review the source code of anymatch, and i found a solution:

const matcher = anymatch(["**/node_modules/**"], null, {dot: true});
const str = "abs/node_modules/.path/file.js";
const str2 = "abs/node_modules/.file.js";
const result = matcher(str); // true  // ts checker error
const result2 = matcher(str2); // true // ts checker error

but if this code is in ts, the ide tell me an error of checker at the line that match the test string, because anymatch/index.d.ts dosn't have this override, so we should add a comment to tell checker to ignore this line.

const matcher = anymatch(["**/node_modules/**"], null, {dot: true});
const str = "abs/node_modules/.path/file.js";
const str2 = "abs/node_modules/.file.js";
// @ts-ignore
const result = matcher(str); // true
// @ts-ignore
const result2 = matcher(str2); // true

Alucelx avatar May 14 '21 10:05 Alucelx