npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pyncz/zod-key-mapper

v1.0.1

Published

Transform keys of zod object schemas

Readme

@pyncz/zod-key-mapper

🗝️ Transform keys of zod object schemas


Installation

Just install it with your favourite package manager:

pnpm install @pyncz/zod-key-mapper

Usage

Let'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.

@pyncz/zod-key-mapper provides a convenient way to transform keys:

import { z } from 'zod'
import { mapped } from '@pyncz/zod-key-mapper'

const schema = mapped(z.object({
  snake_case_field: z.string(),
  foo: z.number(),
  bar: z.number(),
}), { snake_case_field: 'weRespectCamelsHere' })

console.log(schema.parse({ snake_case_field: 'hey', foo: 69, bar: 420 }))
// > { weRespectCamelsHere: 'hey', foo: 69, bar: 420 }

You can map multiple keys:

const schema = mapped(z.object({
  key1: z.string(),
  key2: z.number(),
  key3: z.number(),
}), { key1: 'key1mod', key2: 'key2mod' })

console.log(schema.parse({ key1: 'hey', key2: 69, key3: 420 }))
// > { key1mod: 'hey', key2mod: 69, key3: 420 }

Or you can map the schema key by key:

const schema = mapped(mapped(z.object({
  key1: z.string(),
  key2: z.number(),
  key3: z.number(),
}), { key1: 'key1mod' }), { key2: 'key2mod' })

console.log(schema.parse({ key1: 'hey', key2: 69, key3: 420 }))
// > { key1mod: 'hey', key2mod: 69, key3: 420 }

Arguments

  • schema - your Zod type
  • keysMap - a readonly object with keys you want to rename as keys, and corresponding new keys as values.

What's up with other keys operations?

"What if I want to add or remove keys, not just transform them?"

Well, you should use prick / omit methods zod provides out of the box, before mapping:

const schema = mapped(z.object({
  key1: z.string(),
  key2: z.number(),
  key3: z.number(),
}).pick({ key1: true }), { key1: 'key1mod' })

console.log(schema.parse({ key1: 'hey', key2: 69, key3: 420 }))
// > { key1mod: 'hey' }