path-mapper-json
v1.4.0
Published
A small library to turn an array of paths like the one below:
Maintainers
Readme
path-mapper-json
A small library to turn an array of paths like the one below:
const paths = ["Coding", "Coding/JS", "Coding/JS/Enum.ts", "Coding/JS/ForLoop.md", "Coding/TS", "Security", "Security/Easy/Example1.ts", "Security/Medium"];...into a JSON structure made like this:
[
{
"name": "Coding",
"type": "tree",
"children": [
{
"name": "JS",
"type": "tree",
"children": [
{
"name": "Enum.ts",
"type": "blob",
"children": []
},
{
"name": "ForLoop.md",
"type": "blob",
"children": []
}
]
},
{
"name": "TS",
"type": "tree",
"children": []
}
]
},
{
"name": "Security",
"type": "tree",
"children": [
{
"name": "Easy",
"type": "tree",
"children": [
{
"name": "Example1.ts",
"type": "blob",
"children": []
}
]
},
{
"name": "Medium",
"type": "tree",
"children": []
}
]
}
]Installation
npm install path-mapper-jsonUsage
import { buildTree } from 'path-mapper-json';
const paths = ["Coding", "Coding/JS", "Coding/JS/Enum.ts", "Coding/JS/ForLoop.md", "Coding/TS"];
const tree = buildTree(paths);
console.log(tree);MIT © LucaOttvn
