FS Sniff
Simple helper sniffing for files based on provided patterns.
Methods
file(path)
Searches for local files based on passed parameters.
If you searching for docs/readme.md
file you can call file()
method passing path as a parameter.
// file location
Method returns promise. If file exist promise resolve with file
object, which contains 2 parameters:
path
- file location (string)stats
- fs.Stats object
If you would like to check if file exists in more than one directory you can call file()
method passing into it an array of paths, eg.:
file(path, options)
Method file
allows "sniffing" options object to be passed as a second parameter. It should have either of (or both) properties:
index
- array of index filesext
- file extensions you are looking fortype
file type string:'any'
(default),'file'
,'dir'
Below code will look for public/index.html
and public/index.htm
in that order
Another example, looking for directory:
lib/script/
and files:
lib/script.jsx
,lib/script.js
lib/script.cofee
in that order.
list(path, options)
Returns list of files from path
location. I takes two parameters:
path
location stringopts
object as an optional parameter with two propertiesdepth
recursive listing depth (default: 0)type
file type string:'any'
(default),'file'
,'dir'
Should output something like:
[
"directory-1",
"directory-1\subcategory-1",
"directory-1\subcategory-2",
]
tree(path, options)
Returns array of dir
objects from path
location. Method takes two parameters:
poath
and options
object with internal properties listed below.
path
location stringopts
object as an optional parameter with two propertiesdepth
recursive listing depth (default: 0)rootPrefix
iffalse
it won't prefixuri
properties with root directory
Should output something like:
{
"name": "example",
"uri": "",
"path": "full/path/to/directory",
"dirs": [
/* nested dir objects */
],
"files": [
"index.js",
"another-file.md
]
}
Notice that uri
property is empty (""
) because opts.rootPrefix
parameter
passed to a method is set to false