Skip to content

Fills an existing object with new properties, but only for the keys that already exist.

License

Notifications You must be signed in to change notification settings

christianrank/object-fill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-fill

Fills an existing object with new properties, but only for the keys that already exist.

This also works recursive.

Installation

NPM
npm install --save object-fill

Yarn
yarn add object-fill

Usage

const newDestination = objectFill(destination, source)
  • destination - the existing object
  • source - the data that is inserted into the destination

returns: the new object

Example

const objectFill = require('object-fill');

const destination = {
    foo: 'something',
    bar: 'another thing',
};

const source = {
    bar: 'a new string',
    baz: 'an irrelevant string',
}

const newDestination = objectFill(destination, source);

/* newDestination:
 * {
 *     foo: 'something',
 *     bar: 'a new string'
 * }
 */

License

MIT

About

Fills an existing object with new properties, but only for the keys that already exist.

Resources

License

Stars

Watchers

Forks

Packages

No packages published