https://github.com/parro-it/include-folder
expose the content of each file in a folder as an object property
https://github.com/parro-it/include-folder
Last synced: 9 months ago
JSON representation
expose the content of each file in a folder as an object property
- Host: GitHub
- URL: https://github.com/parro-it/include-folder
- Owner: parro-it
- License: mit
- Created: 2013-12-05T17:34:05.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T12:59:56.000Z (over 5 years ago)
- Last Synced: 2024-08-08T22:35:10.013Z (over 1 year ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 18
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# include-folder
[](http://travis-ci.org/parro-it/include-folder) [](https://npmjs.org/package/include-folder) [](https://codeclimate.com/github/parro-it/include-folder)
Expose the content of each file in a folder as an object property.
This module is browserifiable using the [folderify transform](https://github.com/parro-it/folderify)
## Getting Started
Install the module with: `npm install include-folder --save`
Then use like this:
```javascript
var includeFolder = require('include-folder'),
folder = includeFolder("./aFolder");
```
Supposing that the content of aFolder was the same as in [the sample in test](https://github.com/parro-it/include-folder/tree/master/test/files)
folder var will contains:
```javascript
{
file3OtherFile: 'this is file3OtherContent content',
file1: 'this is file1 content',
file1_1: 'this is file1_1 content'
}
```
## Filter included files
You can filter which files to include using the filter parameter:
```javascript
var includeFolder = require('include-folder'),
folder = includeFolder("./aFolder",/^a.*/);
```
This only include files that start with 'a'
Filter parameters defaults to /^[^.].*$/, which include every file
in the folder, except hidden ones (these that has a name starting with dot).
## Preserve filenames
To prevent normalization and stripping of the extension in the result object, the `preserveFilenames` option can be used:
```javascript
includeFolder('./www', null, { preserveFilenames: true });
```
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality.
## License
Copyright (c) 2013 Andrea Parodi
Licensed under the MIT license.