Package Exports
- loader-cache
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (loader-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
loader-cache

Register loader functions that dynamically read, parse or otherwise transform file contents when the name of the loader matches a file extension. You can also compose loaders from other loaders.
Install with npm
npm i loader-cache --save
Example
// register a loader for parsing YAML
loaders.register('yaml', function(fp) {
return YAML.safeLoad(fp);
});
// register a loader to be used in other loaders
loaders.register('read', function(fp) {
return fs.readFileSync(fp, 'utf8');
});
// create a new loader from the `yaml` and `read` loaders.
loaders.register('yml', ['read', 'yaml']);
// the `.load()` method calls any loaders registered
// to the `ext` on the given filepath
loaders.load('config.yml');
Running tests
Install dev dependencies.
npm i -d && npm test
Usage
var loaders = require('loader-cache');
API
Loaders
Create a new instance of Loaders
var Loaders = require('loader-cache');
var loaders = new Loaders();
.registerSync
ext
{String|Array}: File extension or name of the loader.fn
{Function|Array}: A loader function, or create a loader from other others by passing an array of names.returns
{Object}Loaders
: to enable chaining
Register the given loader callback fn
as ext
. Any arbitrary
name can be assigned to a loader, however, the loader will only be
called when either:
a. ext
matches the file extension of a path passed to the .load()
method, or
b. ext
is an arbitrary name passed on the loader stack of another loader. Example below.
.registerAsync
ext
{String|Array}: File extension or name of the loader.fn
{Function|Array}: A loader function with a callback parameter, or create a loader from other others by passing an array of names.returns
{Object}Loaders
: to enable chaining
Register the given async loader callback fn
as ext
. Any arbitrary
name can be assigned to a loader, however, the loader will only be
called when either:
a. ext
matches the file extension of a path passed to the .load()
method, or
b. ext
is an arbitrary name passed on the loader stack of another loader. Example below.
.registerPromise
ext
{String|Array}: File extension or name of the loader.fn
{Function|Array}: A loader function that returns a promise, or create a loader from other others by passing an array of names.returns
{Object}Loaders
: to enable chaining
Register the given promise loader callback fn
as ext
. Any arbitrary
name can be assigned to a loader, however, the loader will only be
called when either:
a. ext
matches the file extension of a path passed to the .load()
method, or
b. ext
is an arbitrary name passed on the loader stack of another loader. Example below.
.registerStream
ext
{String|Array}: File extension or name of the loader.fn
{Stream|Array}: A stream loader, or create a loader from other others by passing an array of names.returns
{Object}Loaders
: to enable chaining
Register the given stream loader callback fn
as ext
. Any arbitrary
name can be assigned to a loader, however, the loader will only be
called when either:
a. ext
matches the file extension of a path passed to the .load()
method, or
b. ext
is an arbitrary name passed on the loader stack of another loader. Example below.
.load
Run loaders associated with ext
of the given filepath.
val
{String}: Value to load, like a file path.options
{String}: Options to pass to whatever loaders are defined.returns
: {String}
Example
// this will run the `yml` loader from the `.compose()` example
loaders.load('config.yml');
.loadAsync
Run async loaders associated with ext
of the given filepath.
fp
{String}: File path to load.options
{Object}: Options to pass to whatever loaders are defined.cb
{Function}: Callback to indicate loading has finishedreturns
: {String}
Example
// this will run the `yml` async loader from the `.compose()` example
loaders.loadAsync('config.yml', function (err, obj) {
// do some async stuff
});
.loadPromise
Run promise loaders associated with ext
of the given filepath.
fp
{String}: File path to load.options
{Object}: Options to pass to whatever loaders are defined.returns
{Promise}: a promise that will be fulfilled later
Example
// this will run the `yml` promise loader from the `.compose()` example
loaders.loadPromise('config.yml')
.then(function (results) {
// do some promise stuff
});
.loadStream
Run stream loaders associated with ext
of the given filepath.
fp
{String}: File path to load.options
{Object}: Options to pass to whatever loaders are defined.returns
{Stream}: a stream that will be fulfilled later
Example
// this will run the `yml` stream loader from the `.compose()` example
loaders.LoadStream('config.yml')
.pipe(foo())
.on('data', function (results) {
// do stuff
});
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb-cli on March 10, 2015.