Comparing version 2.0.2 to 2.1.0
@@ -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(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]); | ||
!function(e){var r={};function i(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=e,i.c=r,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},i.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="",i(i.s=9)}([function(e,r,i){"use strict";e.exports={isPrimitiveValue:function(e){return"string"==typeof e||(!("number"!=typeof e||!isFinite(e))||"boolean"==typeof e)},looksLikeNumber:function(e){return!isNaN(+e)},isObject:function(e){return Object(e)===e&&Object.getPrototypeOf(e)===Object.prototype},isEmptyObject:function(e){for(var r in e)if(e.hasOwnProperty(r))return!1;return!0},escapeRegExp:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isNoValue:function(e){return void 0===e||null===e||""===e}}},function(e,r,i){"use strict";var t=i(0),n={},u=0;function o(e,r){this.isPrepared=!1,this.livrRules=e,this.validators={},this.validatorBuilders={},this.errors=null,this.isAutoTrim=null!==r&&void 0!==r?r:u,this.registerRules(n)}o.registerDefaultRules=function(e){for(var r in e)n[r]=e[r]},o.getDefaultRules=function(){return n},o.registerAliasedDefaultRule=function(e){if(!e.name)throw"Alias name required";n[e.name]=o._buildAliasedRule(e)},o._buildAliasedRule=function(e){if(!e.name)throw"Alias name required";if(!e.rules)throw"Alias rules required";var r={value:e.rules};return function(i){var t=new o(r).registerRules(i).prepare();return function(r,i,n){var u=t.validate({value:r});return u?void n.push(u.value):e.error||t.getErrors().value}}},o.defaultAutoTrim=function(e){u=!!e},o.prototype={prepare:function(){var e=this.livrRules;for(var r in e){var i=e[r];Array.isArray(i)||(i=[i]);for(var t=[],n=0;n<i.length;n++){var u=this._parseRule(i[n]);t.push(this._buildValidator(u.name,u.args))}this.validators[r]=t}return this.isPrepared=!0,this},validate:function(e){if(this.isPrepared||this.prepare(),t.isObject(e)){this.isAutoTrim&&(e=this._autoTrim(e));var r={},i={};for(var n in this.validators){var u=this.validators[n];if(u&&u.length)for(var o=e[n],s=0;s<u.length;s++){var l=[],a=u[s](i.hasOwnProperty(n)?i[n]:o,e,l);if(a){r[n]=a;break}l.length?i[n]=l[0]:e.hasOwnProperty(n)&&!i.hasOwnProperty(n)&&(i[n]=o)}}return t.isEmptyObject(r)?(this.errors=null,i):(this.errors=r,!1)}this.errors="FORMAT_ERROR"},getErrors:function(){return this.errors},registerRules:function(e){for(var r in e)this.validatorBuilders[r]=e[r];return this},registerAliasedRule:function(e){if(!e.name)throw"Alias name required";return this.validatorBuilders[e.name]=o._buildAliasedRule(e),this},getRules:function(){return this.validatorBuilders},_parseRule:function(e){var r,i;return t.isObject(e)?(i=e[r=Object.keys(e)[0]],Array.isArray(i)||(i=[i])):(r=e,i=[]),{name:r,args:i}},_buildValidator:function(e,r){if(!this.validatorBuilders[e])throw"Rule ["+e+"] not registered";var i=[];return i.push.apply(i,r),i.push(this.getRules()),this.validatorBuilders[e].apply(null,i)},_autoTrim:function(e){var r=typeof e;if("object"!==r&&e)return e.replace?e.replace(/^\s*/,"").replace(/\s*$/,""):e;if("object"==r&&Array.isArray(e)){for(var i=[],n=0;n<e.length;n++)i[n]=this._autoTrim(e[n]);return i}if("object"==r&&t.isObject(e)){i={};for(var u in e)e.hasOwnProperty(u)&&(i[u]=this._autoTrim(e[u]));return i}return e}},e.exports=o},function(e,r,i){"use strict";var t=i(0);e.exports={default:function(e){return function(r,i,n){t.isNoValue(r)&&n.push(e)}},trim:function(){return function(e,r,i){t.isNoValue(e)||"object"==typeof e||(e+="",i.push(e.replace(/^\s*/,"").replace(/\s*$/,"")))}},to_lc:function(){return function(e,r,i){t.isNoValue(e)||"object"==typeof e||(e+="",i.push(e.toLowerCase()))}},to_uc:function(){return function(e,r,i){t.isNoValue(e)||"object"==typeof e||(e+="",i.push(e.toUpperCase()))}},remove:function(e){e=t.escapeRegExp(e);var r=new RegExp("["+e+"]","g");return function(e,i,n){t.isNoValue(e)||"object"==typeof e||(e+="",n.push(e.replace(r,"")))}},leave_only:function(e){e=t.escapeRegExp(e);var r=new RegExp("[^"+e+"]","g");return function(e,i,n){t.isNoValue(e)||"object"==typeof e||(e+="",n.push(e.replace(r,"")))}}}},function(e,r,i){"use strict";var t=i(1),n=i(0);e.exports={nested_object:function(e,r){var i=new t(e).registerRules(r).prepare();return function(e,r,t){if(!n.isNoValue(e)){if(!n.isObject(e))return"FORMAT_ERROR";var u=i.validate(e);return u?void t.push(u):i.getErrors()}}},variable_object:function(e,r,i){var u={};for(var o in r){var s=new t(r[o]).registerRules(i).prepare();u[o]=s}return function(r,i,t){if(!n.isNoValue(r)){if(!n.isObject(r)||!r[e]||!u[r[e]])return"FORMAT_ERROR";var o=u[r[e]],s=o.validate(r);return s?void t.push(s):o.getErrors()}}},list_of:function(e,r){Array.isArray(e)||(r=(e=Array.prototype.slice.call(arguments)).pop());var i=new t({field:e}).registerRules(r).prepare();return function(e,r,t){if(!n.isNoValue(e)){if(!Array.isArray(e))return"FORMAT_ERROR";for(var u=[],o=[],s=!1,l=0;l<e.length;l++){var a=i.validate({field:e[l]});a?(u.push(a.field),o.push(null)):(s=!0,o.push(i.getErrors().field),u.push(null))}return s?o:void t.push(u)}}},list_of_objects:function(e,r){var i=new t(e).registerRules(r).prepare();return function(e,r,t){if(!n.isNoValue(e)){if(!Array.isArray(e))return"FORMAT_ERROR";for(var u=[],o=[],s=!1,l=0;l<e.length;l++){var a=i.validate(e[l]);a?(u.push(a),o.push(null)):(s=!0,o.push(i.getErrors()),u.push(null))}return s?o:void t.push(u)}}},list_of_different_objects:function(e,r,i){var u={};for(var o in r){var s=new t(r[o]).registerRules(i).prepare();u[o]=s}return function(r,i,t){if(!n.isNoValue(r)){if(!Array.isArray(r))return"FORMAT_ERROR";for(var o=[],s=[],l=!1,a=0;a<r.length;a++){var f=r[a];if("object"==typeof f&&f[e]&&u[f[e]]){var c=u[f[e]],_=c.validate(f);_?(o.push(_),s.push(null)):(l=!0,s.push(c.getErrors()),o.push(null))}else s.push("FORMAT_ERROR")}return l?s:void t.push(o)}}},or:function(){var e=Array.prototype.slice.call(arguments),r=e.pop(),i=e.map(function(e){return new t({field:e}).registerRules(r).prepare()});return function(e,r,t){if(!n.isNoValue(e)){for(var u,o=0;o<i.length;o++){var s=i[o],l=s.validate({field:e});if(l)return void t.push(l.field);u=s.getErrors().field}return u||void 0}}}}},function(e,r,i){"use strict";var t=i(0);e.exports={email:function(){var e=/^([\w\-_+]+(?:\.[\w\-_+]+)*)@((?:[\w\-]+\.)*\w[\w\-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return function(r){if(void 0!==r&&null!==r&&""!==r)return t.isPrimitiveValue(r)?(r+="",e.test(r)?/\@.*\@/.test(r)?"WRONG_EMAIL":/\@.*_/.test(r)?"WRONG_EMAIL":void 0:"WRONG_EMAIL"):"FORMAT_ERROR"}},equal_to_field:function(e){return function(r,i){if(void 0!==r&&null!==r&&""!==r)return t.isPrimitiveValue(r)?r!=i[e]?"FIELDS_NOT_EQUAL":void 0:"FORMAT_ERROR"}},url:function(){var e=new RegExp("^(?:(?: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*)?$","i");return function(r){if(void 0!==r&&null!==r&&""!==r){if(!t.isPrimitiveValue(r))return"FORMAT_ERROR";if(!(r.length<2083&&e.test(r)))return"WRONG_URL"}}},iso_date:function(){return function(e){if(void 0!==e&&null!==e&&""!==e){if(!t.isPrimitiveValue(e))return"FORMAT_ERROR";var r=e.match(/^(\d{4})-([0-1][0-9])-([0-3][0-9])$/);if(r){var i=Date.parse(e);if(!i&&0!==i)return"WRONG_DATE";var n=new Date(i);if(n.setTime(n.getTime()+60*n.getTimezoneOffset()*1e3),n.getFullYear()==r[1]&&n.getMonth()+1==+r[2]&&n.getDate()==+r[3])return}return"WRONG_DATE"}}}}},function(e,r,i){"use strict";var t=i(0);e.exports={integer:function(){return function(e,r,i){if(!t.isNoValue(e))return t.isPrimitiveValue(e)?t.looksLikeNumber(e)&&Number.isInteger(+e)?void i.push(+e):"NOT_INTEGER":"FORMAT_ERROR"}},positive_integer:function(){return function(e,r,i){if(!t.isNoValue(e))return t.isPrimitiveValue(e)?t.looksLikeNumber(e)?!Number.isInteger(+e)||+e<1?"NOT_POSITIVE_INTEGER":void i.push(+e):"NOT_POSITIVE_INTEGER":"FORMAT_ERROR"}},decimal:function(){return function(e,r,i){if(!t.isNoValue(e)){if(!t.isPrimitiveValue(e))return"FORMAT_ERROR";if(!t.looksLikeNumber(e))return"NOT_DECIMAL";if(!/^(?:\-?(?:(?:[0-9]+\.[0-9]+)|(?:[0-9]+)))$/.test(e+=""))return"NOT_DECIMAL";i.push(+e)}}},positive_decimal:function(){return function(e,r,i){if(!t.isNoValue(e)){if(!t.isPrimitiveValue(e))return"FORMAT_ERROR";if(!t.looksLikeNumber(e))return"NOT_POSITIVE_DECIMAL";if(!/^(?:(?:[0-9]*\.[0-9]+)|(?:[1-9][0-9]*))$/.test(e+=""))return"NOT_POSITIVE_DECIMAL";i.push(+e)}}},max_number:function(e){return function(r,i,n){if(!t.isNoValue(r))return t.isPrimitiveValue(r)?t.looksLikeNumber(r)?+r>+e?"TOO_HIGH":void n.push(+r):"NOT_NUMBER":"FORMAT_ERROR"}},min_number:function(e){return function(r,i,n){if(!t.isNoValue(r))return t.isPrimitiveValue(r)?t.looksLikeNumber(r)?+r<+e?"TOO_LOW":void n.push(+r):"NOT_NUMBER":"FORMAT_ERROR"}},number_between:function(e,r){return function(i,n,u){if(!t.isNoValue(i))return t.isPrimitiveValue(i)?t.looksLikeNumber(i)?+i<+e?"TOO_LOW":+i>+r?"TOO_HIGH":void u.push(+i):"NOT_NUMBER":"FORMAT_ERROR"}}}},function(e,r,i){"use strict";var t=i(0);e.exports={string:function(){return function(e,r,i){if(void 0!==e&&null!==e&&""!==e)return t.isPrimitiveValue(e)?void i.push(e+""):"FORMAT_ERROR"}},eq:function(e){return function(r,i,n){if(void 0!==r&&null!==r&&""!==r){if(!t.isPrimitiveValue(r))return"FORMAT_ERROR";if(r+""!=e+"")return"NOT_ALLOWED_VALUE";n.push(e)}}},one_of:function(e){return Array.isArray(e)||(e=Array.prototype.slice.call(arguments)).pop(),function(r,i,n){if(void 0!==r&&null!==r&&""!==r){if(!t.isPrimitiveValue(r))return"FORMAT_ERROR";for(var u=0;u<e.length;u++)if(r+""==e[u]+"")return void n.push(e[u]);return"NOT_ALLOWED_VALUE"}}},max_length:function(e){return function(r,i,n){if(void 0!==r&&null!==r&&""!==r){if(!t.isPrimitiveValue(r))return"FORMAT_ERROR";if((r+="").length>e)return"TOO_LONG";n.push(r)}}},min_length:function(e){return function(r,i,n){if(void 0!==r&&null!==r&&""!==r){if(!t.isPrimitiveValue(r))return"FORMAT_ERROR";if((r+="").length<e)return"TOO_SHORT";n.push(r)}}},length_equal:function(e){return function(r,i,n){if(void 0!==r&&null!==r&&""!==r)return t.isPrimitiveValue(r)?(r+="").length<e?"TOO_SHORT":r.length>e?"TOO_LONG":void n.push(r):"FORMAT_ERROR"}},length_between:function(e,r){return function(i,n,u){if(void 0!==i&&null!==i&&""!==i)return t.isPrimitiveValue(i)?(i+="").length<e?"TOO_SHORT":i.length>r?"TOO_LONG":void u.push(i):"FORMAT_ERROR"}},like:function(e,r){var i=3===arguments.length&&r.match("i"),n=new RegExp(e,i?"i":"");return function(e,r,i){if(void 0!==e&&null!==e&&""!==e){if(!t.isPrimitiveValue(e))return"FORMAT_ERROR";if(!(e+="").match(n))return"WRONG_FORMAT";i.push(e)}}}}},function(e,r,i){"use strict";var t=i(0);e.exports={required:function(){return function(e){if(t.isNoValue(e))return"REQUIRED"}},not_empty:function(){return function(e){if(null!==e&&void 0!==e&&""===e)return"CANNOT_BE_EMPTY"}},not_empty_list:function(){return function(e){return void 0===e||""===e?"CANNOT_BE_EMPTY":Array.isArray(e)?e.length<1?"CANNOT_BE_EMPTY":void 0:"FORMAT_ERROR"}},any_object:function(){return function(e){if(!t.isNoValue(e))return t.isObject(e)?void 0:"FORMAT_ERROR"}}}},function(e,r,i){"use strict";var t={rules:{}};t.rules.common=i(7),t.rules.string=i(6),t.rules.numeric=i(5),t.rules.special=i(4),t.rules.meta=i(3),t.rules.modifiers=i(2),t.Validator=i(1),t.util=i(0),t.Validator.registerDefaultRules({required:t.rules.common.required,not_empty:t.rules.common.not_empty,not_empty_list:t.rules.common.not_empty_list,any_object:t.rules.common.any_object,string:t.rules.string.string,eq:t.rules.string.eq,one_of:t.rules.string.one_of,max_length:t.rules.string.max_length,min_length:t.rules.string.min_length,length_equal:t.rules.string.length_equal,length_between:t.rules.string.length_between,like:t.rules.string.like,integer:t.rules.numeric.integer,positive_integer:t.rules.numeric.positive_integer,decimal:t.rules.numeric.decimal,positive_decimal:t.rules.numeric.positive_decimal,max_number:t.rules.numeric.max_number,min_number:t.rules.numeric.min_number,number_between:t.rules.numeric.number_between,email:t.rules.special.email,equal_to_field:t.rules.special.equal_to_field,url:t.rules.special.url,iso_date:t.rules.special.iso_date,nested_object:t.rules.meta.nested_object,variable_object:t.rules.meta.variable_object,list_of:t.rules.meta.list_of,list_of_objects:t.rules.meta.list_of_objects,or:t.rules.meta.or,list_of_different_objects:t.rules.meta.list_of_different_objects,default:t.rules.modifiers.default,trim:t.rules.modifiers.trim,to_lc:t.rules.modifiers.to_lc,to_uc:t.rules.modifiers.to_uc,remove:t.rules.modifiers.remove,leave_only:t.rules.modifiers.leave_only}),e.exports=t},function(e,r,i){window.LIVR=i(8)}]); |
{ | ||
"name": "livr", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Lightweight validator supporting Language Independent Validation Rules Specification", | ||
@@ -10,7 +10,9 @@ "homepage": "https://github.com/koorchik/js-validator-livr", | ||
}, | ||
"license": "Artistic License 2.0", | ||
"license": "MIT", | ||
"main": "./lib/LIVR", | ||
"scripts": { | ||
"test": "mocha --timeout 6000 --ui qunit t/*.js", | ||
"build": "browserify -e scripts/browserify_entry.js -d -o dist/livr-debug.js; browserify -e scripts/browserify_entry.js | uglifyjs -o dist/livr-min.js;" | ||
"build:min": "webpack scripts/browser_build_entry.js -p -o dist/livr-min.js", | ||
"build:debug": "webpack scripts/browser_build_entry.js -d -o dist/livr-debug.js", | ||
"build": "npm run build:min && npm run build:debug" | ||
}, | ||
@@ -35,4 +37,5 @@ "repository": { | ||
"mocha": "^2.3.0", | ||
"uglify-js": "*" | ||
"webpack": "^4.1.1", | ||
"webpack-cli": "^2.0.12" | ||
} | ||
} |
@@ -83,3 +83,3 @@ # LIVR Validator | ||
Features: | ||
__Features:__ | ||
@@ -97,4 +97,9 @@ * Rules are declarative and language independent | ||
__You can find more rules in [livr-extra-rules](https://www.npmjs.com/package/livr-extra-rules)__ | ||
__JavaScript version extra features:__ | ||
* Zero dependencies | ||
* Works in NodeJs and in a browser | ||
* 3.6kb (min+gzip), 13kb (minified) | ||
* __You can find more rules in [livr-extra-rules](https://www.npmjs.com/package/livr-extra-rules)__ | ||
# INSTALL | ||
@@ -108,5 +113,5 @@ | ||
#### Browser | ||
#### Browser (if you do not use npm) | ||
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. | ||
You can find prebuilt browser 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. | ||
@@ -113,0 +118,0 @@ # CLASS METHODS |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
199748
0
100
0
274
1
5
3463