https://github.com/volem/secure-callback
Securely return to callback
https://github.com/volem/secure-callback
callback returns secure
Last synced: 23 days ago
JSON representation
Securely return to callback
- Host: GitHub
- URL: https://github.com/volem/secure-callback
- Owner: Volem
- Created: 2017-03-09T15:12:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T14:26:36.000Z (over 9 years ago)
- Last Synced: 2026-05-24T15:07:16.008Z (about 1 month ago)
- Topics: callback, returns, secure
- Language: JavaScript
- Homepage: http://nodejs.withvolkan.com/2017/03/13/Type-Definitions/
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# secure-callback [](https://travis-ci.org/Volem/secure-callback)
We all check that the callback function is available and if we forget to check we may end up strange errors. So how do we check? Let me write quickly, I believe you will remember :)
``` javascript
if (callback) {
callback(err);
}
return;
```
This is a very simple package to remove these lines of code and also provides custom message when you forgot to provide callback. A simple class which takes 3 arguments and all optional.
* First argument determines if you want to throw exception or not.
* Second argument is a custom message when you provide something else than a function by mistake. (Default message : callback is not a function.)
* Third argument is also a custom message when you forgot to provide the callback function. (Default message : callback should be defined.)
## Usage
``` javascript
var securecallback = require('secure-callback');
var secure = new securecallback();
...
// In your function that has callback use secure.respond
// Pass your callback and any number of arguments for your callback.
function callbackTest(callback) {
secure.respond(callback, null, 'success messsage');
}
```
Enjoy..