https://github.com/mattipv4/tree-parse
A super simple package to parse the string output of the unix tree command into an object.
https://github.com/mattipv4/tree-parse
Last synced: 9 months ago
JSON representation
A super simple package to parse the string output of the unix tree command into an object.
- Host: GitHub
- URL: https://github.com/mattipv4/tree-parse
- Owner: MattIPv4
- License: apache-2.0
- Created: 2020-03-17T21:13:21.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T02:20:04.000Z (over 2 years ago)
- Last Synced: 2025-03-28T17:05:59.551Z (10 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/tree-parse
- Size: 83 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tree-parse
A super simple package to parse the string output of the unix tree command into an object.
---
Use the `parse` function to convert the output of the unix `tree` command into an object.
The object will contain keys for each file or directory found.
Each file will have a value that is an empty object,
with each directory's value being an object containing all its children.
Use the `files` function to convert the output of the `tree` function into a single array of files, as strings.
---
```javascript
const { parse } = require('tree-parse');
const demo = `
.
├── README.md
├── example.png
├── package-lock.json
├── package.json
├── src
│ ├── app.js
│ ├── util.js
│ └── test
│ └── test.js
└── index.js
2 directories, 8 files
`;
const tree = parse(demo);
console.log(tree);
```
```json
{
".": {
"README.md": {},
"example.png": {},
"package-lock.json": {},
"package.json": {},
"src": {
"app.js": {},
"util.js": {},
"test": {
"test.js": {}
}
},
"index.js": {}
}
}
```
```javascript
const { parse, files } = require('tree-parse');
const demo = `
.
├── README.md
├── example.png
├── package-lock.json
├── package.json
├── src
│ ├── app.js
│ ├── util.js
│ └── test
│ └── test.js
└── index.js
2 directories, 8 files
`;
const tree = parse(demo);
const list = files(tree);
console.log(list);
```
```json
[
"./README.md",
"./example.png",
"./package-lock.json",
"./package.json",
"./src/app.js",
"./src/util.js",
"./src/test/test.js",
"./index.js"
]
```