charol

0.3.0 • Public • Published

charol

JSON topic object to String representation. Useful for "autocompletion" of the topic paths.

It assigns to the last object level (leaf) the String representation of the topic path from root to this attribute. Also it adds a _path property to the intermediate object levels of the your object "tree"

How to use

npm i --save charol

Define your topic structure as a JSON object and then call the charol function passing the object as parameter. For example:

let topicScheme = {
    "home": {
        "kitchen": {
            "light": {
                "power": {
                    "set": null,
                },
                "temperature": null
            },
            "oven": {
                "gas": null,
                "fire": {
                    "set": null
                }
            }
        }
    }
}
 
const topicPaths = charol(topicScheme)
```Javascript
 
`console.log(topicPaths.home.kitchen.light.temperature)`
 
_> outputs "home/kitchen/light/temperature"_
 
`console.log(topicPaths.home.kitchen.oven.fire.set)`
 
_> outputs "home/kitchen/oven/fire/set"_
 
`console.log(topicPaths.home.kitchen._path)`
 
_> outputs "home/kitchen"_
 
`console.log(topicPaths.home.kitchen.light.power._path)`
 
_> outputs "home/kitchen/light/power"_
 

Example that works fine with VSCode and ReactJS

topics.js:

 
let topics = {
    chatList: {
        select: null,
        message: {
            new: null
        }
    }
}
 
topics = charol(topics)
 
export default topics
 

Package Sidebar

Install

npm i charol

Weekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

6.31 kB

Total Files

6

Last publish

Collaborators

  • tiagostutz