1.0.6 • Published 7 years ago
@yapsody/generic-validations v1.0.6
@yapsody/generic-validations
Generic validations built on top of Joi
Installation
npm i @yapsody/generic-validations --saveUsage
// require the entire library
const genericValidations = require('@yapsody/generic-validation');
// or require individual components
const { string, number, date } = require('@yapsody/generic-validations')
// using a validation to validate something
const { error, result } = genericValidations.number.positive.validate(1); // Success
const { error, result } = genericValidations.number.positive.validate('abc'); // ErrorAvailable Validations
date
| Validation | Usage | Description |
|---|---|---|
| timestamp | date.timestamp.validate('2019-04-11T11:46:22.560Z') | Check for a valid iso date time string |
| iso | date.iso.validate('2019-04-19T09:09:40.826Z') | Check for a valid iso date time string |
| isoWithNull | date.isoWithNull.validate('2019-04-19T09:09:40.826Z') | Check for a valid iso date time string. Allow null value |
number
| Validation | Usage | Description |
|---|---|---|
| integer | number.integer.validate('123') | Check for a valid integer number |
| positive | number.positive.validate('123') | Check for a valid positive integer number |
| precision | number.precision.validate('123') | Check for a valid number with precision upto 3 decimal |
string
| Validation | Usage | Description |
|---|---|---|
| small | string.small.validate('2019-04-11T11:46:22.560Z') | Check for a string with length between 3 to 255 |
| medium | string.medium.validate('2019-04-11T11:46:22.560Z') | Check for a string with length between 3 to 1000 |
Changelog
See the changelog page on Gitlab.