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.
Example usage
var LoaderCache = require('loader-cache');
var loaders = new LoaderCache();
// register a loader for reading files
loaders.register('read', function(fp) {
return fs.readFileSync(fp, 'utf8');
});
// register a loader for parsing YAML
loaders.register('yaml', function(fp) {
return YAML.safeLoad(fp);
});
// create a loader from any combination of other
// registered loaders and functions.
loaders.register('dataLoader', ['read', 'yaml'], function(data) {
if (!data) throw new Error('no data!');
return data;
});
// pass a loader stack or the name of a loader to `.compose()`
// to create the actual function to be used for loading
var fn = loaders.compose('dataLoader');
var data = fn('config.yml');
Install
Install with npm
$ npm i loader-cache --save
Table of contents
(Table of contents generated by [verb])
API
Loaders
Create a new instance of Loaders
Example
var Loaders = require('loader-cache');
var loaders = new Loaders();
.getStack
Get a loader stack from the cache.
Params
name
{String}returns
{Object}
.buildStack
Build a loader stack from a mix of functions and loader names.
Params
stack
{Array}: array of loader functions and names.returns
{Array}: Resolved loader functions
.compose
Compose a loader function from the given functions and/or the names of loaders.
Params
loader(s)
{String|Array|Function}: String, list or array of loader names or functions, in any combination or order.returns
{Function}: Returns a function to use for loading.
Example
// this will return a function from the given loaders
// and function
loaders.compose(['a', 'b', 'c'], function(val) {
//=> do stuff to val
});
Related libs
- config-cache: General purpose JavaScript object storage methods.
- cache-base: Generic object cache for node.js/javascript projects.
- engine-cache: express.js inspired template-engine manager.
- helper-cache: Easily register and get helper functions to be passed to any template engine or node.js… more
- option-cache: Simple API for managing options in JavaScript applications.
- parser-cache: Cache and load parsers, similiar to consolidate.js engines.
Running tests
Install dev dependencies:
$ npm i -d && npm test
Code coverage
Please help improve code coverage by adding unit tests.
-----------------|-----------|-----------|-----------|-----------|
File | % Stmts |% Branches | % Funcs | % Lines |
-----------------|-----------|-----------|-----------|-----------|
loader-cache/ | 91.27 | 82.35 | 85.71 | 92.5 |
index.js | 91.27 | 82.35 | 85.71 | 92.5 |
-----------------|-----------|-----------|-----------|-----------|
All files | 91.27 | 82.35 | 85.71 | 92.5 |
-----------------|-----------|-----------|-----------|-----------|
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on June 13, 2015.