Skip to content

angus-c/property-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

property-map

Apply a function to each property of an object

Install

npm install property-map

API

propertyMap(baseObj, callback [, thisObject]);

callback is a function that can accept up to three arguments:

value
The value for each property in baseObj
key (optional)
The key for each property in baseObj
baseObj (optional)
The baseObj

Usage

// commonJS...
var propertyMap = require('property-map');
// ...or es2015
import propertyMap from 'property-map';

propertyMap({height: 4, width: 3}, x => x + 1); // {height: 5, width: 4}

propertyMap(
  {a: 4, b: 6, c: 3},
  function(_, key) {return this[key]},
  {a: 1, c: 3}
); // {a: 1, b: undefined, c: 3}

Tests

npm test

About

Apply a function to each property of an object

Resources

License

Stars

Watchers

Forks

Packages

No packages published