Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

joi-plus

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-plus

Joi with extra rules for string and array.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
45
decreased by-48.28%
Maintainers
1
Weekly downloads
 
Created
Source

Joi-Plus

@hapi/joi - v16.1.8 Making the most powerful schema description language and data validator for JavaScript slightly more powerful.

Introduction

  • Joi.string().escape() -- replace <, >, &, ', ", / and \ with HTML entities.

  • Joi.string().numeric() -- Requires the string value to only contain 0-9.

  • Joi.string().base32() -- Requires the value to be a valid base32 string.

  • Joi.string().countryCode(type) -- Requires the value to be a valid ISO alpha-2 or ISO alpha-3 country code.

  • Joi.string().password(rules) -- Requires the string value to match rules.

  • Joi.string().match(reference) -- Requires the string value to match the reference. -- Removed after validation.

  • Joi.array().inList(list, [label]) -- Requires the value in array to match the list. -- Overrides the key name for value in error messages.

Quick Start

Installation

$ npm i joi-plus

Initialization

const Joi = require('joi-plus');

Usage

const schema = Joi.object({
	email: Joi.string()
		.email()
		.required(),

	password: Joi.string()
		.password({
			min: 8,
			max: 120,
			lowercase: true,
			uppercase: true,
			number: true,
			special: true
		})
		.required(),

	repeat_password: Joi.string()
		.match('password')
		.required(),

	country: Joi.string()
		.countryCode('alpha-2')
		.required(),

	contact_number: Joi.string()
		.min(2)
		.max(20)
		.numeric()
		.required(),

	fav_animals: Joi.array()
		.inList(['dog', 'cat', 'lion', 'tiger', 'elephant', 'hippo'], 'animals')
		.required()
})

The above schema defines the following constraints:

  • email
    • a required string
    • a valid email address string
  • password
    • a required string
    • at least 8 characters long but no more than 120
    • must contains at least one lowercase character
    • must contains at least one uppercase character
    • must contains at least one numeric character
    • must contains at least one special character
      • space ! " # $ % & ' ( ) * + , - . : ; < = > ? @ [ \ ] ^ _ ` { | } ~
  • repeat_password
    • a required string
    • must match password
    • will be removed after validation
  • country
    • a required string
    • must be a valid ISO 'alpha-2' country code
  • contact_number
    • a required string
    • at least 8 characters long but no more than 20
    • must contain only numeric characters
  • fav_animals
    • a required array
    • must be one of [dog, cat, lion, tiger, elephant, hippo]

Keywords

FAQs

Package last updated on 05 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc