
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
validate = require('vchains').validate;
console.log(
validate('4276-8010-XXXX-5090', 'Credit card number is valid.').isCard('It is not credit card number!').msg()
); // Will print "Credit card number is valid."
If you need custom validation method, your can extend vchains.
Call vchains.use() with your validation method as parameter. After that you can access you method from any validation object instance.
vchains = require('vchains');
validate = vchains.validate;
vchains.use('globalTest', function(msg){
if(this.value.indexOf(' ') >= 0) return msg || 'Value contains space!';
});
console.log(
validate('Hello, world!').globalTest().msg()
); // Will print "Value contains space!"
You can register multiple custom validators at once.
vchains = require('vchains');
validate = vchains.validate;
vchains.use({
'globalTest1': function(msg){
if(this.value.indexOf(' ') >= 0) return msg || 'Value contains space!';
},
'globalTest2': function(msg){
if(this.value.indexOf('#') >= 0) return msg || 'Value contains "#"!';
}
});
console.log(
validate('Hello, world! #1').globalTest1().msg(),
validate('Hello, world! #2').globalTest2().msg()
); // Will print "Value contains space! Value contains "#"!"
You can add custom validation method directly from validation chain.
In this case custom method will be accessible only for current validation object.
validate = require('vchains').validate;
console.log(
validate('My string', 'No error :)').use('localTest', function(c, msg){
if(this.value.indexOf(c) >= 0) return msg || 'Error in localTest!';
}).localTest('s').msg()
); // Will print "Error in localTest!"
If the second parameter of vchains.use() is 'true' validator will be accessible from any new validation object.
validate = require('vchains').validate;
console.log(
validate('My string', 'No error :)').use('globalTest', function(msg){
if(this.value.indexOf(c) >= 0) return msg || 'Error in localTest!';
}, true /* !!! */).globalTest().msg(),
validate('Other_string', 'This string does not contains spaces.').globalTest().msg()
); // Will print "Error in localTest! This string does not contains spaces."
You can pass any number of parameters to your custom validator.
Last parameter must be an error message if validation failed.
validate = require('vchains').validate;
console.log(
validate('Short string', 'No error :)').use('parametersTest', function(min, max, msg){
var l = String(this.value).length;
if(min > l || l > max) return msg || 'Error in parametersTest!';
}).parametersTest(0, 32).msg();
); // Will print "Error in parametersTest!"
validate = require('vchains').validate;
validate('123a').onError(function(err){
if(err) console.log('Validation error:', err); else console.log('No error!');
}).isNum('Not numeric string!'); // Will print "Validation error: Not numeric string!"
FAQs
Chaining validators for javascript
We found that vchains 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.