property-map

    0.0.2 • Public • Published

    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(
      {a: 4, b: 6, c: 3},
      value => value + 1
    ); // {a: 5, b: 7, c: 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
    

    Install

    npm i property-map

    DownloadsWeekly Downloads

    3

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • angus-c