Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nknapp/tree-from-paths
Convert a list of paths into a archy directory-tree
https://github.com/nknapp/tree-from-paths
Last synced: 6 days ago
JSON representation
Convert a list of paths into a archy directory-tree
- Host: GitHub
- URL: https://github.com/nknapp/tree-from-paths
- Owner: nknapp
- License: mit
- Created: 2017-05-20T21:09:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-14T20:51:43.000Z (almost 7 years ago)
- Last Synced: 2024-10-06T03:41:20.953Z (about 1 month ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# tree-from-paths
[![NPM version](https://img.shields.io/npm/v/tree-from-paths.svg)](https://npmjs.com/package/tree-from-paths)
[![Travis Build Status](https://travis-ci.org/nknapp/tree-from-paths.svg?branch=master)](https://travis-ci.org/nknapp/tree-from-paths)
[![Coverage Status](https://img.shields.io/coveralls/nknapp/tree-from-paths.svg)](https://coveralls.io/r/nknapp/tree-from-paths)> Convert a list of paths into a archy directory-tree
# Installation
```
npm install tree-from-paths
```
# UsageThe following example demonstrates how to use this module:
```js
var {render} = require('tree-from-paths')console.log(render(
[
'basedir/dir1/file1.txt',
'basedir/dir1/file2.txt',
'basedir/dir2/file3.txt',
'basedir/dir3/',
'basedir/dir3/file4.txt',
'basedir/dir3/file5.txt',
'basedir/dir4/dir5/file7.txt'
],
'basedir',
(parent, file, explicit) => {
return `${file}${explicit ? '(*)' : ''}`
}
))const files = [
{
path: 'basedir/dir1/file1.txt',
created: true
},
{
path: 'basedir/dir1/file2.txt'
},
{
path: 'basedir/dir2/file3.txt'
},
{
path: 'basedir/dir3/'
},
{
path: 'basedir/dir3/file4.txt',
created: true
},
{
path: 'basedir/dir3/file5.txt'
},
{
path: 'basedir/dir4/dir5/file7.txt'
}
]console.log(
render(files.map(x => x.path), 'basedir', (parent, file, explicit, index) => {
const createdStr = (index >= 0 && files[index].created) ? ' created' : ''
return `${file}${createdStr}`
})
)
```This will generate the following output
```
/
├─┬ dir1/
│ ├── file1.txt(*)
│ └── file2.txt(*)
├─┬ dir2/
│ └── file3.txt(*)
├─┬ dir3/(*)
│ ├── file4.txt(*)
│ └── file5.txt(*)
└─┬ dir4/dir5/
└── file7.txt(*)/
├─┬ dir1/
│ ├── file1.txt created
│ └── file2.txt
├─┬ dir2/
│ └── file3.txt
├─┬ dir3/
│ ├── file4.txt created
│ └── file5.txt
└─┬ dir4/dir5/
└── file7.txt
```# License
`tree-from-paths` is published under the MIT-license.
See [LICENSE.md](LICENSE.md) for details.
# Release-Notes
For release notes, see [CHANGELOG.md](CHANGELOG.md)
# Contributing guidelinesSee [CONTRIBUTING.md](CONTRIBUTING.md).