Have ideas to improve npm?Join in the discussion! »

    magic-path

    0.0.5 • Public • Published

    Build Status

    what is this ?

    Get and Set Values from JS Objects magically.

    Installation

    npm i magic-path

    How to Use

    Get value😎

    ... 
    import { get } from 'magic-path'; // import
    ...
    .
    ...
    const yourDataObject = { 
        name: "sherlock holmes", 
        address: { 
        plotNo: "221B", 
        street: "baker street"
        } 
    }
    get(yourDataObject,"name"); // sherlock holmes
    get(yourDataObject,"address"); // ---address Object
    get(yourDataObject,"address.plotNo"); // 221B
    
    const yourArray = [{name: "SHERLOCK"},{name: "WATSON"}, {name: "moriarty"}];
    get(yourArray,["name"]); // ["SHERLOCK", "WATSON","moriarty"]
    ...
    

    Set value😎

    ... 
    import { set } from 'magic-path'; // import
    ...
    .
    ...
    const yourDataObject = { 
        name: "sherlock holmes", 
        address: { 
        plotNo: "221B", 
        street: "baker street"
        } 
    }
    const newData = set("family.brother.name",'mycroft',yourDataObject);
    { 
        name: "sherlock holmes",
        family: {
            brother: {
                name: mycroft;
            }
        }
        address: { 
            plotNo: "221B", 
            street: "baker street"
        } 
    }
    ...
    

    Install

    npm i magic-path

    DownloadsWeekly Downloads

    6

    Version

    0.0.5

    License

    ISC

    Unpacked Size

    35.9 kB

    Total Files

    14

    Last publish

    Collaborators

    • avatar