search-path - locate and fetch files from the filesystem using search path
A simple extension to Array to hold various search path directories and provide checks for existence and locate/fetch files accordingly.
Usage
Example usage (coffeescript):
SearchPath = require 'search-path'search = basedir: __dirnameexts: 'txt''doc' encoding: 'utf-8' # include example and test/foo directories as part of search (relative # to basedir) searchadd 'example''test/foo' consolelog search # shows current contents of search path consolelog searchlocate 'hello' # shows where 'hello', 'hello.txt', or 'hello.doc' was found consolelog searchfetch 'hello' # retrieves located content using 'encoding'
API
exists (paths..., opts)
Checks whether passed in paths exists in the local filesystem.
opts.basedir | string | prefix for relative paths opts.isDirectory | boolean | if true, checks if directory opts.isFile | boolean | if true, checks if file
base (path)
Update the current basedir to use for relative paths.
searchbase'/home' include 'some-user' include 'other-user/docs' consolelog search ## include (paths...) Adds additional directories into search path if they exist ## locate (files...) Finds all *files* existing in the current search path Always returnsan array containing one or more matching files ## resolve (files...) Locates all *files* existing in the current search path including anyfiles matching the configured *exts* as part of the current searchpath instance ## fetch (files...) Grabs contents of all resolved *files* using the *encoding* for thesearch path This is a convenience function and simply applies `fsreadFileSync` onthe results of `resolve` from above # License Apache 2.0LICENSE