read-directory
Read a directory of files.
Install
npm install --save read-directory
Examples
Async example:
var read =
Sync example:
var read = var contents = read
Using in the browser with browserify & budo
Use the included browserify transform module to convert calls to read.sync
to the contents of the directory.
Note that to use the browserify transform you must use read.sync
, and the path to the file directory can not be a variable.
File that will be browserified & transformed:
var path = var read = var contents = read
Browserify example:
browserify index.js -t read-directory -o bundle.js
budo example:
budo index.js:bundle.js -- -t read-directory
API
readDirectory
Read the contents of a directory asynchronously
Parameters
dir
String – The directory to readoptions
Objectoptions.fs
Object – alternate fs implementation, optionaloptions.dirnames
Boolean – include or exclude subdirectory names in keys of returned objectoptions.encoding
String – encoding of files, default: utf8options.filter
String – glob pattern for filtering files, examples:*.md
,*.css
options.ignore
String – glob pattern for ignoring filesoptions.ignore
Array – array of glob patterns for ignoring filesoptions.transform
Function – A function you can use to transform the contents of files after they are read
Examples
var read =
readDirectory.sync
Read the contents of a directory asynchronously
Parameters
dir
String – The directory to readoptions
Objectoptions.fs
Object – alternate fs implementation, optionaloptions.dirnames
Boolean – include or exclude subdirectory names in keys of returned objectoptions.encoding
String – encoding of files, default: utf8options.filter
String – glob pattern for filtering files, examples:*.md
,*.css
options.ignore
String – glob pattern for ignoring filesoptions.ignore
Array – array of glob patterns for ignoring filesoptions.transform
Function – A function you can use to transform the contents of files after they are read
Examples
var read = var contents = read