{"id":18552486,"url":"https://github.com/andrejewski/tagged-routes","last_synced_at":"2025-05-15T11:13:15.968Z","repository":{"id":65514040,"uuid":"117781757","full_name":"andrejewski/tagged-routes","owner":"andrejewski","description":"Routing with tagged unions","archived":false,"fork":false,"pushed_at":"2020-05-11T17:14:45.000Z","size":76,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T00:02:40.414Z","etag":null,"topics":["routing","tagged-unions"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/andrejewski.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":null,"support":null}},"created_at":"2018-01-17T04:01:39.000Z","updated_at":"2019-03-28T16:35:01.000Z","dependencies_parsed_at":"2023-01-26T20:55:23.348Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/tagged-routes","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ftagged-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ftagged-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ftagged-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ftagged-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/tagged-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328389,"owners_count":22052633,"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":["routing","tagged-unions"],"created_at":"2024-11-06T21:14:21.540Z","updated_at":"2025-05-15T11:13:15.928Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tagged Routes\n\u003e Routing using tagged unions\n\n```sh\nnpm install tagged-routes\n```\n\n[![npm](https://img.shields.io/npm/v/tagged-routes.svg)](https://www.npmjs.com/package/tagged-routes)\n[![Build Status](https://travis-ci.org/andrejewski/tagged-routes.svg?branch=master)](https://travis-ci.org/andrejewski/tagged-routes)\n[![Greenkeeper badge](https://badges.greenkeeper.io/andrejewski/tagged-routes.svg)](https://greenkeeper.io/)\n\n## Example\n\n```js\nimport { createRoutes } from 'tagged-routes'\n\nconst { Route, getRouteForURL, getURLForRoute } = routeTable(\n    {\n        AppList: '/',\n        AppMain: '/apps/:appId',\n        AppSettings: '/apps/:appId/settings',\n        Settings: '/settings/(.*)'\n    },\n    'NotFound'\n)\n\nconsole.log(getRouteForUrl('/apps/example?tab=hosting'))\n/* =\u003e \u003cAppMain ({\n    routeParams: { appId: 'example' },\n    queryParams: { tab: 'hosting' }\n})\u003e */\n\nconsole.log(getRouteForUrl('/settings/can-be-anything'))\n/* =\u003e \u003cSettings ({\n    routeParams: {},\n    queryParams: {},\n    routeSplat: 'can-be-anything'\n})\u003e */\n\nconsole.log(getRouteForUrl('/bad/route-bad'))\n/* =\u003e \u003cNotFound ({\n    routeParams: {},\n    queryParams: {},\n    routePath: '/bad/route-bad'\n})\u003e */\n\nconst exemplarRoute = Route.AppMain({\n    routeParams: { appId: 'exemplar' },\n    queryParams: { tab: 'billing' }\n})\n\nconsole.log(getURLForRoute(exemplarRoute))\n// =\u003e /apps/exemplar?tab=billing\n```\n\n## Documentation\n\n### `createRoutes(routeTable, catchAllRouteKind: string, options?: object)`\nAccepts a `routeTable` object with route kinds (types of Route) as keys and valid [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) paths as values along with a catch-all route kind `catchAllRouteKind`. The `options` are passed to `path-to-regexp` and `options.encode` is passed to `path-to-regexp.compile` URL builders to override the `encodeURIComponent` default.\n\nReturns an object containing the below `Route` union and functions.\n\n### `Route`\nA [`tagmeme`](https://github.com/andrejewski/tagmeme) union, has a `.match` method and constructors for each route kind.\n\n### `getRouteForURL(url: string): Route`\nReturns the route that matches the `url`, or the catch-all route if none match. The shape of route data is:\n\n```ts\ninterface RouteData {\n    routeParams: {[key: string]: string}\n    queryParams: {[key: string]: string}\n    routeSplat?: string // only if route has a splat \"(.*)\" segment\n    routePath?: string  // only if catch-all route\n}\n```\n\n### `getURLForRoute(route: Route): string`\nReturns the URL that matches the `route`.\n\nThrows in development if:\n\n- a route requiring certain `routeParams` values is missing values.\n- the catch-all route does not have the `routePath` specified.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Ftagged-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Ftagged-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Ftagged-routes/lists"}