
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
beyo-model-validation
Advanced tools
Data validation for beyo models.
npm install beyo-model-validation --save
Just require beyo-model-validation
before defining a new model. Requiring this
module is only needed once; not required when defining subsequent models.
var Validation = require('beyo-model-validation').Validation;
var optionsUtils = require('beyo-model-validation').utils.options;
var Model = require('beyo-model');
Validation.define('passwordStrength', function * (model, propertyName, options, translator, next) {
var allowSpecial = optionsUtil.getBoolean(options, 'allowSpecial', true);
var allowWhitespace = optionsUtil.getBoolean(options, 'allowWhitespace', false);
if (/* model._data[propertyName] is valid ? */) {
return yield next;
} else {
return 'Password strength failed';
}
});
var Foo = Model.define('Foo', {
'attributes': {
'id': {
type: 'int',
primary: true,
validation: {
notEmpty: true,
unique: true
}
},
'user': {
type: 'string',
validation: {
notEmpty: true,
email: true
}
},
'pass': {
type: 'string',
validation: {
notEmpty: true,
minLength: 6,
maxLength: 24,
passwordStrength: ['lowercase', 'uppercase', 'digit', 'special']
}
},
'active': {
type: 'boolean',
default: true
}
}
});
var foo = new Foo({ id: 1, user: 'Bob', pass: '1234' });
console.log(yield foo.validate());
// { "user": "Invalid email address",
// "pass": "String must contain at least 6 characters"
// }
NOTE: the order of the declared validation chain is important; validators will be executed in the same order.
NOTE: model.validate()
returns false
if all validation passes. This is to
facilitate checks like var errors = model.validate(); if (errors) { ... }
.
null
or undefined
)Any help welcome! See contribution!
0
, ""
, []
, or {}
)==
).===
).null
.RegExp
object.true
(double equality ==
).undefined
.All contributions welcome! Every PR must be accompanied by their associated unit tests!
The MIT License (MIT)
Copyright (c) 2014 Mind2Soft yanick.rochon@mind2soft.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Data validation for beyo models
We found that beyo-model-validation 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.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.