@se-oss/glob-parser
v1.0.0
Published
High-performance parser and lexer for glob patterns
Readme
@se-oss/glob-parser is a high-performance parser and lexer for glob patterns, built to construct compliant Abstract Syntax Trees (AST).
📦 Installation
npm install @se-oss/glob-parserpnpm
pnpm install @se-oss/glob-parseryarn
yarn add @se-oss/glob-parser📖 Usage
Basic Usage
Convert a glob pattern into a list of tokens and compile it into a standard AST.
import { Lexer, Parser } from '@se-oss/glob-parser';
const tokens = new Lexer('src/**/*.ts').tokenize();
const ast = new Parser(tokens).parse();Advanced Options
Toggle features like Windows path normalization and disabling extglobs.
const lexer = new Lexer('foo\\*bar', {
windows: false, // Do not normalize backslash to forward slash
unescape: true, // Retain escape characters in tokens
});AST Optimization
The parser automatically compresses redundant globstars and consecutive wildcards.
// "foo/**/**/**/bar" resolves to a single globstar segment
const tokens = new Lexer('foo/**/**/**/bar').tokenize();
const ast = new Parser(tokens).parse();Strict Syntax Validation
Enable strict checks to throw syntax errors on unbalanced braces, brackets, or extglobs.
import { Lexer, Parser } from '@se-oss/glob-parser';
try {
const tokens = new Lexer('{foo,bar').tokenize();
const ast = new Parser(tokens, { strict: true }).parse();
} catch (err) {
console.error(err.message);
// Unclosed brace "{" at position 0
}📚 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.
