@raven99p/path-list-to-tree
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

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":[

      ]
   }

Readme

Keywords

Package Sidebar

Install

npm i @raven99p/path-list-to-tree

Weekly Downloads

3

Version

1.1.3

License

MIT

Unpacked Size

2.68 kB

Total Files

4

Last publish

Collaborators

  • raven99p