Comparing version 1.0.0 to 1.0.1
20
index.js
@@ -29,10 +29,10 @@ const Joi = require('@hapi/joi'); | ||
password: { | ||
method(options = {}) { | ||
let min = options.min; | ||
let max = options.max; | ||
return this.min(min).max(max).$_addRule({ name: 'password', args: { options } }); | ||
method(rules = {}) { | ||
let min = rules.min; | ||
let max = rules.max; | ||
return this.min(min).max(max).$_addRule({ name: 'password', args: { rules } }); | ||
}, | ||
args: [ | ||
{ | ||
name: 'options', | ||
name: 'rules', | ||
assert: (value) => Object.keys(value).length > 0, | ||
@@ -43,18 +43,18 @@ message: 'must be an object' | ||
validate: (value, helpers, args, options) => { | ||
let opt = args.options; | ||
let rules = args.rules; | ||
let regex = '^'; | ||
let message = 'must contains at least'; | ||
if (opt.lowercase) { | ||
if (rules.lowercase) { | ||
regex += '(?=.*[a-z])'; | ||
message += ' one lowercase character,'; | ||
} | ||
if (opt.uppercase) { | ||
if (rules.uppercase) { | ||
regex += '(?=.*[A-Z])'; | ||
message += ' one uppercase character,'; | ||
} | ||
if (opt.number) { | ||
if (rules.number) { | ||
regex += '(?=.*\\d)'; | ||
message += ' one numeric character,'; | ||
} | ||
if (opt.special) { | ||
if (rules.special) { | ||
regex += '(?=.*[ -/:-@[-`{-~])'; | ||
@@ -61,0 +61,0 @@ message += ' one special character,'; |
{ | ||
"name": "joi-plus", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Joi with extra rules for string and array.", | ||
@@ -5,0 +5,0 @@ "author": "Larry Png", |
5189
89