Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
compose-iterator
Advanced tools
Use iterator for middleware composition.
$ npm install compose-iterator
'use strict'
const Promise = require('any-promise')
const iterator = require('..')
/**
* Expose compositor.
*/
module.exports = compose
/**
* Compose `middleware` returning
* a fully valid middleware comprised
* of all those which are passed.
*
* @param {Array} middleware
* @return {Function}
* @api public
*/
function compose (middleware) {
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!')
}
/**
* @param {Object} context
* @return {Promise}
* @api public
*/
return function (context, next) {
// iteration object
const iter = iterator[Symbol.iterator](middleware, context, next)
try {
return Promise.resolve(iter.next().value)
} catch (err) {
return Promise.reject(err)
}
}
}
const co = require('co')
const compose = require('./compose')
function wait (ms) {
return new Promise((resolve) => setTimeout(resolve, ms || 1))
}
var arr = []
var stack = []
stack.push(function * (context, next) {
arr.push(1)
yield wait(1)
yield next()
yield wait(1)
arr.push(6)
})
stack.push(function * (context, next) {
arr.push(2)
yield wait(1)
yield next()
yield wait(1)
arr.push(5)
})
stack.push(function * (context, next) {
arr.push(3)
yield wait(1)
yield next()
yield wait(1)
arr.push(4)
})
compose(stack.map((fn) => co.wrap(fn)))({}).then(function () {
console.log(arr.toString() === [1, 2, 3, 4, 5, 6].toString())
})
FAQs
Fastest iterator for middleware composition
The npm package compose-iterator receives a total of 2 weekly downloads. As such, compose-iterator popularity was classified as not popular.
We found that compose-iterator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.