1.1.3 • Published 3 years ago

@raven99p/path-list-to-tree v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

path-list-to-tree

Converts a list of file paths into a tree structure.

This is a forked npm package from here https://www.npmjs.com/package/path-list-to-tree. I modified it, so the output tree has "label" instead of "name".

Example

import pathListToTree from 'path-list-to-tree';

const filePaths = [
  '.gitignore',
  'README.md',
  'package.json',
  'src/index.ts',
  'tsconfig.json',
  'yarn-error.log',
  'yarn.lock'
];

console.log(pathListToTree(filePaths))
[
   {
      "label":".gitignore",
      "children":[

      ]
   },
   {
      "label":"README.md",
      "children":[

      ]
   },
   {
      "label":"package.json",
      "children":[

      ]
   },
   {
      "label":"src",
      "children":[
         {
            "label":"index.ts",
            "children":[

            ]
         }
      ]
   },
   {
      "label":"tsconfig.json",
      "children":[

      ]
   },
   {
      "label":"yarn-error.log",
      "children":[

      ]
   },
   {
      "label":"yarn.lock",
      "children":[

      ]
   }