1.2.7 • Published 4 years ago

@studiowebux/validator v1.2.7

Weekly downloads
2
License
SEE LICENSE IN li...
Repository
github
Last release
4 years ago

Webux Validator

This module is a wrapper around the Joi module.

Installation

Linux

npm i --save @studiowebux/validator

Windows

npm i --save @studiowebux/validator

Mac

npm i --save @studiowebux/validator

Usage

Available validators

Body (req.body)

Body(Schema)(req, res, next)=>{...};

MongoID (req.params.id)

MongoID(Schema)(req, res, next)=>{...};

MongoIdOrURL (req.params.id_url)

MongoIdOrURL(Schema)(req, res, next)=>{...};

User (req.user)

User(Schema)(req, res, next)=>{...};

Headers (req.headers)

Headers(Schema)(req, res, next)=>{...};

Files (req.files)

Files(Schema)(req, res, next)=>{...};

Custom (object)

Custom(Schema, object);

Usage

validator

To get more information about validator, please consult the Joi documentation,
Inside the validators directory,

validators/language.js

A schema exemple for Create and MongoID,

const Joi = require("joi");

const Create = Joi.object().keys({
  language: {
    name: Joi.string().required(),
    shortcuts: Joi.array()
      .items(Joi.string())
      .required(),
    defaultValue: Joi.boolean().required()
  }
});

const MongoID = Joi.string()
  .regex(/^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/i)
  .required();

module.exports = {
  Create,
  MongoID
};

example

Check the /examples directory.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

SEE LICENSE IN license.txt

1.2.7

4 years ago

1.2.6

5 years ago