{"id":20771304,"url":"https://github.com/ootidea/type-safe-url","last_synced_at":"2025-10-28T08:45:11.775Z","repository":{"id":196341090,"uuid":"695488821","full_name":"ootidea/type-safe-url","owner":"ootidea","description":"A lightweight TypeScript library for writing URLs in a type-safe manner.","archived":false,"fork":false,"pushed_at":"2023-10-05T05:12:30.000Z","size":128,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-06T14:34:17.151Z","etag":null,"topics":["library","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/type-safe-url","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ootidea.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-23T10:45:31.000Z","updated_at":"2024-05-06T19:57:54.000Z","dependencies_parsed_at":"2023-09-27T09:47:34.480Z","dependency_job_id":"5bea46e6-b9e0-4db6-b529-bfbf4a7ead6d","html_url":"https://github.com/ootidea/type-safe-url","commit_stats":null,"previous_names":["ootidea/type-safe-url"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Ftype-safe-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Ftype-safe-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Ftype-safe-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Ftype-safe-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ootidea","download_url":"https://codeload.github.com/ootidea/type-safe-url/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243104069,"owners_count":20236944,"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":["library","npm-package","typescript"],"created_at":"2024-11-17T12:14:27.233Z","updated_at":"2025-10-28T08:45:06.756Z","avatar_url":"https://github.com/ootidea.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003etype-safe-url\u003c/h1\u003e\n\nA lightweight TypeScript library for writing URLs in a type-safe manner.  \n\n### Features\n- Supports path parameters and query parameters\n- Automatic URL encoding\n- Works on both browsers and Node.js\n- Tiny bundle size and 0 dependencies\n\nWith an IDE, you can list URL references and rename URL components 👍.  \n\n### Basic example\n\nHere is an example of how to define a URL structure and write corresponding URLs.  \n\n```ts\nimport { createRootPathObject, urlOf } from 'type-safe-url'\n\n// Define your URL structure\nconst root = createRootPathObject\u003c{\n  company: {    // '/company'\n    access: {}  // '/company/access'\n    history: {} // '/company/history'\n  }\n}\u003e()\n\n// Create URL strings\nconsole.log(\n  urlOf(root),                // '/'\n  urlOf(root.company.access), // '/company/access'\n)\n```\n\n### Path parameters\n\nPath parameters are represented using **function types** as follows:  \n\n```ts\nconst root = createRootPathObject\u003c{\n  user: (name: string) =\u003e {   // 👈️ Path parameter\n    profile: {}\n    posts: (id: number) =\u003e {} // 👈️ Nested path parameter\n  }\n}\u003e()\n\nconsole.log(\n  urlOf(root.user),                  // '/user'\n  urlOf(root.user('alice')),         // '/user/alice'\n  urlOf(root.user('alice').posts),   // '/user/alice/posts'\n  urlOf(root.user('alice').posts(1)) // '/user/alice/posts/1'\n)\n```\n\n### Query parameters\n\nQuery parameters are represented as follows:  \n\n```ts\nconst root = createRootPathObject\u003c{\n  items: {\n    '?': { page: number; limit: number }\n  }\n}\u003e()\n\nconsole.log(\n  urlOf(root.items),                         // '/items'\n  urlOf(root.items, { page: 2 }),            // '/items?page=2'\n  urlOf(root.items, { page: 2, limit: 30 }), // '/items?page=2\u0026limit=30'\n)\n```\n\n### Options for creating URL strings\n\nYou can configure the base URL and slashes at both ends.\n\n```ts\nconst root = createRootPathObject\u003c{\n  about: {}\n}\u003e({\n  baseUrl: 'https://example.com/',\n  autoAddLeadingSlash: false,\n  autoAddTrailingSlash: true,\n})\n\nconsole.log(urlOf(root.about)) // 'https://example.com/about/'\n```\n\n### Multi-Value Query Parameters\n\nYou can define query parameters that accept multiple values.  \nSimply use **array types** as below.  \n\n```ts\nconst root = createRootPathObject\u003c{\n  articles: {\n    '?': { tags: string[] } // 👈️ Multi-value as an array\n  }\n}\u003e()\n\nconsole.log(\n  urlOf(root.articles, { tags: ['css', 'html'] }), // '/articles?tags=css\u0026tags=html'\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Footidea%2Ftype-safe-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Footidea%2Ftype-safe-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Footidea%2Ftype-safe-url/lists"}