Reqr
Tiny configurable library for requiring collections of files.
This library was inspired by require-dir.
Reqr.dir(path, config)
require
s a collection of files in a directory.
Returns a tree object: each leaf is a loaded file, each node is a directory.
The defaults
The following is an example with the default configuration.
Reqrdir'.' recur: false filter: /\.js$/ alias: Reqr { return a; } cull: true lazy: false { return a; } { return a; }
Config
recur
Whether or not to traverse down all directories found.
"type": "Boolean" "default": false
filter
When filter is a function it is called with the filenames found. If it returns truthy, then the file is accepted into the result. When filter is a regular expression, the file is accepted if the filename matches the filter pattern. Otherwise, files are always accepted.
"type": "(String -> Boolean) | RegExp | *" "default": /\.js$/
alias
Transform file names.
"type": "String -> String" "default": Reqr
aliasDir
Transform the names of directories.
"type": "String -> String" { return a; }
cull
Ignore empty directories.
"type": "Boolean" "default": true
lazy
When true, the files will not be loaded until they are first accessed.
"type": "Boolean" "default": false
transform
Defines a transformation to be applied to every loaded file.
"type": "* -> *" { return a; }
choose
Defines the mechanism by which we should choose which file to include if
there is an alias conflict. A Modlet
is an object with a file path
and
the loaded module
: { path: String, module: * }
.
"type": "(Modlet, Modlet) -> Modlet" { return a; }
Reqr.scan(path, config)
Scan for a collection of files in a directory.
Returns a tree object: each leaf is a file path, each node is a directory.
The defaults
The following is an example with the default configuration.
Reqr
Config
recur
Whether or not to traverse down all directories found.
"type": "Boolean" "default": false
filter
When filter is a function it is called with the filenames found. If it returns truthy, then the file is accepted into the result. When filter is a regular expression, the file is accepted if the filename matches the filter pattern. Otherwise, files are always accepted.
"type": "(String -> Boolean) | RegExp | *" "default": /\.js$/
alias
Transform file names.
"type": "String -> String" "default": Reqr
aliasDir
Transform the names of directories.
"type": "String -> String" { return a; }
cull
Ignore empty directories.
"type": "Boolean" "default": true
Reqr.load(tree, config)
require
s a collection of files in a tree.
Given a tree of filenames, returns a new tree object in which each leaf is
the corresponding filename require
d, and each node is a directory.
The defaults
The following is an example with the default configuration.
Reqr
Config
lazy
When true, the files will not be loaded until they are first accessed.
"type": "Boolean" "default": false
transform
Defines a transformation to be applied to every loaded file.
"type": "* -> *" { return a; }
choose
Defines the mechanism by which we should choose which file to include if
there is an alias conflict. A Modlet
is an object with a file path
and
the loaded module
: { path: String, module: * }
.
"type": "(Modlet, Modlet) -> Modlet" { return a; }
Reqr.force(tree)
Given a tree of lazily required files, force load all the files.
The defaults
The following is an example with the default configuration.
Reqr
Config
recur
Whether or not to traverse the whole tree. When false, only loads the top-level.
"type": "Boolean" "default": false
Reqr.replace(pattern, replacement)(string)
Util function for string.replace(pattern, replacement)
.