1.0.0 • Published 7 years ago

deepmapkeys v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

Deep Map Keys

API

deepMapKeys(obj, mod);

ParamTypeDescription
obj or array{} or []An object or array whose keys are to be modified
modfunctionA function by which the keys of your object will be modified

Install

$ npm install

Tests

$ npm test

Example

// Example with an object
 const testObject = {
    a: true,
    b: [{
      c: 'val'
    }]
 };
 deepMapKeys(testObject, key => key.toUpperCase()); 
 /* {
    A: true,
    B: [{
      C: 'val'
    }]
 }
*/

// Example with an array
const testArray = [{
    a: 'hi'
  }, {
    b: 'bye',
    c: {
      d: 'yo'
    }
  }];

  result = deepMapKeys(testArray, key => key.toUpperCase());

/*
  [{
	A: 'hi'
   }, {
   B: 'bye',
   C: {
	 D: 'yo'
	}
   }]
*/

Author

  • Jonathan Schapiro

Special Thanks

  • Jeff Knight