@mzvonar/deletein

0.0.7 • Public • Published

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);
Name Description
context Object from which the value deleted
path Must 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

/@mzvonar/deletein/

    Package Sidebar

    Install

    npm i @mzvonar/deletein

    Weekly Downloads

    6

    Version

    0.0.7

    License

    MIT

    Unpacked Size

    6.48 kB

    Total Files

    4

    Last publish

    Collaborators

    • mzvonar