Skip to content

dryajov/normalize-keys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Normalize an object's keys

This is a simple module to normalize an objects keys. It will create a new object, it will never mutate the original object.

API

normalizeKeys - takes an object and producse a new object with the keys/properties normalized to the desired format; by default camel case.

  • {Object} obj - the object to normalize
  • {Function} normalizer - a formatter function, by default lodash.camelcase
  • {Array} skipKeys - an array of keys to skip from the resulting object

Example:

const normalizeKeys = require('normalize-keys')

const normalizer = (key) => {
  // camel case formatter....
}

const Obj1 = {
  'my-key-1': 'I am key #1',
  'my-key-2': 'I am key #2',
  'my-key-3': 'I am key #3',
  'my-key-4': 'I am key #4'
}

const Obj2 = normalizeKeys(Obj1, formatter, ['my-key-3'])

console.dir(Obj2)

// Prints:
// {
//   'myKey1': 'I am key #1',
//   'myKey2': 'I am key #2',
//   'myKey4': 'I am key #4'
// }

About

Normalize an object's keys

Resources

Stars

Watchers

Forks

Packages

No packages published