indicative
Advanced tools
Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "indicative", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Intentionally beautiful schema and raw validator for nodejs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,2 +16,9 @@ 'use strict' | ||
/** | ||
* modes supported by indicative | ||
* @type {Array} | ||
*/ | ||
const modes = ['normal', 'string strict'] | ||
let currentMode = 'normal' | ||
/** | ||
* @module Validator | ||
@@ -53,2 +60,3 @@ * @description Validator to run through an object | ||
} | ||
Validator.transformFieldValue(data, field) | ||
return Validations[convertedValidation](data, field, message, validationRules[validation].args, dotProp.get) | ||
@@ -77,2 +85,18 @@ .catch(function (message) { | ||
/** | ||
* @description sets field value to null when current field is empty | ||
* and when currentMode is set to string strict | ||
* @param {Object} data | ||
* @param {String} field | ||
* @return {void} | ||
*/ | ||
Validator.transformFieldValue = function (data, field) { | ||
if(currentMode === 'string strict') { | ||
const value = dotProp.get(data, field) | ||
if(typeof(value) === 'string' && value.length === 0){ | ||
dotProp.set(data, field, null) | ||
} | ||
} | ||
} | ||
/** | ||
* @description validates an object of rules by parsing | ||
@@ -153,2 +177,16 @@ * rules and custom messages.It is a very high level | ||
/** | ||
* @description setting up validation mode for indicative | ||
* @method setMode | ||
* @param {String} mode | ||
* @public | ||
*/ | ||
Validator.setMode = function (mode) { | ||
if(modes.indexOf(mode) <= -1) { | ||
console.log(`indicative: ${mode} is not a valid mode, switching back to normal mode`) | ||
return | ||
} | ||
currentMode = mode | ||
} | ||
/** | ||
* attaching raw validator | ||
@@ -155,0 +193,0 @@ * @type {Object} |
59965
2254