feathers-hooks-yup
Feathers hook utility for schema validation and sanitization using Yup. Error messages are converted to web/mobile friendly formats, and optionally translated for clarity or internationalization.
Supports both JS and Typescript.
The reason I decided to do this, because I found that using Yup clientside with react is the recommended approach. but I did not want to rewrite the rules in JOI or any other validation framework that are already available. this hook allows me to simply share the validations from the clientside.
Code Example
;;; const yupSchema = Yupobject email: Yup retypeEmail: Yup password: Yup acceptedTerms: Yup ;;
;;const yupOptions = abortEarly: false;;
(3) Internationalize or clarify Joi error messages.
Translation method example:
//some translating logic... { return str; } // internationalizationconst translationMethod = { forconst errorKey in formattedErrors formattedErrorserrorKey = ; return formattedErrors; } ;
Motivation
Installation
Install Nodejs.
Run npm install feathers-hooks-yup --save
in your project folder.
or
Run yarn add feathers-hooks-yup
in your project folder.
You can then require the utilities.
API Reference
To do.
Tests
To do.
npm test
to run tests.
npm run cover
to run tests plus coverage.
Contributors
Credit
- logicwind for taking their readme as an example, and for the inspiration to set up this package.
License
MIT. See LICENSE.