middlewarify
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "middlewarify", | ||
"description": "Apply the middleware pattern to any function.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/thanpolas/middlewarify", | ||
@@ -17,8 +17,3 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/thanpolas/middlewarify/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"license": "MIT", | ||
"contributors": [ | ||
@@ -28,18 +23,21 @@ {} | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
"node": ">= 10" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha -u tdd -R spec test/" | ||
"test": "mocha -u tdd -R spec test/", | ||
"release": "grunt release:patch", | ||
"release:minor": "grunt release:minor", | ||
"release:major": "grunt release:major" | ||
}, | ||
"dependencies": { | ||
"lodash": "~3.10.0", | ||
"async": "~1.4.0", | ||
"bluebird": "~2.9.34" | ||
"lodash": "~4.17.15", | ||
"async": "~3.1.1", | ||
"bluebird": "~3.7.2" | ||
}, | ||
"devDependencies": { | ||
"sinon": "~1.15.4", | ||
"mocha": "~2.2.5", | ||
"chai": "~3.2.0", | ||
"grunt": "~0.4.5", | ||
"grunt-release": "~0.13.0" | ||
"sinon": "~8.1.1", | ||
"mocha": "~7.0.1", | ||
"chai": "~4.2.0", | ||
"grunt": "~1.0.4", | ||
"grunt-release": "~0.14.0" | ||
}, | ||
@@ -46,0 +44,0 @@ "keywords": [ |
@@ -23,11 +23,14 @@ # Middlewarify | ||
```js | ||
var middlewarify = require('middlewarify'); | ||
const middlewarify = require('middlewarify'); | ||
var tasks = module.exports = {}; | ||
const tasks = module.exports = {}; | ||
// this is the main callback of your middleware, | ||
// it will be the last callback to be invoked. | ||
function createTask() { | ||
function createTask(data) { | ||
console.log('createTask Final Fn to be invoked'); | ||
return 'a value'; | ||
/** do something with "data" ... */ | ||
return true; | ||
} | ||
@@ -44,8 +47,9 @@ | ||
var tasks = require('./tasks'); | ||
const tasks = require('./tasks'); | ||
// add middleware to the 'create' operation | ||
tasks.create.use(function(){ | ||
tasks.create.use(function(data) { | ||
console.log('middleware 1'); | ||
data.newAttr = 2; | ||
}); | ||
@@ -55,10 +59,9 @@ | ||
// this time use a promise to indicate asynchronicity | ||
tasks.create.use(function() { | ||
return new Promise(resolve, reject) { | ||
console.log('middleware 2'); | ||
tasks.create.use(function(data) { | ||
return new Promise(function(resolve, reject) { | ||
console.log('middleware 2. Title:', data.title); | ||
data.secondAttr = 3; | ||
resolve(); | ||
}); | ||
}); | ||
``` | ||
@@ -70,10 +73,10 @@ | ||
// ... Invoking them all together | ||
tasks.create() | ||
// prints | ||
tasks.create(data) | ||
// prints: | ||
// middleware 1 | ||
// middleware 2 | ||
// createTask Final Fn to be invoked | ||
.then(function(val) { | ||
console.log(val); | ||
// prints: "a value" | ||
.then(function(result) { | ||
console.log(result); | ||
// prints: true | ||
}); | ||
@@ -85,3 +88,3 @@ ``` | ||
```js | ||
tasks.create().then(function() { | ||
tasks.create(data).then(function(result) { | ||
// all middleware finished. | ||
@@ -93,2 +96,12 @@ }, function(err) { | ||
You may also use Async/Await: | ||
```js | ||
try { | ||
const result = await tasks.create(data); | ||
} catch (ex) { | ||
// handle error. | ||
} | ||
``` | ||
### Using the Before / After / Last Middleware types | ||
@@ -109,5 +122,5 @@ | ||
```js | ||
var middlewarify = require('middlewarify'); | ||
const middlewarify = require('middlewarify'); | ||
var tasks = module.exports = {}; | ||
const tasks = module.exports = {}; | ||
@@ -161,3 +174,3 @@ // This is the main callback of your middleware, | ||
// create a Middleware Container | ||
var crud = {}; | ||
const crud = {}; | ||
middlewarify.make(crud, 'create'); | ||
@@ -192,3 +205,3 @@ ``` | ||
// create the Middleware Container | ||
var crud = {}; | ||
const crud = {}; | ||
middlewarify.make(crud, 'create', fnFinal); | ||
@@ -234,3 +247,3 @@ | ||
crud.create.before(function() { | ||
return new Promise(resolve, reject) { | ||
return new Promise(function(resolve, reject) { | ||
// do something async... | ||
@@ -249,3 +262,3 @@ resolve(); | ||
```js | ||
var crud = {}; | ||
const crud = {}; | ||
middlewarify.make(crud, 'create'); | ||
@@ -319,5 +332,7 @@ | ||
- **v1.0.1**, *30 Jan 2020* | ||
- Updated all dependencies to latest. | ||
- **v1.0.0**, *23 Jul 2015* | ||
- Honorary release. | ||
- Update all dependencies to latest | ||
- Updated all dependencies to latest. | ||
- **v0.4.0**, *25 Jul 2014* | ||
@@ -356,6 +371,4 @@ - Now After & Last middlewares may alter the result value by returning a non undefined value. | ||
Copyright ©2015 Thanasis Polychronakis | ||
Copyright Thanasis Polychronakis, licensed under the [MIT License](LICENSE-MIT). | ||
Licensed under the [MIT License](LICENSE-MIT) | ||
[grunt]: http://gruntjs.com/ | ||
@@ -362,0 +375,0 @@ [Getting Started]: https://github.com/gruntjs/grunt/wiki/Getting-started |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48354
367
12
+ Addedasync@3.1.1(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedlodash@4.17.21(transitive)
- Removedasync@1.4.2(transitive)
- Removedbluebird@2.9.34(transitive)
- Removedlodash@3.10.1(transitive)
Updatedasync@~3.1.1
Updatedbluebird@~3.7.2
Updatedlodash@~4.17.15