1.0.7 • Published 3 years ago

paths-to-tree-structure v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Paths to Tree Structure

Takes an array of paths & turns it into a tree data structure.

Installation:

Using npm:

npm i paths-to-tree-structure

Using jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/paths-to-tree-structure@1.0.5/index.min.js"></script>

Example

const pathsToTree = require("paths-to-tree-structure");

const paths = [
  "/var/www/html/index.html",
  "/home/directory/again/app.js",
  "/home/documents/readme.md",
];

let tree = pathsToTree(paths);

Output Format

{
  "items": [
    {
      "name": "var",
      "type": "dir",
      "id": "4f143ac6-351e-49af-8818-e2174999e73c",
      "children": [
        {
          "name": "www",
          "type": "dir",
          "id": "aeffebef-50b7-43b8-8437-1e92bed2c6cd",
          "children": [
            {
              "name": "html",
              "type": "dir",
              "id": "3c0621e0-15ab-421b-956d-6a37667c5817",
              "children": [
                {
                  "name": "index.html",
                  "type": "html",
                  "id": "874190a8-9074-4012-a139-622d0c89fff9"
                }
              ]
            }
          ]
        }
      ]
    },
    ...
  ]
}
1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago