magic-path

0.1.0 • Public • Published

Build Status Contributors Forks Stargazers Issues MIT License

magic-path

🪄 Get and Set Values from JS Objects magically 🐇

Report Bug · Request Feature

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

Package Sidebar

Install

npm i magic-path

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

37.7 kB

Total Files

14

Last publish

Collaborators

  • shubhro