0.1.0 • Published 3 years ago

magic-path v0.1.0

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

Build Status Contributors Forks Stargazers Issues MIT License

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"
    } 
}
...