Comparing version 2.0.0 to 2.0.1
@@ -1,1 +0,1 @@ | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){"use strict";var LIVR={rules:{}};LIVR.rules.common=require("./LIVR/Rules/Common");LIVR.rules.string=require("./LIVR/Rules/String");LIVR.rules.numeric=require("./LIVR/Rules/Numeric");LIVR.rules.special=require("./LIVR/Rules/Special");LIVR.rules.meta=require("./LIVR/Rules/Meta");LIVR.rules.modifiers=require("./LIVR/Rules/Modifiers");LIVR.Validator=require("./LIVR/Validator");LIVR.util=require("./LIVR/util");LIVR.Validator.registerDefaultRules({required:LIVR.rules.common.required,not_empty:LIVR.rules.common.not_empty,not_empty_list:LIVR.rules.common.not_empty_list,any_object:LIVR.rules.common.any_object,string:LIVR.rules.string.string,eq:LIVR.rules.string.eq,one_of:LIVR.rules.string.one_of,max_length:LIVR.rules.string.max_length,min_length:LIVR.rules.string.min_length,length_equal:LIVR.rules.string.length_equal,length_between:LIVR.rules.string.length_between,like:LIVR.rules.string.like,integer:LIVR.rules.numeric.integer,positive_integer:LIVR.rules.numeric.positive_integer,decimal:LIVR.rules.numeric.decimal,positive_decimal:LIVR.rules.numeric.positive_decimal,max_number:LIVR.rules.numeric.max_number,min_number:LIVR.rules.numeric.min_number,number_between:LIVR.rules.numeric.number_between,email:LIVR.rules.special.email,equal_to_field:LIVR.rules.special.equal_to_field,url:LIVR.rules.special.url,iso_date:LIVR.rules.special.iso_date,nested_object:LIVR.rules.meta.nested_object,variable_object:LIVR.rules.meta.variable_object,list_of:LIVR.rules.meta.list_of,list_of_objects:LIVR.rules.meta.list_of_objects,or:LIVR.rules.meta.or,list_of_different_objects:LIVR.rules.meta.list_of_different_objects,"default":LIVR.rules.modifiers.default,trim:LIVR.rules.modifiers.trim,to_lc:LIVR.rules.modifiers.to_lc,to_uc:LIVR.rules.modifiers.to_uc,remove:LIVR.rules.modifiers.remove,leave_only:LIVR.rules.modifiers.leave_only});module.exports=LIVR},{"./LIVR/Rules/Common":2,"./LIVR/Rules/Meta":3,"./LIVR/Rules/Modifiers":4,"./LIVR/Rules/Numeric":5,"./LIVR/Rules/Special":6,"./LIVR/Rules/String":7,"./LIVR/Validator":8,"./LIVR/util":9}],2:[function(require,module,exports){"use strict";var util=require("../util");module.exports={required:function(){return function(value){if(util.isNoValue(value)){return"REQUIRED"}return}},not_empty:function(){return function(value){if(value!==null&&value!==undefined&&value===""){return"CANNOT_BE_EMPTY"}return}},not_empty_list:function(){return function(list){if(list===undefined||list==="")return"CANNOT_BE_EMPTY";if(!Array.isArray(list))return"FORMAT_ERROR";if(list.length<1)return"CANNOT_BE_EMPTY";return}},any_object:function(){return function(value){if(util.isNoValue(value))return;if(!util.isObject(value)){return"FORMAT_ERROR"}}}}},{"../util":9}],3:[function(require,module,exports){"use strict";var Validator=require("../Validator");var util=require("../util");module.exports={nested_object:function(livr,ruleBuilders){var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(nestedObject,params,outputArr){if(util.isNoValue(nestedObject))return;if(!util.isObject(nestedObject))return"FORMAT_ERROR";var result=validator.validate(nestedObject);if(result){outputArr.push(result);return}else{return validator.getErrors()}}},variable_object:function(selectorField,livrs,ruleBuilders){var validators={};for(var selectorValue in livrs){var validator=new Validator(livrs[selectorValue]).registerRules(ruleBuilders).prepare();validators[selectorValue]=validator}return function(object,params,outputArr){if(util.isNoValue(object))return;if(!util.isObject(object)||!object[selectorField]||!validators[object[selectorField]]){return"FORMAT_ERROR"}var validator=validators[object[selectorField]];var result=validator.validate(object);if(result){outputArr.push(result);return}else{return validator.getErrors()}}},list_of:function(rules,ruleBuilders){if(!Array.isArray(rules)){rules=Array.prototype.slice.call(arguments);ruleBuilders=rules.pop()}var livr={field:rules};var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(values,params,outputArr){if(util.isNoValue(values))return;if(!Array.isArray(values))return"FORMAT_ERROR";var results=[];var errors=[];var hasErrors=false;for(var i=0;i<values.length;i++){var result=validator.validate({field:values[i]});if(result){results.push(result.field);errors.push(null)}else{hasErrors=true;errors.push(validator.getErrors().field);results.push(null)}}if(hasErrors){return errors}else{outputArr.push(results);return}}},list_of_objects:function(livr,ruleBuilders){var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(objects,params,outputArr){if(util.isNoValue(objects))return;if(!Array.isArray(objects))return"FORMAT_ERROR";var results=[];var errors=[];var hasErrors=false;for(var i=0;i<objects.length;i++){var result=validator.validate(objects[i]);if(result){results.push(result);errors.push(null)}else{hasErrors=true;errors.push(validator.getErrors());results.push(null)}}if(hasErrors){return errors}else{outputArr.push(results);return}}},list_of_different_objects:function(selectorField,livrs,ruleBuilders){var validators={};for(var selectorValue in livrs){var validator=new Validator(livrs[selectorValue]).registerRules(ruleBuilders).prepare();validators[selectorValue]=validator}return function(objects,params,outputArr){if(util.isNoValue(objects))return;if(!Array.isArray(objects))return"FORMAT_ERROR";var results=[];var errors=[];var hasErrors=false;for(var i=0;i<objects.length;i++){var object=objects[i];if(typeof object!="object"||!object[selectorField]||!validators[object[selectorField]]){errors.push("FORMAT_ERROR");continue}var validator=validators[object[selectorField]];var result=validator.validate(object);if(result){results.push(result);errors.push(null)}else{hasErrors=true;errors.push(validator.getErrors());results.push(null)}}if(hasErrors){return errors}else{outputArr.push(results);return}}},or:function(){var ruleSets=Array.prototype.slice.call(arguments);var ruleBuilders=ruleSets.pop();var validators=ruleSets.map(function(rules){var livr={field:rules};var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return validator});return function(value,params,outputArr){if(util.isNoValue(value))return;var lastError;for(var i=0;i<validators.length;i++){var validator=validators[i];var result=validator.validate({field:value});if(result){outputArr.push(result.field);return}else{lastError=validator.getErrors().field}}if(lastError){return lastError}}}}},{"../Validator":8,"../util":9}],4:[function(require,module,exports){"use strict";var util=require("../util");module.exports={"default":function(defaulValue){return function(value,params,outputArr){if(util.isNoValue(value)){outputArr.push(defaulValue)}}},trim:function(){return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.replace(/^\s*/,"").replace(/\s*$/,""))}},to_lc:function(){return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.toLowerCase())}},to_uc:function(){return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.toUpperCase())}},remove:function(chars){chars=util.escapeRegExp(chars);var re=new RegExp("["+chars+"]","g");return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.replace(re,""))}},leave_only:function(chars){chars=util.escapeRegExp(chars);var re=new RegExp("[^"+chars+"]","g");return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.replace(re,""))}}}},{"../util":9}],5:[function(require,module,exports){"use strict";var util=require("../util");module.exports={integer:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_INTEGER";if(!Number.isInteger(+value))return"NOT_INTEGER";outputArr.push(+value)}},positive_integer:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_POSITIVE_INTEGER";if(!Number.isInteger(+value)||+value<1)return"NOT_POSITIVE_INTEGER";outputArr.push(+value)}},decimal:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_DECIMAL";value+="";if(!/^(?:\-?(?:[0-9]+\.[0-9]+)|(?:[0-9]+))$/.test(value))return"NOT_DECIMAL";outputArr.push(+value)}},positive_decimal:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_POSITIVE_DECIMAL";value+="";if(!/^(?:(?:[0-9]*\.[0-9]+)|(?:[1-9][0-9]*))$/.test(value))return"NOT_POSITIVE_DECIMAL";outputArr.push(+value)}},max_number:function(maxNumber){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_NUMBER";if(+value>+maxNumber)return"TOO_HIGH";outputArr.push(+value)}},min_number:function(minNumber){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_NUMBER";if(+value<+minNumber)return"TOO_LOW";outputArr.push(+value)}},number_between:function(minNumber,maxNumber){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_NUMBER";if(+value<+minNumber)return"TOO_LOW";if(+value>+maxNumber)return"TOO_HIGH";outputArr.push(+value)}}}},{"../util":9}],6:[function(require,module,exports){"use strict";var util=require("../util");module.exports={email:function(){var emailRe=/^([\w\-_+]+(?:\.[\w\-_+]+)*)@((?:[\w\-]+\.)*\w[\w\-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return function(value){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(!emailRe.test(value))return"WRONG_EMAIL";if(/\@.*\@/.test(value))return"WRONG_EMAIL";if(/\@.*_/.test(value))return"WRONG_EMAIL";return}},equal_to_field:function(field){return function(value,params){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(value!=params[field])return"FIELDS_NOT_EQUAL";return}},url:function(){var urlReStr="^(?:(?:http|https)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[0-1]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))\\.?|localhost)(?::\\d{2,5})?(?:[/?#]\\S*)?$";var urlRe=new RegExp(urlReStr,"i");return function(value){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(value.length<2083&&urlRe.test(value))return;return"WRONG_URL"}},iso_date:function(){return function(value){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";var matched=value.match(/^(\d{4})-([0-1][0-9])-([0-3][0-9])$/);if(matched){var epoch=Date.parse(value);if(!epoch&&epoch!==0)return"WRONG_DATE";var d=new Date(epoch);d.setTime(d.getTime()+d.getTimezoneOffset()*60*1e3);if(d.getFullYear()==matched[1]&&d.getMonth()+1==+matched[2]&&d.getDate()==+matched[3]){return}}return"WRONG_DATE"}}}},{"../util":9}],7:[function(require,module,exports){"use strict";var util=require("../util");module.exports={string:function(){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";outputArr.push(value+"");return}},eq:function(allowedValue){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(value+""===allowedValue+""){outputArr.push(allowedValue);return}return"NOT_ALLOWED_VALUE"}},one_of:function(allowedValues){if(!Array.isArray(allowedValues)){allowedValues=Array.prototype.slice.call(arguments);allowedValues.pop()}return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";for(var i=0;i<allowedValues.length;i++){if(value+""===allowedValues[i]+""){outputArr.push(allowedValues[i]);return}}return"NOT_ALLOWED_VALUE"}},max_length:function(maxLength){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length>maxLength)return"TOO_LONG";outputArr.push(value)}},min_length:function(minLength){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length<minLength)return"TOO_SHORT";outputArr.push(value)}},length_equal:function(length){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length<length)return"TOO_SHORT";if(value.length>length)return"TOO_LONG";outputArr.push(value)}},length_between:function(minLength,maxLength){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length<minLength)return"TOO_SHORT";if(value.length>maxLength)return"TOO_LONG";outputArr.push(value)}},like:function(reStr,flags){var isIgnoreCase=arguments.length===3&&flags.match("i");var re=new RegExp(reStr,isIgnoreCase?"i":"");return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(!value.match(re))return"WRONG_FORMAT";outputArr.push(value)}}}},{"../util":9}],8:[function(require,module,exports){"use strict";var util=require("./util");var DEFAULT_RULES={};var IS_DEFAULT_AUTO_TRIM=0;function Validator(livrRules,isAutoTrim){this.isPrepared=false;this.livrRules=livrRules;this.validators={};this.validatorBuilders={};this.errors=null;if(isAutoTrim!==null&&isAutoTrim!==undefined){this.isAutoTrim=isAutoTrim}else{this.isAutoTrim=IS_DEFAULT_AUTO_TRIM}this.registerRules(DEFAULT_RULES)}Validator.registerDefaultRules=function(rules){for(var ruleName in rules){DEFAULT_RULES[ruleName]=rules[ruleName]}};Validator.getDefaultRules=function(){return DEFAULT_RULES};Validator.registerAliasedDefaultRule=function(alias){if(!alias.name)throw"Alias name required";DEFAULT_RULES[alias.name]=Validator._buildAliasedRule(alias)};Validator._buildAliasedRule=function(alias){if(!alias.name)throw"Alias name required";if(!alias.rules)throw"Alias rules required";var livr={value:alias.rules};return function(ruleBuilders){var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(value,params,outputArr){var result=validator.validate({value:value});if(result){outputArr.push(result.value);return}else{return alias.error||validator.getErrors().value}}}};Validator.defaultAutoTrim=function(isAutoTrim){IS_DEFAULT_AUTO_TRIM=!!isAutoTrim};Validator.prototype={prepare:function(){var allRules=this.livrRules;for(var field in allRules){var fieldRules=allRules[field];if(!Array.isArray(fieldRules)){fieldRules=[fieldRules]}var validators=[];for(var i=0;i<fieldRules.length;i++){var parsed=this._parseRule(fieldRules[i]);validators.push(this._buildValidator(parsed.name,parsed.args))}this.validators[field]=validators}this.isPrepared=true;return this},validate:function(data){if(!this.isPrepared)this.prepare();if(!util.isObject(data)){this.errors="FORMAT_ERROR";return}if(this.isAutoTrim){data=this._autoTrim(data)}var errors={},result={};for(var fieldName in this.validators){var validators=this.validators[fieldName];if(!validators||!validators.length)continue;var value=data[fieldName];for(var i=0;i<validators.length;i++){var fieldResultArr=[];var errCode=validators[i](result.hasOwnProperty(fieldName)?result[fieldName]:value,data,fieldResultArr);if(errCode){errors[fieldName]=errCode;break}else if(fieldResultArr.length){result[fieldName]=fieldResultArr[0]}else if(data.hasOwnProperty(fieldName)&&!result.hasOwnProperty(fieldName)){result[fieldName]=value}}}if(util.isEmptyObject(errors)){this.errors=null;return result}else{this.errors=errors;return false}},getErrors:function(){return this.errors},registerRules:function(rules){for(var ruleName in rules){this.validatorBuilders[ruleName]=rules[ruleName]}return this},registerAliasedRule:function(alias){if(!alias.name)throw"Alias name required";this.validatorBuilders[alias.name]=Validator._buildAliasedRule(alias);return this},getRules:function(){return this.validatorBuilders},_parseRule:function(livrRule){var name,args;if(util.isObject(livrRule)){name=Object.keys(livrRule)[0];args=livrRule[name];if(!Array.isArray(args))args=[args]}else{name=livrRule;args=[]}return{name:name,args:args}},_buildValidator:function(name,args){if(!this.validatorBuilders[name]){throw"Rule ["+name+"] not registered"}var allArgs=[];allArgs.push.apply(allArgs,args);allArgs.push(this.getRules());return this.validatorBuilders[name].apply(null,allArgs)},_autoTrim:function(data){var dataType=typeof data;if(dataType!=="object"&&data){if(data.replace){return data.replace(/^\s*/,"").replace(/\s*$/,"")}else{return data}}else if(dataType=="object"&&Array.isArray(data)){var trimmedData=[];for(var i=0;i<data.length;i++){trimmedData[i]=this._autoTrim(data[i])}return trimmedData}else if(dataType=="object"&&util.isObject(data)){var trimmedData={};for(var key in data){if(data.hasOwnProperty(key)){trimmedData[key]=this._autoTrim(data[key])}}return trimmedData}return data}};module.exports=Validator},{"./util":9}],9:[function(require,module,exports){"use strict";module.exports={isPrimitiveValue:function(value){if(typeof value=="string")return true;if(typeof value=="number"&&isFinite(value))return true;if(typeof value=="boolean")return true;return false},looksLikeNumber:function(value){if(!isNaN(+value))return true;return false},isObject:function(obj){return Object(obj)===obj&&Object.getPrototypeOf(obj)===Object.prototype},isEmptyObject:function(map){for(var key in map){if(map.hasOwnProperty(key)){return false}}return true},escapeRegExp:function(str){return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isNoValue:function(value){return value===undefined||value===null||value===""}}},{}],10:[function(require,module,exports){window.LIVR=require("../lib/LIVR")},{"../lib/LIVR":1}]},{},[10]); | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){"use strict";var LIVR={rules:{}};LIVR.rules.common=require("./LIVR/Rules/Common");LIVR.rules.string=require("./LIVR/Rules/String");LIVR.rules.numeric=require("./LIVR/Rules/Numeric");LIVR.rules.special=require("./LIVR/Rules/Special");LIVR.rules.meta=require("./LIVR/Rules/Meta");LIVR.rules.modifiers=require("./LIVR/Rules/Modifiers");LIVR.Validator=require("./LIVR/Validator");LIVR.util=require("./LIVR/util");LIVR.Validator.registerDefaultRules({required:LIVR.rules.common.required,not_empty:LIVR.rules.common.not_empty,not_empty_list:LIVR.rules.common.not_empty_list,any_object:LIVR.rules.common.any_object,string:LIVR.rules.string.string,eq:LIVR.rules.string.eq,one_of:LIVR.rules.string.one_of,max_length:LIVR.rules.string.max_length,min_length:LIVR.rules.string.min_length,length_equal:LIVR.rules.string.length_equal,length_between:LIVR.rules.string.length_between,like:LIVR.rules.string.like,integer:LIVR.rules.numeric.integer,positive_integer:LIVR.rules.numeric.positive_integer,decimal:LIVR.rules.numeric.decimal,positive_decimal:LIVR.rules.numeric.positive_decimal,max_number:LIVR.rules.numeric.max_number,min_number:LIVR.rules.numeric.min_number,number_between:LIVR.rules.numeric.number_between,email:LIVR.rules.special.email,equal_to_field:LIVR.rules.special.equal_to_field,url:LIVR.rules.special.url,iso_date:LIVR.rules.special.iso_date,nested_object:LIVR.rules.meta.nested_object,variable_object:LIVR.rules.meta.variable_object,list_of:LIVR.rules.meta.list_of,list_of_objects:LIVR.rules.meta.list_of_objects,or:LIVR.rules.meta.or,list_of_different_objects:LIVR.rules.meta.list_of_different_objects,default:LIVR.rules.modifiers.default,trim:LIVR.rules.modifiers.trim,to_lc:LIVR.rules.modifiers.to_lc,to_uc:LIVR.rules.modifiers.to_uc,remove:LIVR.rules.modifiers.remove,leave_only:LIVR.rules.modifiers.leave_only});module.exports=LIVR},{"./LIVR/Rules/Common":2,"./LIVR/Rules/Meta":3,"./LIVR/Rules/Modifiers":4,"./LIVR/Rules/Numeric":5,"./LIVR/Rules/Special":6,"./LIVR/Rules/String":7,"./LIVR/Validator":8,"./LIVR/util":9}],2:[function(require,module,exports){"use strict";var util=require("../util");module.exports={required:function(){return function(value){if(util.isNoValue(value)){return"REQUIRED"}return}},not_empty:function(){return function(value){if(value!==null&&value!==undefined&&value===""){return"CANNOT_BE_EMPTY"}return}},not_empty_list:function(){return function(list){if(list===undefined||list==="")return"CANNOT_BE_EMPTY";if(!Array.isArray(list))return"FORMAT_ERROR";if(list.length<1)return"CANNOT_BE_EMPTY";return}},any_object:function(){return function(value){if(util.isNoValue(value))return;if(!util.isObject(value)){return"FORMAT_ERROR"}}}}},{"../util":9}],3:[function(require,module,exports){"use strict";var Validator=require("../Validator");var util=require("../util");module.exports={nested_object:function(livr,ruleBuilders){var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(nestedObject,params,outputArr){if(util.isNoValue(nestedObject))return;if(!util.isObject(nestedObject))return"FORMAT_ERROR";var result=validator.validate(nestedObject);if(result){outputArr.push(result);return}else{return validator.getErrors()}}},variable_object:function(selectorField,livrs,ruleBuilders){var validators={};for(var selectorValue in livrs){var validator=new Validator(livrs[selectorValue]).registerRules(ruleBuilders).prepare();validators[selectorValue]=validator}return function(object,params,outputArr){if(util.isNoValue(object))return;if(!util.isObject(object)||!object[selectorField]||!validators[object[selectorField]]){return"FORMAT_ERROR"}var validator=validators[object[selectorField]];var result=validator.validate(object);if(result){outputArr.push(result);return}else{return validator.getErrors()}}},list_of:function(rules,ruleBuilders){if(!Array.isArray(rules)){rules=Array.prototype.slice.call(arguments);ruleBuilders=rules.pop()}var livr={field:rules};var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(values,params,outputArr){if(util.isNoValue(values))return;if(!Array.isArray(values))return"FORMAT_ERROR";var results=[];var errors=[];var hasErrors=false;for(var i=0;i<values.length;i++){var result=validator.validate({field:values[i]});if(result){results.push(result.field);errors.push(null)}else{hasErrors=true;errors.push(validator.getErrors().field);results.push(null)}}if(hasErrors){return errors}else{outputArr.push(results);return}}},list_of_objects:function(livr,ruleBuilders){var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(objects,params,outputArr){if(util.isNoValue(objects))return;if(!Array.isArray(objects))return"FORMAT_ERROR";var results=[];var errors=[];var hasErrors=false;for(var i=0;i<objects.length;i++){var result=validator.validate(objects[i]);if(result){results.push(result);errors.push(null)}else{hasErrors=true;errors.push(validator.getErrors());results.push(null)}}if(hasErrors){return errors}else{outputArr.push(results);return}}},list_of_different_objects:function(selectorField,livrs,ruleBuilders){var validators={};for(var selectorValue in livrs){var validator=new Validator(livrs[selectorValue]).registerRules(ruleBuilders).prepare();validators[selectorValue]=validator}return function(objects,params,outputArr){if(util.isNoValue(objects))return;if(!Array.isArray(objects))return"FORMAT_ERROR";var results=[];var errors=[];var hasErrors=false;for(var i=0;i<objects.length;i++){var object=objects[i];if(typeof object!="object"||!object[selectorField]||!validators[object[selectorField]]){errors.push("FORMAT_ERROR");continue}var validator=validators[object[selectorField]];var result=validator.validate(object);if(result){results.push(result);errors.push(null)}else{hasErrors=true;errors.push(validator.getErrors());results.push(null)}}if(hasErrors){return errors}else{outputArr.push(results);return}}},or:function(){var ruleSets=Array.prototype.slice.call(arguments);var ruleBuilders=ruleSets.pop();var validators=ruleSets.map(function(rules){var livr={field:rules};var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return validator});return function(value,params,outputArr){if(util.isNoValue(value))return;var lastError;for(var i=0;i<validators.length;i++){var validator=validators[i];var result=validator.validate({field:value});if(result){outputArr.push(result.field);return}else{lastError=validator.getErrors().field}}if(lastError){return lastError}}}}},{"../Validator":8,"../util":9}],4:[function(require,module,exports){"use strict";var util=require("../util");module.exports={default:function(defaultValue){return function(value,params,outputArr){if(util.isNoValue(value)){outputArr.push(defaultValue)}}},trim:function(){return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.replace(/^\s*/,"").replace(/\s*$/,""))}},to_lc:function(){return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.toLowerCase())}},to_uc:function(){return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.toUpperCase())}},remove:function(chars){chars=util.escapeRegExp(chars);var re=new RegExp("["+chars+"]","g");return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.replace(re,""))}},leave_only:function(chars){chars=util.escapeRegExp(chars);var re=new RegExp("[^"+chars+"]","g");return function(value,params,outputArr){if(util.isNoValue(value)||typeof value==="object")return;value+="";outputArr.push(value.replace(re,""))}}}},{"../util":9}],5:[function(require,module,exports){"use strict";var util=require("../util");module.exports={integer:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_INTEGER";if(!Number.isInteger(+value))return"NOT_INTEGER";outputArr.push(+value)}},positive_integer:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_POSITIVE_INTEGER";if(!Number.isInteger(+value)||+value<1)return"NOT_POSITIVE_INTEGER";outputArr.push(+value)}},decimal:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_DECIMAL";value+="";if(!/^(?:\-?(?:(?:[0-9]+\.[0-9]+)|(?:[0-9]+)))$/.test(value))return"NOT_DECIMAL";outputArr.push(+value)}},positive_decimal:function(){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_POSITIVE_DECIMAL";value+="";if(!/^(?:(?:[0-9]*\.[0-9]+)|(?:[1-9][0-9]*))$/.test(value))return"NOT_POSITIVE_DECIMAL";outputArr.push(+value)}},max_number:function(maxNumber){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_NUMBER";if(+value>+maxNumber)return"TOO_HIGH";outputArr.push(+value)}},min_number:function(minNumber){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_NUMBER";if(+value<+minNumber)return"TOO_LOW";outputArr.push(+value)}},number_between:function(minNumber,maxNumber){return function(value,params,outputArr){if(util.isNoValue(value))return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(!util.looksLikeNumber(value))return"NOT_NUMBER";if(+value<+minNumber)return"TOO_LOW";if(+value>+maxNumber)return"TOO_HIGH";outputArr.push(+value)}}}},{"../util":9}],6:[function(require,module,exports){"use strict";var util=require("../util");module.exports={email:function(){var emailRe=/^([\w\-_+]+(?:\.[\w\-_+]+)*)@((?:[\w\-]+\.)*\w[\w\-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return function(value){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(!emailRe.test(value))return"WRONG_EMAIL";if(/\@.*\@/.test(value))return"WRONG_EMAIL";if(/\@.*_/.test(value))return"WRONG_EMAIL";return}},equal_to_field:function(field){return function(value,params){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(value!=params[field])return"FIELDS_NOT_EQUAL";return}},url:function(){var urlReStr="^(?:(?:http|https)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[0-1]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))\\.?|localhost)(?::\\d{2,5})?(?:[/?#]\\S*)?$";var urlRe=new RegExp(urlReStr,"i");return function(value){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(value.length<2083&&urlRe.test(value))return;return"WRONG_URL"}},iso_date:function(){return function(value){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";var matched=value.match(/^(\d{4})-([0-1][0-9])-([0-3][0-9])$/);if(matched){var epoch=Date.parse(value);if(!epoch&&epoch!==0)return"WRONG_DATE";var d=new Date(epoch);d.setTime(d.getTime()+d.getTimezoneOffset()*60*1e3);if(d.getFullYear()==matched[1]&&d.getMonth()+1==+matched[2]&&d.getDate()==+matched[3]){return}}return"WRONG_DATE"}}}},{"../util":9}],7:[function(require,module,exports){"use strict";var util=require("../util");module.exports={string:function(){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";outputArr.push(value+"");return}},eq:function(allowedValue){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";if(value+""===allowedValue+""){outputArr.push(allowedValue);return}return"NOT_ALLOWED_VALUE"}},one_of:function(allowedValues){if(!Array.isArray(allowedValues)){allowedValues=Array.prototype.slice.call(arguments);allowedValues.pop()}return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";for(var i=0;i<allowedValues.length;i++){if(value+""===allowedValues[i]+""){outputArr.push(allowedValues[i]);return}}return"NOT_ALLOWED_VALUE"}},max_length:function(maxLength){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length>maxLength)return"TOO_LONG";outputArr.push(value)}},min_length:function(minLength){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length<minLength)return"TOO_SHORT";outputArr.push(value)}},length_equal:function(length){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length<length)return"TOO_SHORT";if(value.length>length)return"TOO_LONG";outputArr.push(value)}},length_between:function(minLength,maxLength){return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(value.length<minLength)return"TOO_SHORT";if(value.length>maxLength)return"TOO_LONG";outputArr.push(value)}},like:function(reStr,flags){var isIgnoreCase=arguments.length===3&&flags.match("i");var re=new RegExp(reStr,isIgnoreCase?"i":"");return function(value,params,outputArr){if(value===undefined||value===null||value==="")return;if(!util.isPrimitiveValue(value))return"FORMAT_ERROR";value+="";if(!value.match(re))return"WRONG_FORMAT";outputArr.push(value)}}}},{"../util":9}],8:[function(require,module,exports){"use strict";var util=require("./util");var DEFAULT_RULES={};var IS_DEFAULT_AUTO_TRIM=0;function Validator(livrRules,isAutoTrim){this.isPrepared=false;this.livrRules=livrRules;this.validators={};this.validatorBuilders={};this.errors=null;if(isAutoTrim!==null&&isAutoTrim!==undefined){this.isAutoTrim=isAutoTrim}else{this.isAutoTrim=IS_DEFAULT_AUTO_TRIM}this.registerRules(DEFAULT_RULES)}Validator.registerDefaultRules=function(rules){for(var ruleName in rules){DEFAULT_RULES[ruleName]=rules[ruleName]}};Validator.getDefaultRules=function(){return DEFAULT_RULES};Validator.registerAliasedDefaultRule=function(alias){if(!alias.name)throw"Alias name required";DEFAULT_RULES[alias.name]=Validator._buildAliasedRule(alias)};Validator._buildAliasedRule=function(alias){if(!alias.name)throw"Alias name required";if(!alias.rules)throw"Alias rules required";var livr={value:alias.rules};return function(ruleBuilders){var validator=new Validator(livr).registerRules(ruleBuilders).prepare();return function(value,params,outputArr){var result=validator.validate({value:value});if(result){outputArr.push(result.value);return}else{return alias.error||validator.getErrors().value}}}};Validator.defaultAutoTrim=function(isAutoTrim){IS_DEFAULT_AUTO_TRIM=!!isAutoTrim};Validator.prototype={prepare:function(){var allRules=this.livrRules;for(var field in allRules){var fieldRules=allRules[field];if(!Array.isArray(fieldRules)){fieldRules=[fieldRules]}var validators=[];for(var i=0;i<fieldRules.length;i++){var parsed=this._parseRule(fieldRules[i]);validators.push(this._buildValidator(parsed.name,parsed.args))}this.validators[field]=validators}this.isPrepared=true;return this},validate:function(data){if(!this.isPrepared)this.prepare();if(!util.isObject(data)){this.errors="FORMAT_ERROR";return}if(this.isAutoTrim){data=this._autoTrim(data)}var errors={},result={};for(var fieldName in this.validators){var validators=this.validators[fieldName];if(!validators||!validators.length)continue;var value=data[fieldName];for(var i=0;i<validators.length;i++){var fieldResultArr=[];var errCode=validators[i](result.hasOwnProperty(fieldName)?result[fieldName]:value,data,fieldResultArr);if(errCode){errors[fieldName]=errCode;break}else if(fieldResultArr.length){result[fieldName]=fieldResultArr[0]}else if(data.hasOwnProperty(fieldName)&&!result.hasOwnProperty(fieldName)){result[fieldName]=value}}}if(util.isEmptyObject(errors)){this.errors=null;return result}else{this.errors=errors;return false}},getErrors:function(){return this.errors},registerRules:function(rules){for(var ruleName in rules){this.validatorBuilders[ruleName]=rules[ruleName]}return this},registerAliasedRule:function(alias){if(!alias.name)throw"Alias name required";this.validatorBuilders[alias.name]=Validator._buildAliasedRule(alias);return this},getRules:function(){return this.validatorBuilders},_parseRule:function(livrRule){var name,args;if(util.isObject(livrRule)){name=Object.keys(livrRule)[0];args=livrRule[name];if(!Array.isArray(args))args=[args]}else{name=livrRule;args=[]}return{name:name,args:args}},_buildValidator:function(name,args){if(!this.validatorBuilders[name]){throw"Rule ["+name+"] not registered"}var allArgs=[];allArgs.push.apply(allArgs,args);allArgs.push(this.getRules());return this.validatorBuilders[name].apply(null,allArgs)},_autoTrim:function(data){var dataType=typeof data;if(dataType!=="object"&&data){if(data.replace){return data.replace(/^\s*/,"").replace(/\s*$/,"")}else{return data}}else if(dataType=="object"&&Array.isArray(data)){var trimmedData=[];for(var i=0;i<data.length;i++){trimmedData[i]=this._autoTrim(data[i])}return trimmedData}else if(dataType=="object"&&util.isObject(data)){var trimmedData={};for(var key in data){if(data.hasOwnProperty(key)){trimmedData[key]=this._autoTrim(data[key])}}return trimmedData}return data}};module.exports=Validator},{"./util":9}],9:[function(require,module,exports){"use strict";module.exports={isPrimitiveValue:function(value){if(typeof value=="string")return true;if(typeof value=="number"&&isFinite(value))return true;if(typeof value=="boolean")return true;return false},looksLikeNumber:function(value){if(!isNaN(+value))return true;return false},isObject:function(obj){return Object(obj)===obj&&Object.getPrototypeOf(obj)===Object.prototype},isEmptyObject:function(map){for(var key in map){if(map.hasOwnProperty(key)){return false}}return true},escapeRegExp:function(str){return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isNoValue:function(value){return value===undefined||value===null||value===""}}},{}],10:[function(require,module,exports){window.LIVR=require("../lib/LIVR")},{"../lib/LIVR":1}]},{},[10]); |
@@ -6,6 +6,6 @@ 'use strict'; | ||
module.exports = { | ||
default: function(defaulValue) { | ||
default: function(defaultValue) { | ||
return function(value, params, outputArr) { | ||
if ( util.isNoValue(value) ) { | ||
outputArr.push( defaulValue ); | ||
outputArr.push( defaultValue ); | ||
} | ||
@@ -12,0 +12,0 @@ }; |
@@ -35,3 +35,3 @@ 'use strict'; | ||
value += ''; | ||
if ( ! /^(?:\-?(?:[0-9]+\.[0-9]+)|(?:[0-9]+))$/.test(value) ) return 'NOT_DECIMAL'; | ||
if ( ! /^(?:\-?(?:(?:[0-9]+\.[0-9]+)|(?:[0-9]+)))$/.test(value) ) return 'NOT_DECIMAL'; | ||
outputArr.push(+value); | ||
@@ -38,0 +38,0 @@ }; |
{ | ||
"name": "livr", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Lightweight validator supporting Language Independent Validation Rules Specification", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/koorchik/js-validator-livr", |
[![Build Status](https://travis-ci.org/koorchik/js-validator-livr.svg?branch=master)](https://travis-ci.org/koorchik/js-validator-livr) | ||
# NAME | ||
# LIVR Validator | ||
LIVR.Validator - Lightweight validator supporting Language Independent Validation Rules Specification (LIVR) | ||
@@ -43,3 +43,3 @@ | ||
You can use aliases(prefferable, syntax covered by the specification) for a lot of cases: | ||
You can use aliases(preferable, syntax covered by the specification) for a lot of cases: | ||
@@ -86,4 +86,4 @@ ```javascript | ||
* Excludes all fields that do not have validation rules described | ||
* Has possibility to validatate complex hierarchical structures | ||
* Easy to describe and undersand rules | ||
* Has possibility to validate complex hierarchical structures | ||
* Easy to describe and understand rules | ||
* Returns understandable error codes(not error messages) | ||
@@ -94,2 +94,4 @@ * Easy to add own rules | ||
__You can find more rules in [livr-extra-rules](https://www.npmjs.com/package/livr-extra-rules)__ | ||
# INSTALL | ||
@@ -105,3 +107,3 @@ | ||
You can find browserified versions in "dist" folder (livr-debug.js - not minified development version with source maps, livr-min.js - minified production version) | ||
You can find browserified versions in "dist" folder (livr-debug.js - not minified development version with source maps, livr-min.js - minified production version). Possible you will need some polyfills ("isInteger" etc) for older browsers. | ||
@@ -111,3 +113,3 @@ # CLASS METHODS | ||
## new LIVR.Validator(livr, isAutoTrim); | ||
Contructor creates validator objects. | ||
Constructor creates validator objects. | ||
livr - validations rules. Rules description is available here - https://github.com/koorchik/LIVR | ||
@@ -169,3 +171,3 @@ | ||
} | ||
}); | ||
}}); | ||
``` | ||
@@ -209,3 +211,3 @@ | ||
List of usefull utils for writing your rules (see source code) | ||
List of useful utils for writing your rules (see source code) | ||
@@ -218,3 +220,3 @@ # OBJECT METHODS | ||
```javascript | ||
my validaData = validator.validate(input) | ||
var validData = validator.validate(input) | ||
@@ -242,8 +244,8 @@ if (validData) { | ||
```javascript | ||
{ | ||
"country": "NOT_ALLOWED_VALUE", | ||
"zip": "NOT_POSITIVE_INTEGER", | ||
"street": "REQUIRED", | ||
"building": "NOT_POSITIVE_INTEGER" | ||
} | ||
{ | ||
"country": "NOT_ALLOWED_VALUE", | ||
"zip": "NOT_POSITIVE_INTEGER", | ||
"street": "REQUIRED", | ||
"building": "NOT_POSITIVE_INTEGER" | ||
} | ||
``` | ||
@@ -250,0 +252,0 @@ |
{ | ||
"number1": "TOO_LOW", | ||
"number2": "TOO_LOW", | ||
"number3": "TOO_LOW", | ||
@@ -5,0 +6,0 @@ "value_is_string": "NOT_NUMBER", |
{ | ||
"number1": "5", | ||
"number2": "-10", | ||
"number3": 1.2, | ||
"empty_field": "", | ||
@@ -5,0 +6,0 @@ "extra_field": "100", |
{ | ||
"number1": { "min_number" : 10 }, | ||
"number2": [{ "min_number" : 20 }], | ||
"number3": [{ "min_number" : 5 }], | ||
"empty_field": { "min_number" : 10 }, | ||
@@ -5,0 +6,0 @@ |
{ | ||
"number1": "TOO_LOW", | ||
"number2": "TOO_HIGH", | ||
"number3": "TOO_LOW", | ||
"number4": "TOO_HIGH", | ||
@@ -5,0 +7,0 @@ "value_is_string": "NOT_NUMBER", |
{ | ||
"number1": "5", | ||
"number2": "40", | ||
"number3": -40, | ||
"number4": 40, | ||
"empty_field": "", | ||
@@ -5,0 +7,0 @@ "extra_field": "100", |
{ | ||
"number1": { "number_between": [10,20] }, | ||
"number2": [ { "number_between": [10,20] } ], | ||
"number3": [ { "number_between": [-10,10] } ], | ||
"number4": [ { "number_between": [-10,10] } ], | ||
"empty_field": { "number_between": [10,20] }, | ||
@@ -5,0 +7,0 @@ |
@@ -5,2 +5,3 @@ { | ||
"iso_date3": "WRONG_DATE", | ||
"like_iso_date": "WRONG_DATE", | ||
@@ -11,2 +12,2 @@ "value_is_hash": "FORMAT_ERROR", | ||
"value_is_empty_array": "FORMAT_ERROR" | ||
} | ||
} |
@@ -5,2 +5,3 @@ { | ||
"iso_date3": "2014-10-10T22:22", | ||
"like_iso_date":"aaaa-bb-cc", | ||
"empty_field": "", | ||
@@ -13,2 +14,2 @@ "extra_field": "aaaa", | ||
"value_is_empty_array": [] | ||
} | ||
} |
@@ -5,2 +5,3 @@ { | ||
"iso_date3": [ { "iso_date": [] } ], | ||
"like_iso_date": [ { "iso_date": [] } ], | ||
"empty_field": "iso_date", | ||
@@ -12,2 +13,2 @@ | ||
"value_is_empty_array": "iso_date" | ||
} | ||
} |
@@ -6,7 +6,9 @@ { | ||
"number1": "NOT_ALLOWED_VALUE", | ||
"value_is_hash": "FORMAT_ERROR", | ||
"value_is_empty_hash": "FORMAT_ERROR", | ||
"value_is_array": "FORMAT_ERROR", | ||
"number2": "NOT_ALLOWED_VALUE", | ||
"number3": "NOT_ALLOWED_VALUE", | ||
"empty_string": "NOT_ALLOWED_VALUE", | ||
"value_is_hash": "FORMAT_ERROR", | ||
"value_is_empty_hash": "FORMAT_ERROR", | ||
"value_is_array": "FORMAT_ERROR", | ||
"value_is_empty_array": "FORMAT_ERROR" | ||
} |
@@ -6,4 +6,6 @@ { | ||
"number1": "1.0", | ||
"number2": "asdasd", | ||
"number3": " _", | ||
"empty_string": " ", | ||
"extra_city": "New York", | ||
"value_is_hash": {"test": 1}, | ||
@@ -10,0 +12,0 @@ "value_is_empty_hash": {}, |
@@ -6,3 +6,5 @@ { | ||
"number1": { "eq": 1 }, | ||
"number2": { "eq": 1 }, | ||
"number3": { "eq": 1.2 }, | ||
"empty_string": {"eq": 1 }, | ||
"value_is_hash": { "eq": "Moscow" }, | ||
@@ -9,0 +11,0 @@ "value_is_empty_hash": { "eq": "Moscow" }, |
@@ -7,2 +7,3 @@ { | ||
"number2": 2, | ||
"number3": 1.2, | ||
"boolean": true, | ||
@@ -9,0 +10,0 @@ "empty_city": "", |
@@ -7,4 +7,5 @@ { | ||
"number2": "2", | ||
"number3": 1.2, | ||
"boolean": true, | ||
"empty_city": "" | ||
} |
@@ -7,4 +7,5 @@ { | ||
"number2": { "one_of": ["1", "2"] }, | ||
"number3": { "one_of": 1.2 }, | ||
"boolean": { "one_of": [true, false] }, | ||
"empty_city": { "one_of": [["Moscow", "Kiev" ]] } | ||
} |
@@ -6,4 +6,5 @@ { | ||
"number1": 1111, | ||
"decimal": 1.2, | ||
"empty_name": "", | ||
"extra_name": "extra_name" | ||
} |
@@ -6,3 +6,4 @@ { | ||
"number1": "1111", | ||
"decimal": "1.2", | ||
"empty_name": "" | ||
} |
@@ -6,4 +6,5 @@ { | ||
"number1": { "max_length": 5 }, | ||
"decimal": { "max_length": 3 }, | ||
"empty_name": { "max_length": 3 }, | ||
"missed_name": { "max_length": 3 } | ||
} |
@@ -5,2 +5,3 @@ { | ||
"middle_name": "Some name", | ||
"nick_name": "joney_k", | ||
"number1": 1111, | ||
@@ -7,0 +8,0 @@ "empty_name": "", |
@@ -5,4 +5,5 @@ { | ||
"middle_name": "Some name", | ||
"nick_name": "joney_k", | ||
"number1": "1111", | ||
"empty_name": "" | ||
} |
@@ -5,2 +5,3 @@ { | ||
"middle_name": [{ "length_between": [0, 100] }], | ||
"nick_name": [{ "length_between": [0, 100] }], | ||
"number1": { "length_between": [2, 4] }, | ||
@@ -7,0 +8,0 @@ "empty_name": { "length_between": [2, 3] }, |
@@ -5,4 +5,5 @@ { | ||
"number3": -1.10, | ||
"number4": -3.00, | ||
"empty_field": "", | ||
"extra_field": "100" | ||
} |
@@ -5,3 +5,4 @@ { | ||
"number3": -1.10, | ||
"number4": -3.00, | ||
"empty_field": "" | ||
} |
@@ -5,3 +5,4 @@ { | ||
"number3": [ { "decimal": [] } ], | ||
"number4": "decimal", | ||
"empty_field": "decimal" | ||
} |
@@ -5,4 +5,5 @@ { | ||
"number3": "0", | ||
"number4": 1, | ||
"empty_field": "", | ||
"extra_field": "100" | ||
} |
@@ -5,3 +5,4 @@ { | ||
"number3": 0, | ||
"number4": 1, | ||
"empty_field": "" | ||
} |
@@ -5,3 +5,4 @@ { | ||
"number3": [ { "number_between": [-1, 1] } ], | ||
"number4": [ { "number_between": [-10, 10] } ], | ||
"empty_field": { "number_between": [10, 20] } | ||
} | ||
} |
@@ -9,3 +9,8 @@ { | ||
}, | ||
"should_be_empty": { | ||
"extra_field": "will be removed" | ||
}, | ||
"extra_field": "will be removed" | ||
} | ||
} |
@@ -7,3 +7,7 @@ { | ||
"building": 10 | ||
}, | ||
"should_be_empty": { | ||
} | ||
} |
@@ -7,3 +7,8 @@ { | ||
"building": ["required", "positive_integer" ] | ||
} } ], | ||
"should_be_empty": [ "required", { "nested_object": { | ||
"country": [{ "one_of": [["Ukraine", "USA"]] } ], | ||
"zip": "positive_integer" | ||
} } ] | ||
} | ||
} |
@@ -5,2 +5,3 @@ { | ||
"city3": "Kiev", | ||
"city4": "Dnipro", | ||
"number1": "2", | ||
@@ -7,0 +8,0 @@ "number2": 2, |
@@ -5,2 +5,3 @@ { | ||
"city3": "Kiev", | ||
"city4": "Dnipro", | ||
"number1": 2, | ||
@@ -7,0 +8,0 @@ "number2": "2", |
@@ -5,2 +5,3 @@ { | ||
"city3": { "eq": "Kiev" }, | ||
"city4": [{ "eq": ["Dnipro"] }], | ||
"number1": { "eq": 2 }, | ||
@@ -7,0 +8,0 @@ "number2": { "eq": "2" }, |
{ | ||
"string_value": " value ", | ||
"decimal_value": 1.2, | ||
"unicode_string": " Привет ", | ||
"object": {"string_value": " some value "}, | ||
"list_of_string_values": [" value1 ", {"key": "123"}, " value2 "] | ||
} | ||
} |
{ | ||
"string_value": "value", | ||
"decimal_value": "1.2", | ||
"unicode_string": "Привет", | ||
"object": {"string_value": "some value"}, | ||
"list_of_string_values": ["value1", {"key": "123"}, "value2"] | ||
} | ||
} |
{ | ||
"string_value": "trim", | ||
"decimal_value": ["trim"], | ||
"unicode_string": "trim", | ||
"object": {"nested_object": {"string_value": "trim"} }, | ||
"list_of_string_values": {"list_of": "trim"} | ||
} | ||
} |
{ | ||
"string_value": "Value", | ||
"decimal_value": 1.2, | ||
"unicode_string": "ПРИВЕТ", | ||
"object": {"string_value": "Some Value"}, | ||
"list_of_string_values": ["VALUE1", {"key": "123"}, "VALUE2"], | ||
"to_lc_with_another_rule": "Value" | ||
} | ||
} |
{ | ||
"string_value": "value", | ||
"decimal_value": "1.2", | ||
"unicode_string": "привет", | ||
"object": {"string_value": "some value"}, | ||
"list_of_string_values": ["value1", {"key": "123"}, "value2"], | ||
"to_lc_with_another_rule": "value" | ||
} | ||
} |
{ | ||
"string_value": "to_lc", | ||
"decimal_value": ["to_lc"], | ||
"unicode_string": "to_lc", | ||
"object": {"nested_object": {"string_value": "to_lc"} }, | ||
"list_of_string_values": {"list_of": "to_lc"}, | ||
"to_lc_with_another_rule": ["to_lc", "required"] | ||
} | ||
} |
{ | ||
"string_value": "Value", | ||
"unicode_string":"привет", | ||
"decimal_value": 1.2, | ||
"object": {"string_value": "Some Value"}, | ||
"list_of_string_values": ["value1", {"key": "123"}, "value2"] | ||
} | ||
} |
{ | ||
"string_value": "VALUE", | ||
"unicode_string": "ПРИВЕТ", | ||
"decimal_value": "1.2", | ||
"object": {"string_value": "SOME VALUE"}, | ||
"list_of_string_values": ["VALUE1", {"key": "123"}, "VALUE2"] | ||
} | ||
} |
{ | ||
"string_value": "to_uc", | ||
"unicode_string": "to_uc", | ||
"decimal_value": ["to_uc"], | ||
"object": {"nested_object": {"string_value": "to_uc"} }, | ||
"list_of_string_values": {"list_of": "to_uc"} | ||
} | ||
} |
@@ -6,3 +6,3 @@ { | ||
"zero_value": 0, | ||
"null_value": null, | ||
"string_value": "Value", | ||
@@ -9,0 +9,0 @@ "object": {"name": "Value"}, |
@@ -6,2 +6,3 @@ { | ||
"zero_value": 0, | ||
"null_value": "12", | ||
"missed_value": "15", | ||
@@ -8,0 +9,0 @@ |
@@ -6,2 +6,3 @@ { | ||
"zero_value": {"default": 10}, | ||
"null_value": {"default":"12"}, | ||
"missed_value": {"default": "15"}, | ||
@@ -8,0 +9,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201773
237
4037
282
6