0.1.7 • Published 6 years ago

@mzvonar/mergein v0.1.7

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago