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

attach-ware

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attach-ware - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

5

history.md

@@ -5,2 +5,7 @@ <!--remark setext-->

2.0.1 / 2016-08-10
==================
* Refactor code-style to use `xo` ([`afc1b80`](https://github.com/wooorm/attach-ware/commit/afc1b80))
2.0.0 / 2016-02-12

@@ -7,0 +12,0 @@ ==================

179

index.js

@@ -7,31 +7,2 @@ /**

* @fileoverview Middleware with configuration.
* @example
* var ware = require('attach-ware')(require('ware'));
*
* var middleware = ware()
* .use(function (context, options) {
* if (!options.condition) return;
*
* return function (req, res, next) {
* res.x = 'hello';
* next();
* };
* }, {
* 'condition': true
* })
* .use(function (context, options) {
* if (!options.condition) return;
*
* return function (req, res, next) {
* res.y = 'world';
* next();
* };
* }, {
* 'condition': false
* });
*
* middleware.run({}, {}, function (err, req, res) {
* res.x; // "hello"
* res.y; // undefined
* });
*/

@@ -41,6 +12,10 @@

/* eslint-env commonjs */
/* Dependencies. */
var unherit = require('unherit');
/* Expose. */
module.exports = patch;
/* Methods. */
var slice = [].slice;
var unherit = require('unherit');

@@ -55,101 +30,71 @@ /**

function patch(Ware) {
/*
* Methods.
*/
var AttachWare = unherit(Ware);
var useFn = Ware.prototype.use;
var useFn = Ware.prototype.use;
AttachWare.prototype.use = use;
/**
* @constructor
* @class {AttachWare}
*/
var AttachWare = unherit(Ware);
return function (fn) {
return new AttachWare(fn);
};
AttachWare.prototype.foo = true;
/**
* Attach configurable middleware.
*
* @memberof {AttachWare}
* @this {AttachWare}
* @param {Function} attach - Attacher.
* @return {AttachWare} - `this`.
*/
function use(attach) {
var self = this;
var params = slice.call(arguments, 1);
var index;
var length;
var fn;
/**
* Attach configurable middleware.
*
* @memberof {AttachWare}
* @this {AttachWare}
* @param {Function} attach - Attacher.
* @return {AttachWare} - `this`.
*/
function use(attach) {
var self = this;
var params = slice.call(arguments, 1);
var index;
var length;
var fn;
/* Multiple attachers. */
if ('length' in attach && typeof attach !== 'function') {
index = -1;
length = attach.length;
/*
* Multiple attachers.
*/
if ('length' in attach && typeof attach !== 'function') {
index = -1;
length = attach.length;
/*
* So, `attach[0]` is a function, meaning its
* either a list of `attachers` or its a `list`.
*/
if (typeof attach[0] === 'function') {
if (
(attach[1] !== null && attach[1] !== undefined) &&
typeof attach[1] !== 'function'
) {
self.use.apply(self, attach);
} else {
while (++index < length) {
self.use.apply(self, [
attach[index]
].concat(params));
}
}
} else {
while (++index < length) {
self.use(attach[index]);
}
}
return self;
/* So, `attach[0]` is a function, meaning its
* either a list of `attachers` or its a `list`. */
if (typeof attach[0] === 'function') {
if (
(attach[1] !== null && attach[1] !== undefined) &&
typeof attach[1] !== 'function'
) {
self.use.apply(self, attach);
} else {
while (++index < length) {
self.use.apply(self, [attach[index]].concat(params));
}
}
} else {
while (++index < length) {
self.use(attach[index]);
}
}
/*
* Single attacher.
*/
return self;
}
fn = attach.apply(null, [self.context || self].concat(params));
/* Single attacher. */
fn = attach.apply(null, [self.context || self].concat(params));
/*
* Store the attacher to not break `new Ware(otherWare)`
* functionality.
*/
/* Store the attacher to not break `new Ware(otherWare)`
* functionality. */
if (!self.attachers) {
self.attachers = [];
}
if (!self.attachers) {
self.attachers = [];
}
self.attachers.push(attach);
self.attachers.push(attach);
/*
* Pass `fn` to the original `Ware#use()`.
*/
if (fn) {
useFn.call(self, fn);
}
return self;
/* Pass `fn` to the original `Ware#use()`. */
if (fn) {
useFn.call(self, fn);
}
AttachWare.prototype.use = use;
return function (fn) {
return new AttachWare(fn);
};
return self;
}
}
module.exports = patch;
{
"name": "attach-ware",
"version": "2.0.0",
"version": "2.0.1",
"description": "Middleware with configuration",

@@ -16,6 +16,3 @@ "license": "MIT",

},
"repository": {
"type": "git",
"url": "https://github.com/wooorm/attach-ware.git"
},
"repository": "https://github.com/wooorm/attach-ware",
"bugs": "https://github.com/wooorm/attach-ware/issues",

@@ -26,2 +23,5 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

],
"engines": {
"node": ">=0.11.0"
},
"files": [

@@ -32,15 +32,12 @@ "index.js"

"browserify": "^13.0.0",
"eslint": "^1.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.4.0",
"jscs": "^2.0.0",
"jscs-jsdoc": "^1.0.0",
"remark": "^4.0.0-alpha.4",
"remark-comment-config": "^3.0.0-alpha.1",
"remark-github": "^4.0.1",
"remark-lint": "^2.0.0",
"remark-toc": "^3.0.0-alpha.2",
"remark-validate-links": "^2.0.2",
"nyc": "^7.1.0",
"remark-cli": "^1.0.0",
"remark-comment-config": "^4.0.0",
"remark-github": "^5.0.0",
"remark-lint": "^4.0.0",
"remark-validate-links": "^4.0.0",
"tape": "^4.4.0",
"ware": "^1.3.0"
"ware": "^1.3.0",
"xo": "^0.16.0"
},

@@ -52,9 +49,36 @@ "scripts": {

"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint-api": "eslint .",
"lint-style": "jscs --reporter inline .",
"lint": "npm run lint-api && npm run lint-style",
"test-api": "node test.js",
"test-coverage": "istanbul cover test.js",
"lint": "xo",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"xo": {
"space": true,
"rules": {},
"ignores": [
"attach-ware.js",
"attach-ware.min.js"
]
},
"remarkConfig": {
"output": true,
"plugins": {
"comment-config": null,
"lint": {
"heading-increment": false,
"list-item-spacing": false
},
"github": null,
"validate-links": null
},
"settings": {
"bullet": "*"
}
}
}

@@ -7,3 +7,3 @@ # attach-ware [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

[npm][npm-install]:
[npm][]:

@@ -14,5 +14,2 @@ ```bash

**attach-ware** is also available as an AMD, CommonJS, and globals
module, [uncompressed and compressed][releases].
## Usage

@@ -81,3 +78,3 @@

**Signatures**:
###### Signatures

@@ -89,14 +86,13 @@ * `attachWare.use(attacher[, input...])`;

**Parameters**:
###### Parameters
* `attacher` (`Function`) — One attacher.
* `attachers` (`Array.<Function>`)
— List where each value is an `attacher`;
* `list` (`Array`)
— List where the first value is an `attacher`, and further values
are `input`;
* `matrix` (`Array`)
— Matrix where each entry is a `list`.
* `attachers` (`Array.<Function>`) — List where each value is an
`attacher`;
* `list` (`Array`) — List where the first value is an `attacher`,
and further values are `input`;
* `matrix` (`Array`) — Matrix where each entry is a `list`.
Invokes `attacher` with [`context`][context] and all `input`.

@@ -128,6 +124,4 @@

[npm-install]: https://docs.npmjs.com/cli/install
[npm]: https://docs.npmjs.com/cli/install
[releases]: https://github.com/wooorm/attach-ware/releases
[license]: LICENSE

@@ -134,0 +128,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