upsert

0.0.3 • Public • Published

Upsert Build Status

Takes an array and modifies it by either updating the object matched by the predicate, or inserting a new object:

upsert(array, test, object)

var upsert = require('upsert')
 
upsert(
    arrayOfPeople,
    function(item) {
        item.name = 'jane';
    },
    {
        degree: 'doctorate'
    });

If the test doesn't match anything in the array, "object" will be pushed onto the array. If the test matches something in the array, then object will be extended onto what was matched.

If there are multiple matches, only the first one is modified.

The array that is passed in is modified, and it is also - for convenience - returned.

To run the tests do, npm install && npm test.

/upsert/

    Package Sidebar

    Install

    npm i upsert

    Weekly Downloads

    4

    Version

    0.0.3

    License

    MIT

    Last publish

    Collaborators

    • pajtai