feathers-hooks-validate-joi
Feathers hook utility for schema validation and sanitization using Joi. Joi error messages are converted to web/mobile friendly formats, and optionally translated for clarity or internationalization.
Code Example
const Joi = ;const validate = ; const name = Joi ;const password = Joi;const schema = Joiobject;const joiOptions = convert: true abortEarly: false ;
(1) Validate sanitize data. The client receives any errors in a format suitable for forms which also seems to be recommend by Feathers.
;
(2) Errors are returned in a Mongoose format.
;
(3) Internationalize or clarify Joi error messages.
{ return str; } // internationalization const translations = { }; ;
Note: Data values in the $set
operator are not validated.
You could use joi-errors-for-forms
for that.
Motivation
Data must be validated and sanitized before the database is changed. The client must be informed of any errors using a schema friendly to web/mobile apps.
This repo helps implement this in Feathers CRUD hooks.
Installation
Install Nodejs.
Run npm install feathers-hooks-validate-joi --save
in your project folder.
You can then require the utilities.
API Reference
To do.
Tests
npm test
to run tests.
npm run cover
to run tests plus coverage.
A Note on Internationalization
The options
in Joi.validate(value, schema, options, cb)
supports a
language
option
with which you can change
Joi error messages
in bulk.
You can then internationalize your field names and regex descriptions in the schema, e.g.
Joilabel
These are suitable methods to internationalize the majority of Joi error messages.
Contributors
License
MIT. See LICENSE.