elvalidator
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -7,2 +7,6 @@ # Changelog | ||
## [1.2.0] - 2022-03-06 | ||
### Changed | ||
- Renamed minlength and maxlength options to minLength and maxLength to match mongoose's schema. | ||
## [1.1.0] - 2022-03-06 | ||
@@ -9,0 +13,0 @@ ### Fixed |
@@ -6,3 +6,3 @@ //import ElValidator from 'elvalidator'; | ||
let validator = new ElValidator({ | ||
name : { type: String, required:true, trim:true, minlength:3 }, | ||
name : { type: String, required:true, trim:true, minLength:3 }, | ||
age : { type: Number, required:true, integer:true, min:18, max:100 }, | ||
@@ -13,3 +13,3 @@ agreedTelemetry : { type: Boolean, default:false }, | ||
tags : [ | ||
{ type: String, minlength:3, lowercase:true, trim:true, match: /^[a-z0-9]+$/ } | ||
{ type: String, minLength:3, lowercase:true, trim:true, match: /^[a-z0-9]+$/ } | ||
], | ||
@@ -31,3 +31,3 @@ | ||
type : [ | ||
{ type: String, minlength:3, lowercase:true, trim:true, match: /^[a-z0-9]+$/ } | ||
{ type: String, minLength:3, lowercase:true, trim:true, match: /^[a-z0-9]+$/ } | ||
], | ||
@@ -34,0 +34,0 @@ minEntries : 0, |
@@ -27,6 +27,6 @@ | ||
let sanitized = await ElValidator.validate(req.body, { | ||
name : { type: String, required: true, minlength:3 }, | ||
name : { type: String, required: true, minLength:3 }, | ||
tags : [ | ||
{ type: String, required:true, lowercase:true, minlength:2, match:/[a-z0-9_]+/ } | ||
{ type: String, required:true, lowercase:true, minLength:2, match:/[a-z0-9_]+/ } | ||
], | ||
}) |
18
index.js
@@ -59,6 +59,6 @@ | ||
} else if(schema[k].type===String) { | ||
if(ElValidator.hasOwnProperty(schema_, 'maxlength')) | ||
schema[k].maxlength = parseInt(schema_.maxlength) || 0; | ||
if(ElValidator.hasOwnProperty(schema_, 'maxlength')) | ||
schema[k].maxlength = parseInt(schema_.maxlength) || 0; | ||
if(ElValidator.hasOwnProperty(schema_, 'maxLength')) | ||
schema[k].maxLength = parseInt(schema_.maxLength) || 0; | ||
if(ElValidator.hasOwnProperty(schema_, 'maxLength')) | ||
schema[k].maxLength = parseInt(schema_.maxLength) || 0; | ||
@@ -148,11 +148,11 @@ if(ElValidator.hasOwnProperty(schema_, 'lowercase')) | ||
if(ElValidator.hasOwnProperty(schema, 'maxlength') && fieldVal.length>schema.maxlength) { | ||
if(ElValidator.hasOwnProperty(schema, 'maxLength') && fieldVal.length>schema.maxLength) { | ||
if(!this.options.strictMode) { | ||
fieldVal = fieldVal.subString(0, schema.maxlength); | ||
fieldVal = fieldVal.subString(0, schema.maxLength); | ||
} else { | ||
this._error('The "'+fieldName+'" field must be at most '+ schema.maxlength +' characters long.'); | ||
this._error('The "'+fieldName+'" field must be at most '+ schema.maxLength +' characters long.'); | ||
} | ||
} | ||
if(ElValidator.hasOwnProperty(schema, 'minlength') && fieldVal.length>schema.minlength) { | ||
this._error('The "'+fieldName+'" field must be at least '+ schema.minlength +' characters long.'); | ||
if(ElValidator.hasOwnProperty(schema, 'minLength') && fieldVal.length<schema.minLength) { | ||
this._error('The "'+fieldName+'" field must be at least '+ schema.minLength +' characters long.'); | ||
} | ||
@@ -159,0 +159,0 @@ if(ElValidator.hasOwnProperty(schema, 'enum') && !schema.enum.includes(fieldVal)) { |
{ | ||
"name": "elvalidator", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Validate and Sanitize JSON objects.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -99,4 +99,4 @@ # El Validator | ||
trim : false, // Trim text (remove whitespace at the start and end of the string) | ||
minlength : 3, // Minimum length of the string | ||
maxlength : 15, // Maximum length of the string | ||
minLength : 3, // Minimum length of the string | ||
maxLength : 15, // Maximum length of the string | ||
enum : ['hello', 'world'], // Array with valid values for this field | ||
@@ -103,0 +103,0 @@ match : /^(hello|world)$/i, // String must match with this regex |
40368