patriarchy
v1.0.8
Published
Render nested hierarchies based only on values
Downloads
7
Readme
I wrote this library to pretty print JSON describing identify records. The code is inspired from archy.
Usage
You can use this as an alternative method to JSON.stringify
when the fields name are obvious to the reader.
console.log(JSON.stringify(obj, null, 2))
{
"name": "Katy Perry",
"description": "American singer-songwriter",
"image": {
"contentUrl": "http://t3.gstatic.com/images?q=tbn:ANd9GcQrlKFmaiEtUImNiuD_pqzHPjDcjF4yaRThSFMh-rYuB8snFUfk",
"url": "https://en.wikipedia.org/wiki/Katy_Perry"
},
"detailedDescription": {
"articleBody": "Katheryn Elizabeth Hudson, known professionally as Katy Perry, is an American singer and songwriter. After singing in church during her childhood, she pursued a career in gospel music as a teenager. ",
"url": "https://en.wikipedia.org/wiki/Katy_Perry",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
},
"url": "http://www.katyperry.com/"
}
JavaScript
const patriarchy = require('patriarchy')
console.log(patriarchy(obj))
Katy Perry
│ American singer-songwriter
│ http://www.katyperry.com/
├─┐ http://t3.gstatic.com/images?q=tbn:ANd9GcQrlKFmaiEtUImNiuD_pqzHPjDcjF4yaRThSFMh-rYuB8snFUfk
│ │ https://en.wikipedia.org/wiki/Katy_Perry
└─┐ Katheryn Elizabeth Hudson, known professionally as Katy Perry, is an American singer and songwriter. After singing in church during her childhood, she pursued a career in gospel music as a teenager.
│ https://en.wikipedia.org/wiki/Katy_Perry
│ https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
Command-line interface
Install the tool globally npm install -g patriarchy
or use with npx patriarchy
if this is available in your Node.js version.
$ patriarchy '{"a1": "hello", "b1": {"a2": "world", "b2": "!"}}'
hello
└─┐ world
│ !
Contributions
Changes and improvements are welcome! Feel free to fork and open a pull request into master
.
Running the tests
You can lint the code and run all unit tests using that script.
npm test
License
patriarchy
is licensed under the Apache 2.0 License.