{"id":16184637,"url":"https://github.com/rmariuzzo/ruty","last_synced_at":"2025-03-19T02:31:25.265Z","repository":{"id":40791066,"uuid":"252357061","full_name":"rmariuzzo/ruty","owner":"rmariuzzo","description":"📦 Ruty is a simple URL route builder, that support typing route params and queries string with TypeScript.","archived":false,"fork":false,"pushed_at":"2023-01-06T02:45:39.000Z","size":2915,"stargazers_count":17,"open_issues_count":10,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T07:10:42.184Z","etag":null,"topics":["builder","route","routebuilder","typescript"],"latest_commit_sha":null,"homepage":"","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/rmariuzzo.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":"2020-04-02T04:42:05.000Z","updated_at":"2023-12-21T04:13:05.000Z","dependencies_parsed_at":"2023-02-05T03:46:28.302Z","dependency_job_id":null,"html_url":"https://github.com/rmariuzzo/ruty","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Fruty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Fruty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Fruty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Fruty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmariuzzo","download_url":"https://codeload.github.com/rmariuzzo/ruty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221720423,"owners_count":16869483,"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":["builder","route","routebuilder","typescript"],"created_at":"2024-10-10T07:10:53.832Z","updated_at":"2024-10-27T19:09:06.568Z","avatar_url":"https://github.com/rmariuzzo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [![Ruty](.github/banner.svg)](#motivation)\n\nRuty is a simple URL route builder, that [supports typing route params and queries string with TypeScript](#typescript).\n\n#### Motivation\n\n_Whether I am working in the frontend or backend, I always define a set of URLs for API endpoints or page URLs. Therefore, instead of having all these URLs routes spread out within multiple files, I prefer to have them defined in one file then reference them where I need them. Also, while using TypeScript I prefer to have my URLs routes params and queries string typed. **That's the reason I created**_ **`ruty`** _**, a tiny library that allows me to define routes with their params and queries strings.**_\n\n## Features\n\n- TypeScript support.\n- Typed route params `/:param` and typed query strings `?query\u0026string`.\n- No dependencies.\n- 100% test coverage.\n\n## Installation\n\n```sh\nnpm i ruty\n```\n\n## Usage\n\n```ts\nimport { Ruty } from 'ruty'\n\nconst { route } = Ruty.configure()\n\nconst routes = {\n  home: route('/').build(),\n  users: route('/users').build(),\n  userById: route('/user/:id?created\u0026sort').build(),\n}\n\nroutes.home()\n// '/'\nroutes.users()\n// '/users'\nroutes.userById({ id: 123 })\n// '/user/123'\nroutes.userById({ id: 123, created: true, sort: 'desc' })\n// '/user/123?created\u0026sort=desc'\n```\n\n## TypeScript\n\nYou can type your route params and queries string with TypeScript by adding generics to the `build` method as shown below:\n\n```ts\nimport { route } from 'ruty'\n\nRuty.configure()\n\nconst routes = {\n  userById: route('/user/:id?created\u0026sort').build\u003c{\n    id: number\n    created: boolean\n    sort: 'asc' | 'desc'\n  }\u003e(),\n}\n\nroutes.userById({ id: 123, created: true, sort: 'desc' })\n// '/user/123?created\u0026sort=desc'\n```\n\nThen you will have autocomplete suggestions and type assertion:\n\n![TypeScript example](.github/typescript.gif)\n\n## Configuration\n\nAny configuration is passed to `Ruty.configure(...)`.\n\n```ts\nconst ruty = Ruty.configure({\n  // 👇 Add a prefix to all genrated routes.\n  prefix: '/:language',\n  // 👇 A function that transform the value for route params.\n  paramTransformer: (param, value) =\u003e value,\n  // 👇 A function that transform the value for query strings.\n  queryTransformer: (query, value) =\u003e value,\n  // 👇 Global route params.\n  params: {\n    language: () =\u003e detectLanguage(),\n  },\n  // 👇 Global query string.\n  query: {\n    theme: 'dark',\n  },\n})\n```\n\n## Development\n\nIf you want to contribute to this project please follow these instructions:\n\n1.  Clone this repo.\n2.  Install dependencies with `npm i`.\n3.  Add your changes, make sure to include tests.\n\nTests can be run with `npm t`. If you want to run tests in watch mode use: `npm t -- --watch`. Also, if you want to run tests coverage use: `npm t -- --coverage`.\n\n## Release\n\nReleases are done with: `npm run release`.\n\n---\n\n\u003ccenter\u003e\n\u003csmall\u003e\n\nMade with love by [@rmariuzzo](https://github.com/rmariuzzo) and [contributors](https://github.com/rmariuzzo/ruty/graphs/contributors).\n\n\u003c/small\u003e\n\u003c/center\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Fruty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmariuzzo%2Fruty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Fruty/lists"}