{"id":38906562,"url":"https://github.com/streamich/glob-to-regex","last_synced_at":"2026-01-17T15:09:23.952Z","repository":{"id":311417350,"uuid":"1043655893","full_name":"streamich/glob-to-regex","owner":"streamich","description":"Converts a GLOB pattern to JavaScript RegExp","archived":false,"fork":false,"pushed_at":"2025-10-15T08:55:49.000Z","size":2160,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-13T16:24:04.420Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"streamich"}},"created_at":"2025-08-24T10:41:56.000Z","updated_at":"2025-10-15T08:55:53.000Z","dependencies_parsed_at":"2025-08-24T15:53:10.419Z","dependency_job_id":"035bf348-94e9-42dd-9864-b3231e7c06be","html_url":"https://github.com/streamich/glob-to-regex","commit_stats":null,"previous_names":["streamich/glob-to-regex"],"tags_count":4,"template":false,"template_full_name":"streamich/template-js-library","purl":"pkg:github/streamich/glob-to-regex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fglob-to-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fglob-to-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fglob-to-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fglob-to-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamich","download_url":"https://codeload.github.com/streamich/glob-to-regex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fglob-to-regex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28510937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-17T15:09:23.226Z","updated_at":"2026-01-17T15:09:23.935Z","avatar_url":"https://github.com/streamich.png","language":"TypeScript","funding_links":["https://github.com/sponsors/streamich"],"categories":[],"sub_categories":[],"readme":"# glob-to-regex.js\n\nTransform GLOB patterns to JavaScript regular expressions for fast file path matching.\n\nThis tiny library converts familiar shell-style glob patterns like `**/*.ts` or `src/{a,b}/**/*.js` into JavaScript `RegExp` objects and provides a convenient matcher utility.\n\n## Install\n\n```bash\nyarn add glob-to-regex.js\n# or\nnpm i glob-to-regex.js\n```\n\n## Quick start\n\n```ts\nimport {toRegex, toMatcher} from 'glob-to-regex.js';\n\n// Build a RegExp from a glob\nconst re = toRegex('src/**/test.ts');\nre.test('src/a/b/test.ts'); // true\nre.test('src/test.ts');     // true\nre.test('src/test.tsx');    // false\n\n// Build a predicate function from a pattern or an array of patterns\nconst match = toMatcher(['**/*.ts', '!**/*.d.ts']); // negative patterns are not special; use a RegExp if needed\nmatch('index.ts');    // true\nmatch('types.d.ts');  // true (negation is not parsed specially)\n```\n\n## API\n\n- toRegex(pattern: string): RegExp\n\t- Converts a glob pattern to an anchored regular expression (`^...$`).\n\n- toMatcher(pattern: string | RegExp | Array\u003cstring | RegExp\u003e): (path: string) =\u003e boolean\n\t- Accepts a glob string, a RegExp, or an array of them. If given an array, it returns true if any item matches (logical OR, short-circuited).\n\t- Strings starting with `/` and ending with `/flags?` are treated as regular expressions (e.g. `\"/\\\\.test\\\\.ts$/\"`).\n\n## Supported glob features\n\n- `/` separates path segments\n- `*` matches zero or more characters within a single segment (does not cross `/`)\n- `?` matches exactly one character within a single segment\n- `**` matches across path segments, including none\n- `{a,b,c}` alternation groups (no nesting). Each item inside can itself contain glob syntax\n- Character classes: `[abc]`, `[a-z]`, `[!a-z]`, `[!abc]`\n- **Extended globbing** (when `extglob: true` option is set):\n  - `?(pattern-list)` matches zero or one occurrence of the given patterns\n  - `*(pattern-list)` matches zero or more occurrences of the given patterns\n  - `+(pattern-list)` matches one or more occurrences of the given patterns\n  - `@(pattern-list)` matches exactly one of the given patterns\n  - `!(pattern-list)` matches anything except one of the given patterns\n  - Pattern lists use `|` as separator (e.g., `@(jpg|png|gif)`)\n\nNotes:\n- The produced RegExp is anchored at start and end (`^...$`).\n- Character classes are copied through to the output regex. Use standard JavaScript class syntax.\n- Brace groups are not nestable. If an unmatched `{` is found, it is treated literally.\n\n## Examples\n\n```ts\ntoRegex('a/b/c.txt').test('a/b/c.txt'); // true\ntoRegex('a/*.txt').test('a/file.txt');  // true\ntoRegex('a/*.txt').test('a/x/y.txt');   // false\ntoRegex('file?.js').test('file1.js');   // true\ntoRegex('src/**/test.ts').test('src/a/b/test.ts'); // true\ntoRegex('assets/**').test('assets/a/b.png');       // true\ntoRegex('*.{html,txt}').test('page.html');         // true\ntoRegex('src/{a,b}/**/*.ts').test('src/b/x/y.ts'); // true\ntoRegex('file[0-9].txt').test('file5.txt');        // true\ntoRegex('file[!0-9].txt').test('filea.txt');       // true\ntoRegex('**/*.[jt]s{,x}').test('dir/a/b.jsx');     // true\n\n// Extended globbing examples\ntoRegex('file?(s).txt', {extglob: true}).test('file.txt');  // true\ntoRegex('file?(s).txt', {extglob: true}).test('files.txt'); // true\ntoRegex('file.@(jpg|png|gif)', {extglob: true}).test('file.jpg'); // true\ntoRegex('/var/log/!(*.gz)', {extglob: true}).test('/var/log/syslog'); // true\ntoRegex('/var/log/!(*.gz)', {extglob: true}).test('/var/log/error.log.gz'); // false\ntoRegex('src/**/!(*.test).js', {extglob: true}).test('src/app.test.js'); // false\ntoRegex('src/**/!(*.test).js', {extglob: true}).test('src/index.js'); // true\n```\n\n## TypeScript\n\nTypes are bundled. The library targets modern Node.js and browsers.\n\n## Performance\n\n`toRegex` performs a single pass over the pattern and creates a native RegExp. Matching is then performed by V8's highly optimized engine.\n\n## Limitations\n\n- Brace groups are not nested.\n- Negated globs like `!**/*.d.ts` are not parsed specially. If you need exclusion, combine multiple matchers or filter results separately.\n\n## License\n\nApache-2.0 © streamich\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamich%2Fglob-to-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamich%2Fglob-to-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamich%2Fglob-to-regex/lists"}