{"id":29079438,"url":"https://github.com/axtk/url-shape","last_synced_at":"2026-04-04T05:31:54.616Z","repository":{"id":299259660,"uuid":"1000906649","full_name":"axtk/url-shape","owner":"axtk","description":"URL builder with optional schema-based type safety","archived":false,"fork":false,"pushed_at":"2026-04-03T22:42:21.000Z","size":153,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-04T00:27:31.388Z","etag":null,"topics":["routes","type-safety","url","url-builder","url-schema","yup","zod"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/url-shape","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/axtk.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-12T13:58:30.000Z","updated_at":"2026-04-03T22:42:24.000Z","dependencies_parsed_at":"2025-10-10T21:08:30.850Z","dependency_job_id":"20687525-3db3-48df-95b1-f6d5fa3cbcb6","html_url":"https://github.com/axtk/url-shape","commit_stats":null,"previous_names":["axtk/url-shape","t8js/url-shape","axcraft/url-shape"],"tags_count":54,"template":false,"template_full_name":null,"purl":"pkg:github/axtk/url-shape","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Furl-shape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Furl-shape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Furl-shape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Furl-shape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axtk","download_url":"https://codeload.github.com/axtk/url-shape/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Furl-shape/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31389382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["routes","type-safety","url","url-builder","url-schema","yup","zod"],"created_at":"2025-06-27T17:02:45.920Z","updated_at":"2026-04-04T05:31:54.610Z","avatar_url":"https://github.com/axtk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# url-shape\n\nURL builder with optional schema-based type safety\n\nContents: [Building URLs](#building-urls) · [Type safety](#type-safety) · [Validating against a URL schema](#validating-against-a-url-schema)\n\n## Building URLs\n\nUse the URL builder `url()` to produce URLs based on their components, such as path placeholders and query parameters.\n\n```js\nimport { url } from \"url-shape\";\n\nurl(\"/sections/:id\", { params: { id: 10 } }).href // \"/sections/10\"\nurl(\"/sections/:id\", { params: { id: 10 } }).toString() // \"/sections/10\"\nString(url(\"/sections/:id\", { params: { id: 10 } })) // \"/sections/10\"\n\nurl(\"/sections/:id\").exec(\"/sections/42\") // { params: { id: 42 } }\nurl(\"/sections/:id\").exec(\"/x/42\") // null\n\nurl(\"/sections/:id\").compile({ params: { id: 10 } }) // \"/sections/10\"\nurl(\"/search\").compile({ query: { term: \"shape\" } }) // \"/search?term=shape\"\n```\n\n⬥ Use `createURLBuilder()` to create a standalone or customized URL builder. Pass an optional `base` URL as the parameter of `createURLBuilder()` to produce URLs relative to the given URL. `base` acts as a prefix, or a replacement to the leading `/` in the paths, applied to the output URLs. It's a handy way to rebase all URLs produced by the URL builder to another root URL.\n\n```js\nimport { createURLBuilder } from \"url-shape\";\n\nconst url = createURLBuilder(\"/nested\");\n\nurl(\"/sections/:id\", { params: { id: 10 } }).href // \"/nested/sections/10\"\n```\n\n## Type safety\n\nPass a URL schema to `createURLBuilder()` to make sure that the URL parameters match the URL and that they contain data of the expected type. A URL schema can be defined with any validation lib supporting the [Standard Schema](https://github.com/standard-schema/standard-schema#readme) spec, including Zod, ArkType, Valibot, or Yup.\n\n```ts\nimport { createURLBuilder } from \"url-shape\";\nimport { z } from \"zod\";\n\nexport const url = createURLBuilder({\n  \"/\": z.object({}), // No parameters, empty schema\n  \"/sections/:id\": z.object({\n    // Path placeholders\n    params: z.object({\n      id: z.coerce.number(),\n    }),\n  }),\n  \"/search\": z.object({\n    // Query (or search) parameters\n    query: z.object({\n      term: z.string(),\n      view: z.optional(z.enum([\"full\", \"compact\"])),\n    }),\n  }),\n});\n```\n\n```ts\nurl(\"/sections/:id\", { params: { id: 10 } }).href // \"/sections/10\"\n                    // ^ { id: number }\n\nurl(\"/search\", { query: { term: \"shape\" } }).href // \"/search?term=shape\"\n              // ^ { term: string, view?: \"full\" | \"compact\" }\n```\n\n⬥ With Zod, mind the `.coerce` part in the schema for non-string parameters so that string URL components are converted to the preferred types.\n\n⬥ An entire web app doesn't have to be covered by a single URL schema. Each self-contained section of the app can have its own URL builder on top of its own URL schema.\n\n⬥ The `base` parameter can be used with a URL schema, too. Use `createURLBuilder(base, schema)` to produce URLs relative to the given `base` URL.\n\n## Validating against a URL schema\n\nAs an alternative to passing a URL schema directly to `createURLBuilder()` as described above, a URL schema can be created as a standalone object:\n\n```ts\nimport { URLSchema } from \"url-shape\";\nimport { z } from \"zod\"; \n\nexport const schema = new URLSchema({\n  \"/sections/:id\": z.object({\n    params: z.object({\n      id: z.coerce.number(),\n    }),\n  }),\n});\n```\n\nUse a `URLSchema` object to check whether a URL matches any entries in the schema:\n\n```ts\nschema.test(\"/sections/10\") // true, found in the schema\nschema.test(\"/x\") // false, not found in the schema\n```\n\n⬥ Testing against a comprehensive URL schema can be used to help handle unknown URLs.\n\n⬥ A `URLSchema` object can also be passed to `createURLBuilder()`.\n\n⬥ A URL schema created as `new URLSchema(null)` is technically valid, too. It doesn't set any constraints, testing any URL against it with `schema.test(url)` results in `true`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Furl-shape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxtk%2Furl-shape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Furl-shape/lists"}