0.0.7 • Published 6 years ago

@mzvonar/deletein v0.0.7

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

deleteIn Build Status Coverage Status npm version

Deletes value from object by path. Path can be string or array (e.g. 'user', 'profile', 'gender').
Always returns new copy of object.

Installation

npm install @mzvonar/deletein

Parameters

deleteIn(context, path);
NameDescription
contextObject from which the value deleted
pathMust be Array or String. See usage

Usage

import deleteIn from '@mzvonar/deletein';
  
const context = {
    user: {
        profile: {
            gender: 'female'
        },
        ids: [1, 2, 3]
    }
};
  
const newContext = deleteIn(context, ['user', 'profile', 'gender']);

returns:

    {
        user: {
            profile: {}
        }
    }
const newContext = deleteIn(context, ['user', 'ids', 1]);

returns:

    {
        user: {
            profile: {
                gender: 'female',
                ids: [1, 3]
            }
        }
    }

mutableDeleteIn

If you need you can import mutableDeleteIn, which is exactly the same as deleteIn, but mutates the original context object without creating copy.

Tests

npm test

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago