1.0.5 • Published 5 years ago

json-merge-patch-in-place v1.0.5

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

json-merge-patch-in-place

Performs JSON merge-patch by changing existing objects. Meant for use with ORM's like Mongoose.

npm install json-merge-patch-in-place

Usage

Patch properties:

import { patch } from 'json-merge-patch-in-place';

let obj = {
    a: "foo",
    b: 100,
    c: true
};

patch(obj, { b: 200 });

/*
{
    a: "foo",
    b: 200,
    c: true
};
*/

Remove properties:

let obj: { a: string | null, b: number | null, c: boolean | null } = {
    a: "foo",
    b: 100,
    c: true
};

patch(obj, { b: null, c: null });

/*
{
    a: "foo",
    b: null,
    c: null
};
*/

Patch subdocuments:

let obj: { a: string, b: { c: string, d: string } | null } = {
    a: "foo",
    b: {
        c: "bar",
        d: "baz"
    },
};

patch(obj, { b: { c: "qux" } });

/*
{
    a: "foo",
    b: {
        c: "qux",
        d: "baz"
    }
};
*/
1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago