@mzvonar/mergein

0.1.7 • Public • Published

mergeIn Build Status Coverage Status npm version

Merges value in object by path with provided object. Path can be string or array (e.g. ['user', 'profile', 'gender']).
If any part of path doesn't exist it is created. Always returns new copy of object.

Installation

npm install @mzvonar/mergein

Usage

const mergeIn = require('@mzvonar/mergein');
  
const context = {
    user: {
        profile: {
            gender: 'female'
        }
    }
};
  
const newContext = mergeIn(context, ['user', 'profile'], {
    gender: 'male',
    address: {
        country: 'slovakia'
    }
});

returns:

    {
        user: {
            profile: {
                gender: 'male',
                address: {
                        country: 'slovakia'
                    }
            }
        }
    }
const newContext = mergeIn(context, 'user', {
    address: {
      country: 'slovakia'
    }
);

returns:

    {
        user: {
            profile: {
                gender: 'female',
            },
            address: {
                country: 'slovakia'
            }
        }
    }

Tests

npm test

Readme

Keywords

Package Sidebar

Install

npm i @mzvonar/mergein

Weekly Downloads

5

Version

0.1.7

License

MIT

Unpacked Size

5.92 kB

Total Files

4

Last publish

Collaborators

  • mzvonar