Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
```


# Usage

The 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 guidelines

See [CONTRIBUTING.md](CONTRIBUTING.md).