path-rooter
Set of utilities that combine glob patterns and node (fresh) imports from a root path.
Explanation
This tool can do 6 things via 6 methods:
rooter.resolve
: Build paths from a root path and the parts.rooter.require
: Import files from a root path and the parts.rooter.execute
: Execute files from a root path and the parts.rooter.find
: Find files from a root path and a set ofglob
patterns.rooter.findAndRequire
: Import files from a root path and a set ofglob
patterns.rooter.findAndExecute
: Execute files from a root path and a set ofglob
patterns.
Installation
$ npm i -s path-rooter
Usage
Import the module and create an instance:
const Rooter = ;const rooter = Rooter;
Build 1 route:
const route = rooter;
Import using cache:
const data = rooter;
Import avoiding cache:
const freshData = rooter;
Build routes from glob patterns:
const routes = rooter;
Import using cache from glob patterns:
const dataSet = rooter;
Import avoiding cache from glob patterns:
const freshDataSet = rooter;
API Reference
Rooter = require("rooter")
Class of rooter
.
rooter = new Rooter($directory)
Constructor of rooter
instances.
Defines the rooter.ROOT
path from which the other routes will be built.
Accepts a string.
Rooter.create($directory)
The same as the constructor.
rooter.resolve(...$routes)
Method that builds a route from its parts and starting from the rooter.ROOT
path.
It accepts a list of strings that will be merged and appended to rooter.ROOT
.
Returns a string with the resultant file.
rooter.find(...$patterns)
Method that returns the paths of the files found from the provided glob
patterns and starting from the rooter.ROOT
path.
It accepts a list of strings and arrays. Each string will be used as globby pattern and appended to rooter.ROOT
to make the search.
Returns a list of strings with the files found.
rooter.require(...$route)
Method that imports one module (using the usual cache of node
) from the parts of its path and from the rooter.ROOT
path.
It accepts a list of strings. Each string will be merged and appended to rooter.ROOT
to create the new path, and that path is imported.
Returns the module.
rooter.execute(...$route)
Method that imports one module (avoiding the usual cache of node
) from the parts of its path and from the rooter.ROOT
path.
It works the same as require
, but it will avoid nodejs default caching.
rooter.findAndRequire(...$patterns)
Method that first finds all the files matching the glob
patterns provided from the rooter.ROOT
path, and then imports them (using the usual cache of node
).
It works the same as find
and require
combined. So, it returns a list (with what modules returned).
rooter.findAndExecute(...$patterns)
Method that first finds all the files matching the glob
patterns provided from the rooter.ROOT
path, and then imports them (avoiding the usual cache of node
).
It works the same as find
and execute
combined. So, it returns a list (with what modules returned).
Test
$ npm run test
Documentation
$ npm run docs
Issues
Here.
License
WTFPL. 100% free.