Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loader-cache

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loader-cache - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

.verb.md

@@ -38,3 +38,3 @@ # {%= name %} {%= badge("fury") %}

```js
var readers = require('{%= name %}');
var loaders = require('{%= name %}');
```

@@ -41,0 +41,0 @@

@@ -19,10 +19,10 @@ /*!

/**
* Create a new instance of `Loader`
* Create a new instance of `Loaders`
*
* ```js
* var Loader = require('loader');
* var loader = new Loader();
* var Loaders = require('loader-cache');
* var loaders = new Loaders();
* ```
*
* @class `Loader`
* @class `Loaders`
* @api public

@@ -88,4 +88,4 @@ */

Loaders.prototype.register = function(ext, fn) {
this._register(ext, fn, 'sync');
Loaders.prototype.register = function(ext, fn, type) {
this._register(ext, fn, type || 'sync');
};

@@ -268,4 +268,3 @@

Loaders.prototype.load = function(fp, options) {
var ext = path.extname(fp);
var fns = this.cache.sync[formatExt(ext)];
var fns = this.cache.sync[matchLoader(fp, options, this)];
if (!fns) return fp;

@@ -303,4 +302,4 @@

}
var ext = path.extname(fp);
var fns = this.cache.async[formatExt(ext)];
var fns = this.cache.async[matchLoader(fp, options, this)];
if (!fns) return fp;

@@ -336,7 +335,6 @@

options = options || {};
var ext = path.extname(fp);
var fns = this.cache.promise[formatExt(ext)];
var fns = this.cache.promise[matchLoader(fp, options, this)];
if (!fns) return current.then(function () { return fp; });
return Promise.reduce(fns, function (acc, fn) {

@@ -370,4 +368,4 @@ return fn(acc, options);

options = options || {};
var ext = path.extname(fp);
var fns = this.cache.stream[formatExt(ext)];
var fns = this.cache.stream[matchLoader(fp, options, this)];
if (!fns) {

@@ -390,2 +388,17 @@ var noop = es.through(function (fp) {

/**
* Get a loader based on the given pattern.
*
* @param {String} `pattern` By default, this is assumed to be a filepath.
* @return {Object} Object
* @api private
*/
function matchLoader(pattern, options, thisArg) {
if (options && options.matchLoader) {
return options.matchLoader(pattern, options, thisArg);
}
return formatExt(path.extname(pattern));
}
/**
* Format extensions.

@@ -392,0 +405,0 @@ *

{
"name": "loader-cache",
"description": "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.",
"version": "0.1.1",
"version": "0.1.2",
"homepage": "https://github.com/jonschlinkert/loader-cache",

@@ -6,0 +6,0 @@ "author": {

@@ -6,3 +6,3 @@ # loader-cache [![NPM version](https://badge.fury.io/js/loader-cache.svg)](http://badge.fury.io/js/loader-cache)

## Install
### Install with [npm](npmjs.org)
## Install with [npm](npmjs.org)

@@ -43,3 +43,3 @@ ```bash

```js
var readers = require('loader-cache');
var loaders = require('loader-cache');
```

@@ -50,10 +50,10 @@

Create a new instance of `Loader`
Create a new instance of `Loaders`
```js
var Loader = require('loader');
var loader = new Loader();
var Loaders = require('loader-cache');
var loaders = new Loaders();
```
### [register](index.js#L87)
### [.register](index.js#L87)

@@ -83,3 +83,3 @@ 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](index.js#L121)
### [.registerAsync](index.js#L121)

@@ -109,3 +109,3 @@ 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](index.js#L165)
### [.registerPromise](index.js#L165)

@@ -145,3 +145,3 @@ 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](index.js#L201)
### [.registerStream](index.js#L201)

@@ -173,3 +173,3 @@ 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](index.js#L265)
### [.load](index.js#L265)

@@ -189,3 +189,3 @@ Run loaders associated with `ext` of the given filepath.

### [loadAsync](index.js#L294)
### [.loadAsync](index.js#L294)

@@ -208,3 +208,3 @@ Run async loaders associated with `ext` of the given filepath.

### [loadPromise](index.js#L328)
### [.loadPromise](index.js#L328)

@@ -227,3 +227,3 @@ Run promise loaders associated with `ext` of the given filepath.

### [loadStream](index.js#L362)
### [.loadStream](index.js#L362)

@@ -264,2 +264,2 @@ Run stream loaders associated with `ext` of the given filepath.

_This file was generated by [verb](https://github.com/assemble/verb) on November 18, 2014._
_This file was generated by [verb](https://github.com/assemble/verb) on November 27, 2014._

@@ -10,2 +10,3 @@ /*!

var path = require('path');
var Promise = require('bluebird');

@@ -80,2 +81,13 @@ var es = require('event-stream');

});
it('should use a custom function for matching loaders:', function () {
loaders.compose('parse', ['read', 'yaml']);
loaders.compose('extend', ['data']);
loaders.compose('bar', ['parse', 'extend']);
loaders.load('fixtures/a.bar', {
matchLoader: function(pattern) {
return path.extname(pattern).slice(1);
}
}).should.eql({c: 'd', e: 'f'});
});
});

@@ -82,0 +94,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc