Created
June 14, 2017 16:48
-
-
Save olizilla/db56a346c62926c28415561f6a27810a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source json is | |
// https://raw.githubusercontent.com/tableflip/libp2p-website/963d50ccb4d586857b85b0f2d35b448a065ca2b0/data/bundles.json | |
/* | |
GOAL: | |
```json | |
[ | |
{ | |
"name": "Browser JS", | |
"status": "live", | |
"image": "../img/logo_1.png", | |
"github": "https://github.com/ipfs/js-libp2p-ipfs-browser", | |
"categories": [ | |
{ | |
"name": "Transport" , | |
"modules": [ | |
{ | |
"id": "libp2p-websockets", | |
"status": "Done", | |
"url": "https://github.com/libp2p/js-libp2p-websockets" | |
}, | |
{ | |
"id": "libp2p-webrtc-star", | |
"status": "Done", | |
"url": "https://github.com/libp2p/js-libp2p-webrtc-star" | |
} | |
] | |
} | |
] | |
} | |
] | |
``` | |
what we have: | |
```json | |
{ | |
"Bundles": { | |
"Browser JS": { | |
"status": "live", | |
"image": "../img/logo_1.png", | |
"github": "https://github.com/ipfs/js-libp2p-ipfs-browser", | |
"categories": { | |
"Transport": { | |
"modules": { | |
"libp2p-websockets": { | |
"status": "Done", | |
"url": "https://github.com/libp2p/js-libp2p-websockets" | |
}, | |
"libp2p-webrtc-star": { | |
"status": "Done", | |
"url": "https://github.com/libp2p/js-libp2p-webrtc-star" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
``` | |
*/ | |
const data = require('./bundles.json').Bundles | |
const res = Object.keys(data).map(langName => { | |
const lang = data[langName] | |
const categories = Object.keys(lang.categories || []).map(categoryName => { | |
const category = lang.categories[categoryName] | |
const modules = Object.keys(category.modules).map(moduleId => { | |
const module = category.modules[moduleId] | |
return { | |
id: moduleId, | |
status: module.status, | |
url: module.url | |
} | |
}) | |
return { | |
name: categoryName, | |
modules | |
} | |
}) | |
return { | |
name: langName, | |
status: lang.status, | |
image: lang.image, | |
github: lang.github, | |
categories: categories | |
} | |
}) | |
console.log(JSON.stringify(res, null, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment