@se-oss/glob
v1.0.0
Published
A high-performance, compiler-grade glob matching and parsing library for TypeScript and JavaScript.
Maintainers
Readme
@se-oss/glob compiles glob patterns into highly optimized regular expressions to deliver a blazing fast, compiler-grade matching engine with strict syntax checking.
📦 Installation
npm install @se-oss/globpnpm
pnpm install @se-oss/globyarn
yarn add @se-oss/glob📖 Usage
Basic Usage
Check if an input string matches a pattern or multiple patterns.
import { isMatch } from '@se-oss/glob';
isMatch('foo/bar.ts', 'foo/**/*.ts'); // true
isMatch('foo/b.ts', ['foo/**/*.ts', '!foo/b.ts']); // falseCompiler Matcher
Compile a glob pattern once into a highly optimized matcher function for repeated matches.
import { compile } from '@se-oss/glob';
const isTs = compile('foo/*.ts');
isTs('foo/bar.ts'); // true
isTs('foo/bar/baz.ts'); // falseRegular Expression
Compile a glob pattern directly into a JavaScript RegExp object.
import { makeRe } from '@se-oss/glob';
const regex = makeRe('foo/*.ts');
regex.test('foo/bar.ts'); // trueScanning
Extract the leading static path (base) and determine if a pattern contains dynamic glob features.
import { scan } from '@se-oss/glob';
scan('foo/bar/*.js');
// { base: 'foo/bar', isDynamic: true, pattern: 'foo/bar/*.js' }Partial Matching
Check if a path is a partial match for a glob pattern. Highly useful for file watchers and tree traversals to skip scanning directories early.
import { isPartialMatch } from '@se-oss/glob';
isPartialMatch('src/app', 'src/**/*.ts'); // true
isPartialMatch('dist', 'src/**/*.ts'); // falseAST Parsing
Parse a glob pattern safely to validate or inspect its Abstract Syntax Tree (AST).
import { safeParse } from '@se-oss/glob';
const result = safeParse('src/**/*.ts');
if (result.success) {
console.log(result.data); // AST Node
}📚 Documentation
For all configuration options, please see the API docs.
🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated! 🙏
License
MIT © Shahrad Elahi and contributors.
