Skip to content

Instantly share code, notes, and snippets.

@olizilla
Created June 14, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olizilla/db56a346c62926c28415561f6a27810a to your computer and use it in GitHub Desktop.
Save olizilla/db56a346c62926c28415561f6a27810a to your computer and use it in GitHub Desktop.
// 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