0.0.3 • Published 9 years ago

upsert v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

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.

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago