npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loader-cache

v0.6.1

Published

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.

Downloads

4,551

Readme

loader-cache NPM version Build Status

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

API

LoaderCache

Create a new instance of LoaderCache

Example

var LoaderCache = require('loader-cache');
var loaders = new LoaderCache();

.iterator

Register an iterator function of the given type. Types typically represent a kind of flow-control, like sync, promise, stream, async etc.

Params

  • type {String}
  • options {Object}
  • fn {Function}: The actual iterator function.
  • returns {Object}

Example

loader.iterator('sync', function(stack) {
  // `stack` is the loader stack (array) to iterate over
  // each item in array is a loader function
  return function(args) {
    // `args` is the arguments passed to the loaders
  }
});

.loader

Register a loader. The first argument is the name of the loader to register.

Params

  • name {String}
  • options {Object}
  • fns {Function|Array}: One or more loader functions or names of other registered loaders.
  • returns {Array}

Example

// create a loader from other loaders.
loaders.loader('foo', ['bar', 'baz']);
// pass a function
loaders.loader('foo', function(patterns, options) {
  return glob.sync(patterns, options);
});
// combination
loaders.loader('foo', ['bar', 'baz'], function(patterns, options) {
  return glob.sync(patterns, options);
});

.compose

Compose the actual load function from a loader stack.

Params

  • name {String}: The name of the loader stack to use.
  • options {Object}
  • stack {Array|Function}: Additional loader names or functions.
  • returns {Function}

Example

var fn = loaders.compose('foo');
// load some files
var files = fn('*.txt');

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 29, 2015.