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 - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

libraries/alpha-2.json

106

index.js

@@ -0,101 +1,7 @@

'use strict';
const Joi = require('@hapi/joi');
module.exports = Joi.extend((joi) => {
return {
type: 'string',
base: joi.string(),
messages: {
'string.numeric': '"{{#label}}" must only contain numeric characters',
'string.clean': '"{{#label}}" contains illegal characters: \\ > < } { `',
'string.password': '"{{#label}}" {{#message}}'
},
rules: {
numeric: {
validate: (value, helpers, args, options) => {
if (/^[0-9]+$/.test(value)) {
return value;
}
return helpers.error('string.numeric');
}
},
clean: {
validate: (value, helpers, args, options) => {
if (/^[^<>{}\\\`]+$/.test(value)) {
return value;
}
return helpers.error('string.clean');
}
},
password: {
method(rules = {}) {
let min = rules.min;
let max = rules.max;
return this.min(min).max(max).$_addRule({ name: 'password', args: { rules } });
},
args: [
{
name: 'rules',
assert: (value) => Object.keys(value).length > 0,
message: 'must be an object'
}
],
validate: (value, helpers, args, options) => {
let rules = args.rules;
let regex = '^';
let message = 'must contains at least';
if (rules.lowercase) {
regex += '(?=.*[a-z])';
message += ' one lowercase character,';
}
if (rules.uppercase) {
regex += '(?=.*[A-Z])';
message += ' one uppercase character,';
}
if (rules.number) {
regex += '(?=.*\\d)';
message += ' one numeric character,';
}
if (rules.special) {
regex += '(?=.*[ -/:-@[-`{-~])';
message += ' one special character,';
}
regex += '.*$';
message = message.slice(0, -1);
regex = new RegExp(regex);
if (!regex.test(value)) {
return helpers.error('string.password', { message });
}
if (!/^.*[ -~]$/.test(value)) {
return helpers.error('string.password', { message: 'contains illegal characters' });
}
return value;
}
},
match: {
method(reference) {
return this.valid(joi.ref(reference)).prefs({
messages: {
'any.only': `"{{#label}}" must match "${reference}"`
}
}).strip();
}
}
}
}
}, (joi) => {
return {
type: 'array',
base: joi.array(),
rules: {
inList: {
method(list, label) {
let schema = joi.any().valid(...list);
if (label) {
return this.unique().items(schema.label(label));
}
return this.unique().items(schema);
}
}
}
}
});
module.exports = Joi.extend(
require('./libraries/string'),
require('./libraries/array')
);
{
"name": "joi-plus",
"version": "1.0.8",
"version": "1.1.0",
"description": "Joi with extra rules for string and array.",

@@ -10,3 +10,3 @@ "repository": "git://github.com/flamehamster/joi-plus",

"dependencies": {
"@hapi/joi": "^16.1.7"
"@hapi/joi": "^16.1.8"
},

@@ -19,3 +19,7 @@ "keywords": [

"password",
"clean",
"escape",
"sanitize",
"country",
"iso 3166",
"country code",
"match",

@@ -22,0 +26,0 @@ "array"

# Joi-Plus
[@hapi/joi - v16.1.7](https://www.npmjs.com/package/@hapi/joi)
[@hapi/joi - v16.1.8](https://www.npmjs.com/package/@hapi/joi)
Making the most powerful schema description language and data validator for JavaScript slightly more powerful.

@@ -8,5 +8,14 @@

* 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)

@@ -58,2 +67,6 @@ -- Requires the string value to match rules.

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

@@ -73,22 +86,25 @@ .min(2)

* `email`
* a required string
* a valid email address string
* 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_ ! " # $ % & ' ( ) * + , - . : ; < = > ? @ [ \ ] ^ _ ` { | } ~
* 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
* 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 120
* must contain only numeric characters
* 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]
* a required array
* must be one of [dog, cat, lion, tiger, elephant, hippo]
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