Skip to content

pajtai/upsert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upsert Build Status

Usage

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(person) {
        return 'goodall' === person.name;
    },
    {
        name: 'dr goodall',
        degree: 'doctorate'
    });

If test doesn't return true for anything in array, object will be pushed onto array. If test matches something in 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.

Installing

To use in a project:

npm install --save upsert

Tests

To run the tests, git clone, npm install, npm test.

About

Insert an object into or update an object in an array.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published