cspell-glob
v10.4.0
Published
Glob matcher for cspell
Downloads
7,813,047
Readme
cspell-glob
A simple library for checking filenames against a set of glob rules. It attempts to emulate the .gitignore rules.
Purpose
The purpose behind this library is a bit different than the other glob matchers. The goal here is to see if a file name matches a glob, not to find files that match globs. This library doesn't do any file i/o. It uses micromatch under the hood for the actual matching.
Usage
import { GlobMatcher } from 'cspell-glob';
// Patterns behave like the contents of a `.gitignore` file.
const patterns = ['*.test.js', '!important.test.js'];
const matcher = new GlobMatcher(patterns, process.cwd());
matcher.match('src/app.test.js'); // true -- matches `*.test.js`
matcher.match('src/important.test.js'); // false -- excluded by the negated pattern
matcher.match('src/app.js'); // false -- does not match any patternBy default, GlobMatcher runs in exclude mode (like .gitignore). Use include mode when searching for
files to check, where patterns must be more explicit to match:
const matcher = new GlobMatcher(['src/**/*.ts'], { root: process.cwd(), mode: 'include' });
matcher.match('src/app.ts'); // true
matcher.match('node_modules/lib/index.ts'); // false