validity-number-or-null
v0.0.2
Published
Validity style validator to ensure a property is either null or numeric (and not NaN)
Downloads
2
Readme
validity-number-or-null
Validity style validator to ensure a property is either null or numeric (and not NaN
).
Installation
npm install validity-number-or-null
Usage
Below is a simple example for usage with schemata:
var validity = require('validity')
, schemata = require('schemata')
, createValidator = require('validity-number-or-null')
var schema = schemata(
{ waitTime:
{ type: Number
, validators: { all: [ createValidator() ] }
}
})
schema.validate({ waitTime: 30 }, function (error, errorMessage) {
console.log(errorMessage) //-> undefined
})
schema.validate({ waitTime: null }, function (error, errorMessage) {
console.log(errorMessage) //-> undefined
})
schema.validate({ waitTime: 'abc' }, function (error, errorMessage) {
console.log(errorMessage) //-> 'Wait time must be a number if present'
})
API
var validate = createValidator()
validate(String:key, String:keyDisplayName, Object:object, Function:cb)
This is a validity compatible function, which in turn is used by schemata for schema validation.
The callback signature cb(err, errorMessage)
.
err
is anError
object if something bad happened andnull
otherwise.errorMessage
is aString
if a validation error happened andundefined
otherwise.
Licence
Licensed under the New BSD License