Glob pattern matching — minimatch alternative for runtime use
npm install @philiprehberger/glob-matchGlob pattern matching -- minimatch alternative for runtime use.
npm install @philiprehberger/glob-match
import { globMatch, globFilter, globToRegex } from '@philiprehberger/glob-match';
globMatch('*.ts', 'index.ts');
// => true
globMatch('src/**/*.ts', 'src/utils/helper.ts');
// => true
globMatch('*.{ts,js}', 'index.css');
// => false
globFilter('*.ts', ['index.ts', 'utils.ts', 'style.css']);
// => ['index.ts', 'utils.ts']
const regex = globToRegex('*.ts');
// => /^[^/]*\.ts$/
globToRegex(pattern: string, options?: GlobOptions): RegExpConvert a glob pattern to a regular expression.
globMatch(pattern: string, str: string, options?: GlobOptions): booleanTest whether a string matches a glob pattern.
globFilter(pattern: string, strings: string[], options?: GlobOptions): string[]Filter an array of strings, returning only those that match the glob pattern.
GlobOptions| Option | Type | Default | Description |
|---|---|---|---|
caseSensitive | boolean | true | Whether matching is case-sensitive |
| Pattern | Description |
|---|---|
* | Match any characters except / |
** | Match any characters including / |
? | Match a single character |
{a,b,c} | Match any of the alternatives |
[abc] | Match any character in the set |
npm install
npm run build
npm test
If you find this project useful: