{"id":19592324,"url":"https://github.com/smikhalevski/route-pattern","last_synced_at":"2025-06-25T19:32:58.444Z","repository":{"id":48418806,"uuid":"371498001","full_name":"smikhalevski/route-pattern","owner":"smikhalevski","description":"🔀 The path pattern parser, that supports named variables, variable constraints, bash-like alternation, regular expressions, and wildcards.","archived":false,"fork":false,"pushed_at":"2022-01-04T16:04:50.000Z","size":706,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T04:04:36.361Z","etag":null,"topics":["parser","path","pattern","route","tokenizer","url"],"latest_commit_sha":null,"homepage":"https://smikhalevski.github.io/route-pattern/","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/smikhalevski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-27T20:36:53.000Z","updated_at":"2022-05-26T16:35:09.000Z","dependencies_parsed_at":"2022-09-09T02:20:15.775Z","dependency_job_id":null,"html_url":"https://github.com/smikhalevski/route-pattern","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smikhalevski%2Froute-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smikhalevski%2Froute-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smikhalevski%2Froute-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smikhalevski%2Froute-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smikhalevski","download_url":"https://codeload.github.com/smikhalevski/route-pattern/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240867427,"owners_count":19870405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["parser","path","pattern","route","tokenizer","url"],"created_at":"2024-11-11T08:34:38.854Z","updated_at":"2025-02-26T14:15:07.465Z","avatar_url":"https://github.com/smikhalevski.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# route-pattern [![build](https://github.com/smikhalevski/route-pattern/actions/workflows/master.yml/badge.svg?branch=master\u0026event=push)](https://github.com/smikhalevski/route-pattern/actions/workflows/master.yml)\n\nThe path pattern parser, that supports named variables, variable constraints, bash-like alternation, regular\nexpressions, and wildcards.\n\nThis package is\ntiny, [just 2.2 kB gzipped including dependencies.](https://bundlephobia.com/package/@smikhalevski/route-pattern)\n\n```sh\nnpm install --save-prod @smikhalevski/route-pattern\n```\n\n# Usage\n\n```ts\nimport {convertPatternToRegExp} from '@smikhalevski/route-pattern';\n\nconst re = convertPatternToRegExp('/(\\\\d+)/:foo{ bar, qux }');\nconst match = re.exec('/123/bar');\n\nconsole.log(match?.groups?.foo); // → 'bar'\n```\n\nThe support of named capturing groups **is not required** from the environment.\n\n# Features\n\n`/foo/bar` is a literal path that is matched as is.\n\nSpaces, tabs, and newlines are ignored, so `/ foo / bar` is the same as `/foo/bar`, and `/foo  bar` is the same\nas `/foobar` (note the absent spaces).\n\nIf you want to preserve spaces, use quotes: `/\" foo bar\"`.\n\n## Regular expression\n\n`(\\\\d+)` declares a regular expression, spaces have meaning inside a regular expression.\n\nRegExps can contain a named capturing groups which are merged with variables. For example, `/:foo/(?\u003cbar\u003eabc)` would\nmatch `/123/abc` and groups would be `{foo: '123', bar: 'abc'}`.\n\n## Wildcards\n\n`*` declares a wildcard that matches everything except the path separator. For example, `/foo/*/bar` would\nmatch `/foo/okay/bar` and `/foo//bar` but won't match `/foo/no/sir/bar`.\n\n`**` declares a greedy wildcard that matches everything, even path separators. For example, `/foo/**/bar` would\nmatch `/foo/okay/bar`, `/foo//bar` and `/foo/no/sir/bar`.\n\nIf you want to match at least one character, use a regular expression instead of a wildcard. For\nexample, `/foo/([^/]+)/bar` would match `/foo/okay/bar` and won't match `/foo//bar`.\n\n## Alternation\n\n`{ foo, bar }` declares an alternation: `foo` or `bar`.\n\nAlternation supports nesting, for example `/foo{ -bar, /(\\\\d+)/qux }` would match `/foo-bar` and `/foo/123/qux`.\n\n## Variables\n\n`:foo` declares a variable. Variable name should match `^[A-Za-z0-9$_]+$`.\n\nBy default, variables match everything except the path separator.\n\nA single pattern that immediately follows the variable declaration is treated as a variable constraint. For example,`:foo bar` and `:foo\"bar\"` would both read variable `foo` and treat `bar` as its string literal constraint.\n\n`:foo(\\\\d+)` declares a variable whose value is constrained by a regular expression.\n\n`:foo{ a, b }` declares a variable whose value is constrained by an alternation.\n\n`:foo{**}` variables can be constrained with wildcards.\n\nVariables can be nested through an alternation: `/aaa/ :foo{ /bbb, /ccc/:bar }`.\n\nVariables are not treated as constraints for other variables. For example, `:foo:bar{abc}` would match `123abc` and\ngroups would be `{foo: '123', bar: 'abc'}`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmikhalevski%2Froute-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmikhalevski%2Froute-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmikhalevski%2Froute-pattern/lists"}