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

async-deco

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-deco - npm Package Compare versions

Comparing version 7.3.0 to 7.4.0

callback/validator.js

3

package.json
{
"name": "async-deco",
"version": "7.3.0",
"version": "7.4.0",
"description": "A collection of decorators for adding features to asynchronous functions (callback or promise based).",

@@ -37,2 +37,3 @@ "main": "index.js",

"memoize-cache-utils": "^0.0.2",
"occamsrazor-match": "^2.2.1",
"require-all": "^2.0.0",

@@ -39,0 +40,0 @@ "setimmediate": "^1.0.4",

@@ -14,2 +14,3 @@ async-deco

* [Proxy](#proxy)
* [Validator](#validator)
* [Fallback](#fallback)

@@ -236,2 +237,28 @@ * [Fallback value](#fallback-value)

Validator
---------
It uses [occamsrazor-match](https://github.com/sithmel/occamsrazor-match) (or any function) to perform arguments validation. It throws an exception if the validation fail.
It is available in 3 flavours, the usual callback, promise and synchronous.
```js
// var validatorDecorator = require('async-deco/promise/validator'); promise based
// var validatorDecorator = require('async-deco/utils/validator'); synchronous
var validatorDecorator = require('async-deco/callback/validator');
var validator = validatorDecorator({ name: /[a-zA-Z]/ }, or([false, true]));
var func = validator(function queryUser(user, onlyFirst, cb) {
...
});
func({ name: 'Bruce Wayne'}, true, function (err, res) {
... this passes the validation
});
func('Bruce Wayne', true, function (err, res) {
... this returns an error
});
```
Fallback

@@ -238,0 +265,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