Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darianstlex/directory-shaker
Convert JS files structure to object, extract data
https://github.com/darianstlex/directory-shaker
Last synced: about 13 hours ago
JSON representation
Convert JS files structure to object, extract data
- Host: GitHub
- URL: https://github.com/darianstlex/directory-shaker
- Owner: darianstlex
- License: mit
- Created: 2018-11-11T18:08:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T22:51:13.000Z (about 6 years ago)
- Last Synced: 2024-12-08T09:15:43.401Z (about 1 month ago)
- Language: JavaScript
- Size: 70.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> Directory Shaker
Convert JS files (include ES6) structure into object, extract data
### Installation
```code
npm install directory-shaker
```### Usage
```code
const path = require('path');
const getTreeObj = require('directory-shaker');.........
const folder = path.resolve(__dirname, 'folder');
const { tree, parserName1, parserName2 } = getTreeObj(folder, {
recursive: true,
spreadIndex: true,
pattern: /^.*\.js$/,
filter: () => true,
}, { // parser }, { // parser } ).........
```
Check test folder for more examples### Arguments
- **`path: string:`** path to the root folder to start with
- **`options: object:`** configuration options
- **`parser: object:`** parser to extract data separately#### Options
- **`recursive: boolean: true`** deep object construction
- **`spreadIndex: boolean: true`** assign index props to the root or in 'index' node
- **`pattern: RegExp: /^.*\.js$/`** file pattern to be included in the tree
- **`filter: function:`** filter files to be included in the tree#### Parser
```code
{
name: 'paths',
key: 'name',
map: ({ name, page }, meta) => ({ name, page, meta}),
}
```- **`name: string:`** name of the object to be returned
- **`key: string:`** key in the result object to assign result of the map function
- **`map: function:`** function to prepare object data to be returned##### Map Function
- **`data: object:`** file default exported object
- **`meta: object:`** file meta data: 'name' and 'path'### Limitations
See 'esm' library documentation for the limitations