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 🙏

© 2024 – Pkg Stats / Ryan Hefner

key-mapper

v1.0.1

Published

Deeply map object keys

Downloads

307

Readme

Travis npm prettier Beerpay

key-mapper

Tiny utility for deeply mapping object keys

Map object keys (properties) to transform an object of any shape and depth*.

* Obviously, there's such a thing as a call stack. If you're working with very large objects, you should consider mapping small subsets of the object instead.

Install

yarn add key-mapper --save
npm install key-mapper --save

Usage

Any object supplied will be deeply mapped, including arrays of objects. Any non-object, non-array contents will be skipped over. This includes any combination (to any depth) of array of objects and objects with arrays, and so on.

km(sourceObject, _.camelCase) // => convert keys to camel case

If you want to exclude certain properties from the mapping, add an optional prefilter function. For example, omit all properties named "options". Note that this means the resulting object will not have any properties named "options", not that it skips them.

km(sourceObject, _.camelCase, omitOptions)

This is useful for working with large objects that could cause key-mapper to hit the call stack limit. You could create multiple objects, one with the keys mapped, another with just the keys you wanted to exclude, then merge them back together.

const mapped = km(sourceObject, _.camelCase, omitOptions)

// here, pickOptions does the opposite of omitOptions
const filtered = km(sourceObject, _.identity, pickOptions)

const finalForm = _.merge(filtered, mapped)

Notice how I used _.identity to leave the keys as-is so I could still deeply pick "options". #protip