{"id":18821375,"url":"https://github.com/borderless/router","last_synced_at":"2025-06-17T18:34:26.177Z","repository":{"id":39702854,"uuid":"383340996","full_name":"borderless/router","owner":"borderless","description":"Simple pathname router that makes zero assumptions about the server","archived":false,"fork":false,"pushed_at":"2023-12-12T06:37:11.000Z","size":1098,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-22T10:12:02.254Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borderless.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-07-06T04:39:59.000Z","updated_at":"2022-05-16T21:52:06.000Z","dependencies_parsed_at":"2025-05-22T10:12:06.421Z","dependency_job_id":"0438b81d-1ad0-4c83-b195-85f9808b9916","html_url":"https://github.com/borderless/router","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/borderless/router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borderless","download_url":"https://codeload.github.com/borderless/router/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Frouter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260419180,"owners_count":23006230,"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":[],"created_at":"2024-11-08T00:39:53.363Z","updated_at":"2025-06-17T18:34:21.168Z","avatar_url":"https://github.com/borderless.png","language":"TypeScript","readme":"# Router\n\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][downloads-image]][downloads-url]\n[![Build status][build-image]][build-url]\n[![Build coverage][coverage-image]][coverage-url]\n\n\u003e Simple pathname router that makes zero assumptions about the server.\n\n## Installation\n\n```sh\nnpm install @borderless/router --save-dev\n```\n\n## Usage\n\n```ts\nexport declare function createRouter(\n  routes: string[]\n): (pathname: string) =\u003e Iterable\u003cResult\u003e;\n```\n\nExposes a simple `createRouter` function that accepts a list of routes. It returns a function that accepts the pathname as input and returns an iterable of results. Results are an object containing the `route` that matched, and list `keys` and `values` (if any) that were extracted from dynamic matches.\n\n```js\nimport { createRouter } from \"@borderless/router\";\n\nconst router = createRouter([\n  \"a\",\n  \"b\",\n  \"[param]\",\n  \"@[param]\",\n  \"[param1]/[param2]\",\n]);\n\nconst results = Array.from(router(\"a\"));\n\nexpect(results).toEqual([\n  { route: \"a\", keys: [], values: [] },\n  { route: \"[param]\", keys: [\"param\"], values: [\"a\"] },\n]);\n```\n\nSince the result is an iterable, if you only want the first match you can discard the iterable to stop computing results.\n\n```js\nconst results = router(\"a\");\nfor (const result of results) {\n  console.log(result); //=\u003e { route: \"a\", keys: [], values: [] }\n  break;\n}\n```\n\nThe routes are pre-sorted to match the most specific routes first (i.e. static routes or most segments), it is not based on the input order. The internal representation is a trie.\n\n## TypeScript\n\nThis project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/@borderless/router\n[npm-url]: https://npmjs.org/package/@borderless/router\n[downloads-image]: https://img.shields.io/npm/dm/@borderless/router\n[downloads-url]: https://npmjs.org/package/@borderless/router\n[build-image]: https://img.shields.io/github/workflow/status/borderless/router/CI/main\n[build-url]: https://github.com/borderless/router/actions/workflows/ci.yml?query=branch%3Amain\n[coverage-image]: https://img.shields.io/codecov/c/gh/borderless/router\n[coverage-url]: https://codecov.io/gh/borderless/router\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborderless%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborderless%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborderless%2Frouter/lists"}