https://github.com/tobilg/fs2obj
A Node.js module which recurses through a folder structure and returns an object with all found files/folders below the start path.
https://github.com/tobilg/fs2obj
Last synced: over 1 year ago
JSON representation
A Node.js module which recurses through a folder structure and returns an object with all found files/folders below the start path.
- Host: GitHub
- URL: https://github.com/tobilg/fs2obj
- Owner: tobilg
- License: mit
- Created: 2015-04-17T12:28:31.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-11-30T11:33:19.000Z (over 3 years ago)
- Last Synced: 2024-10-22T21:08:43.470Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fs2obj
## Current status
[](http://travis-ci.org/tobilg/fs2obj)
[](https://david-dm.org/tobilg/fs2obj)
## Basic usage
### fs2obj( path [, options] )
To all the files and folder from a start folder and any sub-folders:
var fs2obj = require('fs2obj');
var structure = fs2obj('/path/to/folder');
Resulting object will look like:
```
{
"items": [{
"name": "file1.js",
"type": "file",
"size": 0
}, {
"name": "file2.conf",
"type": "file",
"size": 0
}, {
"name": "file3.txt",
"type": "file",
"size": 15
}, {
"items": [{
"name": "test1-file.txt",
"type": "file",
"size": 0
}, {
"items": [{
"name": "subtest-file1.txt",
"type": "file",
"size": 0
}],
"name": "subtest1",
"type": "folder"
}],
"name": "test1",
"type": "folder"
}]
}
```
## Advanced usage
Options can be passed to alter the behaviour.
### filterFiles
A regular expression for what files to include. First matching group defines the key used in returned object.
Defaults to `/^(.+)\.js(on)?$/` (i.e. include all `.js` and `.json` files)
// Include all .js files except those starting with `_`
fs2obj('/path/to/folder', { filterFiles: /^([^_].*)\.js$/ });
### filterFolders
A regular expression for what folders to iterate into. First matching group defines the key used in returned object.
Defaults to `/^([^\.].*)$/` (i.e. process all folders except those beginning with `.`)
// Process all folders except those starting with `.` or `_`
fs2obj('/path/to/folder', { filterFolders: /^([^\._].*)$/ });
### includeBasePath
A boolean value whether the base path (from the start folder) should be included or not.
### includeRealPath
A boolean value whether the real path should be included or not.
## Tests
Use `npm test` to run the tests.
## Issues
If you discover a bug, please raise an issue on Github. https://github.com/tobilg/fs2obj/issues