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

curry-remap-keys

v2.2.1

Published

Utility for remapping key names of an object shallowly and depply nested too, that supports currying for partial application.

Downloads

89

Readme

curry-remap-keys JavaScript Style Guide NPM version NPM monthly downloads NPM total downloads

Utility for remapping key names of an object shallowly and depply nested too, that supports currying for partial application.

It embraces functional programming not mutating its entry, but returning a new object that maintains the original prototype chain and properties enumerables or not, respecting referential transparency.

Install

$ npm install curry-remap-keys --save

Usage (Basic)

const { remapKeys } = require('curry-remap-keys')
// As ES6 Module
import { remapKeys } from 'curry-remap-keys'

const user = {
  user_id: '9e947a10-af08-11e8-9b04-d3ce91a97e8d',
  order_id: 'aa4025d0-af08-11e8-9215-1106c9538c60',
  productName: 'The best notebook of the whole world',
  qty: '1'
}

const remapping = {
  user_id: 'userId',
  order_id: 'orderId'
}

const remappedUser = remapKeys(remapping, user)

console.log(remappedUser)
// {
//   userId: '9e947a10-af08-11e8-9b04-d3ce91a97e8d',
//   orderId: 'aa4025d0-af08-11e8-9215-1106c9538c60',
//   productName: 'The best notebook of the whole world',
//   qty: '1'
// }

Usage (Nested keys)

This will follow or create the necessary key names that fulfills the supplied path.

const { remapKeys } = require('curry-remap-keys')
// As ES6 Module
import { remapKeys } from 'curry-remap-keys'

const user = {
  user_id: '9e947a10-af08-11e8-9b04-d3ce91a97e8d',
  order_id: 'aa4025d0-af08-11e8-9215-1106c9538c60',
  productName: 'The best notebook of the whole world',
  qty: '1',
  billingInfo: {
    locationInfo: {
      billing_address: '1368 Meadowbrook Mall Road',
      city: 'Los Angeles, CA',
      zip: '90017'
    }
  },
  customerInfo: {
    interested_in: ['notebooks', 'smartphones', 'smart tv'],
    isOneTimeBuyer: false
  }
}

const remapping = {
  user_id: 'userId',
  billing_address: ['billingAddress', ['billingInfo', 'locationInfo']],
  // Natural point notation for path to nested key also supported like...
  // billing_address: ['billingAddress', 'billingInfo.locationInfo'],
  interested_in: ['interestedIn', ['customerInfo']]
}

const remappedUser = remapKeys(remapping, user)

console.log(remappedUser)
// {
//   userId: '9e947a10-af08-11e8-9b04-d3ce91a97e8d',
//   order_id: 'aa4025d0-af08-11e8-9215-1106c9538c60',
//   productName: 'The best notebook of the whole world',
//   qty: '1',
//   billingInfo: {
//     locationInfo: {
//       billingAddress: '1368 Meadowbrook Mall Road',
//       city: 'Los Angeles, CA',
//       zip: '90017'
//     }
//   },
//   customerInfo: {
//     interestedIn: ['notebooks', 'smartphones', 'smart tv'],
//     isOneTimeBuyer: false
//   }
// }

Currying

const { remapKeys } = require('curry-remap-keys')
// As ES6 Module
import { remapKeys } from 'curry-remap-keys'

// Same user and remapping object as above

// Partially apply remapKeys for reusing
const userRemapper = remapKeys(remapping)

console.log(userRemapper(user))
// {
//   userId: '9e947a10-af08-11e8-9b04-d3ce91a97e8d',
//   orderId: 'aa4025d0-af08-11e8-9215-1106c9538c60',
//   productName: 'The best notebook of the whole world',
//   qty: '1'
// }

See also

License

Copyright © 2018, José Antonio Reyes. Released under the MIT License.