{"id":20652507,"url":"https://github.com/pyncz/zod-key-mapper","last_synced_at":"2025-04-18T21:38:17.073Z","repository":{"id":150760408,"uuid":"623357551","full_name":"pyncz/zod-key-mapper","owner":"pyncz","description":"🗝️ Transform keys of zod object schemas","archived":false,"fork":false,"pushed_at":"2023-11-27T10:24:16.000Z","size":78,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-08T01:40:37.558Z","etag":null,"topics":["keys","schema","typescript","utils","validation","zod"],"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/pyncz.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}},"created_at":"2023-04-04T08:00:16.000Z","updated_at":"2024-08-13T20:06:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"3a821bc0-d5b5-454e-99ed-4848e631570d","html_url":"https://github.com/pyncz/zod-key-mapper","commit_stats":{"total_commits":22,"total_committers":3,"mean_commits":7.333333333333333,"dds":"0.18181818181818177","last_synced_commit":"7aac41b5618885d9a3362bbe998220051258f200"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":"pyncz/template.ts-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyncz%2Fzod-key-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyncz%2Fzod-key-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyncz%2Fzod-key-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyncz%2Fzod-key-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyncz","download_url":"https://codeload.github.com/pyncz/zod-key-mapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224950581,"owners_count":17397385,"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":["keys","schema","typescript","utils","validation","zod"],"created_at":"2024-11-16T17:35:20.954Z","updated_at":"2024-11-16T17:35:21.444Z","avatar_url":"https://github.com/pyncz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @pyncz/zod-key-mapper\n\n🗝️ Transform keys of [zod](https://github.com/colinhacks/zod) object schemas\n\n---\n\n## Installation\n\nJust install it with your favourite package manager:\n```sh\npnpm install @pyncz/zod-key-mapper\n```\n\n## Usage\n\nLet's say, you use a 3rd party API to fetch some data. You want to parse and transform it with zod for further usage, including some operations with keys, e.g. mapping keys from *snake_case* to *camelCase*, or even change some confusing field names into something more convenient.\n\n`@pyncz/zod-key-mapper` provides a convenient way to transform keys:\n\n```ts\nimport { z } from 'zod'\nimport { mapped } from '@pyncz/zod-key-mapper'\n\nconst schema = mapped(z.object({\n  snake_case_field: z.string(),\n  foo: z.number(),\n  bar: z.number(),\n}), { snake_case_field: 'weRespectCamelsHere' })\n\nconsole.log(schema.parse({ snake_case_field: 'hey', foo: 69, bar: 420 }))\n// \u003e { weRespectCamelsHere: 'hey', foo: 69, bar: 420 }\n```\n\nYou can map multiple keys:\n```ts\nconst schema = mapped(z.object({\n  key1: z.string(),\n  key2: z.number(),\n  key3: z.number(),\n}), { key1: 'key1mod', key2: 'key2mod' })\n\nconsole.log(schema.parse({ key1: 'hey', key2: 69, key3: 420 }))\n// \u003e { key1mod: 'hey', key2mod: 69, key3: 420 }\n```\n\nOr you can map the schema key by key:\n```ts\nconst schema = mapped(mapped(z.object({\n  key1: z.string(),\n  key2: z.number(),\n  key3: z.number(),\n}), { key1: 'key1mod' }), { key2: 'key2mod' })\n\nconsole.log(schema.parse({ key1: 'hey', key2: 69, key3: 420 }))\n// \u003e { key1mod: 'hey', key2mod: 69, key3: 420 }\n```\n\n#### Arguments\n- `schema` - your Zod type\n- `keysMap` - a readonly object with **keys you want to rename** as keys, and **corresponding new keys** as values.\n\n## What's up with other keys operations?\n\n\u003e \"What if I want to add or remove keys, not just transform them?\"\n\nWell, you should use [pick / omit](https://zod.dev/?id=pickomit) methods zod provides out of the box, before mapping:\n\n```ts\nconst schema = mapped(z.object({\n  key1: z.string(),\n  key2: z.number(),\n  key3: z.number(),\n}).pick({ key1: true }), { key1: 'key1mod' })\n\nconsole.log(schema.parse({ key1: 'hey', key2: 69, key3: 420 }))\n// \u003e { key1mod: 'hey' }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyncz%2Fzod-key-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyncz%2Fzod-key-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyncz%2Fzod-key-mapper/lists"}