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

koa-compose

Package Overview
Dependencies
Maintainers
7
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-compose - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

History.md

44

index.js

@@ -0,1 +1,2 @@

'use strict'

@@ -19,22 +20,31 @@ /**

function compose(middleware){
return function *(next){
var i = middleware.length;
var prev = next || noop();
var curr;
if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')
for (const fn of middleware) {
if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')
}
while (i--) {
curr = middleware[i];
prev = curr.call(this, prev);
/**
* @param {Object} context
* @return {Promise}
* @api public
*/
return function (context, next) {
// last called middleware #
let index = -1
return dispatch(0)
function dispatch(i) {
if (i <= index) return Promise.reject(new Error('next() called multiple times'))
index = i
const fn = middleware[i] || next
if (!fn) return Promise.resolve()
try {
return Promise.resolve(fn(context, function next() {
return dispatch(i + 1)
}))
} catch(err) {
return Promise.reject(err);
}
}
yield *prev;
}
}
/**
* Noop.
*
* @api private
*/
function *noop(){}

@@ -5,3 +5,3 @@ {

"repository": "koajs/compose",
"version": "2.3.0",
"version": "3.0.0",
"keywords": [

@@ -17,11 +17,13 @@ "koa",

"devDependencies": {
"co": "~3.0.1",
"mocha": "~1.6.0",
"should": "~2.1.0",
"koa": "~0.3.0"
"co": "^4.6.0",
"istanbul": "0",
"mocha": "2",
"should": "2"
},
"scripts": {
"test": "make test"
"test": "mocha --harmony --require should --reporter spec",
"test-cov": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require should",
"test-travis": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should"
},
"license": "MIT"
}

@@ -6,2 +6,8 @@

## Installation
```js
$ npm install koa-compose
```
## API

@@ -15,2 +21,2 @@

MIT
MIT
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