json-merge-patch-in-place
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.5 • Public • Published

    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"
        }
    };
    */

    Keywords

    none

    Install

    npm i json-merge-patch-in-place

    DownloadsWeekly Downloads

    7

    Version

    1.0.5

    License

    ISC

    Unpacked Size

    13.9 kB

    Total Files

    11

    Last publish

    Collaborators

    • ronpenton