New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

key-mapper

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-mapper

Deeply map object keys

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

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

Keywords

object

FAQs

Package last updated on 21 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts