Comparing version 2.4.0 to 2.5.0
@@ -12,2 +12,13 @@ /* | ||
/***/ "./lib/BaseValidator.js": | ||
/*!******************************!*\ | ||
!*** ./lib/BaseValidator.js ***! | ||
\******************************/ | ||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { | ||
"use strict"; | ||
eval("\n\nconst util = __webpack_require__(/*! ./util */ \"./lib/util.js\");\n\nconst DEFAULT_RULES = {};\nlet IS_DEFAULT_AUTO_TRIM = 0;\n\nclass BaseValidator {\n constructor(livrRules, isAutoTrim) {\n this.isPrepared = false;\n this.livrRules = livrRules;\n this.validators = {};\n this.validatorBuilders = {};\n\n if (isAutoTrim !== null && isAutoTrim !== undefined) {\n this.isAutoTrim = isAutoTrim;\n } else {\n this.isAutoTrim = IS_DEFAULT_AUTO_TRIM;\n }\n\n this.registerRules(DEFAULT_RULES);\n }\n\n static getDefaultRules() {\n return DEFAULT_RULES;\n }\n\n static registerAliasedDefaultRule(alias) {\n if (!alias.name) throw 'Alias name required';\n\n DEFAULT_RULES[alias.name] = this.buildAliasedRule(alias.rules, alias.error);\n }\n\n static registerDefaultRules(rules) {\n for (const ruleName in rules) {\n DEFAULT_RULES[ruleName] = rules[ruleName];\n }\n }\n\n static defaultAutoTrim(isAutoTrim) {\n IS_DEFAULT_AUTO_TRIM = !!isAutoTrim;\n }\n\n prepare() {\n const allRules = this.livrRules;\n\n for (const field in allRules) {\n let fieldRules = allRules[field];\n\n if (!Array.isArray(fieldRules)) {\n fieldRules = [fieldRules];\n }\n\n const validators = [];\n\n for (const fieldRule of fieldRules) {\n const parsed = this._parseRule(fieldRule);\n validators.push(this._buildValidator(parsed.name, parsed.args));\n }\n\n this.validators[field] = validators;\n }\n\n this.isPrepared = true;\n return this;\n }\n\n registerRules(rules) {\n for (const ruleName in rules) {\n this.validatorBuilders[ruleName] = rules[ruleName];\n }\n\n return this;\n }\n\n registerAliasedRule(alias) {\n if (!alias.name) throw 'Alias name required';\n\n this.validatorBuilders[alias.name] = this.constructor.buildAliasedRule(\n alias.rules,\n alias.error\n );\n\n return this;\n }\n\n getRules() {\n return this.validatorBuilders;\n }\n\n _parseRule(livrRule) {\n let name;\n let args;\n\n if (util.isObject(livrRule)) {\n name = Object.keys(livrRule)[0];\n args = livrRule[name];\n\n if (!Array.isArray(args)) args = [args];\n } else {\n name = livrRule;\n args = [];\n }\n\n return { name, args };\n }\n\n _buildValidator(name, args) {\n if (!this.validatorBuilders[name]) {\n throw 'Rule [' + name + '] not registered';\n }\n\n const allArgs = [];\n\n allArgs.push.apply(allArgs, args);\n allArgs.push(this.getRules());\n\n return this.validatorBuilders[name].apply(null, allArgs);\n }\n\n _autoTrim(data) {\n const dataType = typeof data;\n\n if (dataType !== 'object' && data) {\n if (data.replace) {\n return data.replace(/^\\s*/, '').replace(/\\s*$/, '');\n } else {\n return data;\n }\n } else if (dataType == 'object' && Array.isArray(data)) {\n const trimmedData = [];\n\n for (const item of data) {\n trimmedData.push(this._autoTrim(item));\n }\n\n return trimmedData;\n } else if (dataType == 'object' && util.isObject(data)) {\n const trimmedData = {};\n\n for (const key in data) {\n if (data.hasOwnProperty(key)) {\n trimmedData[key] = this._autoTrim(data[key]);\n }\n }\n\n return trimmedData;\n }\n\n return data;\n }\n}\n\nmodule.exports = BaseValidator;\n\n\n//# sourceURL=webpack://livr/./lib/BaseValidator.js?"); | ||
/***/ }), | ||
/***/ "./lib/LIVR.js": | ||
@@ -19,3 +30,3 @@ /*!*********************!*\ | ||
eval("const Validator = __webpack_require__(/*! ./Validator */ \"./lib/Validator.js\");\nconst util = __webpack_require__(/*! ./util */ \"./lib/util.js\");\n\nconst rules = {\n required: __webpack_require__(/*! ./rules/common/required */ \"./lib/rules/common/required.js\"),\n not_empty: __webpack_require__(/*! ./rules/common/not_empty */ \"./lib/rules/common/not_empty.js\"),\n not_empty_list: __webpack_require__(/*! ./rules/common/not_empty_list */ \"./lib/rules/common/not_empty_list.js\"),\n any_object: __webpack_require__(/*! ./rules/common/any_object */ \"./lib/rules/common/any_object.js\"),\n\n string: __webpack_require__(/*! ./rules/string/string */ \"./lib/rules/string/string.js\"),\n eq: __webpack_require__(/*! ./rules/string/eq */ \"./lib/rules/string/eq.js\"),\n one_of: __webpack_require__(/*! ./rules/string/one_of */ \"./lib/rules/string/one_of.js\"),\n max_length: __webpack_require__(/*! ./rules/string/max_length */ \"./lib/rules/string/max_length.js\"),\n min_length: __webpack_require__(/*! ./rules/string/min_length */ \"./lib/rules/string/min_length.js\"),\n length_equal: __webpack_require__(/*! ./rules/string/length_equal */ \"./lib/rules/string/length_equal.js\"),\n length_between: __webpack_require__(/*! ./rules/string/length_between */ \"./lib/rules/string/length_between.js\"),\n like: __webpack_require__(/*! ./rules/string/like */ \"./lib/rules/string/like.js\"),\n\n integer: __webpack_require__(/*! ./rules/numeric/integer */ \"./lib/rules/numeric/integer.js\"),\n positive_integer: __webpack_require__(/*! ./rules/numeric/positive_integer */ \"./lib/rules/numeric/positive_integer.js\"),\n decimal: __webpack_require__(/*! ./rules/numeric/decimal */ \"./lib/rules/numeric/decimal.js\"),\n positive_decimal: __webpack_require__(/*! ./rules/numeric/positive_decimal */ \"./lib/rules/numeric/positive_decimal.js\"),\n max_number: __webpack_require__(/*! ./rules/numeric/max_number */ \"./lib/rules/numeric/max_number.js\"),\n min_number: __webpack_require__(/*! ./rules/numeric/min_number */ \"./lib/rules/numeric/min_number.js\"),\n number_between: __webpack_require__(/*! ./rules/numeric/number_between */ \"./lib/rules/numeric/number_between.js\"),\n\n email: __webpack_require__(/*! ./rules/special/email */ \"./lib/rules/special/email.js\"),\n equal_to_field: __webpack_require__(/*! ./rules/special/equal_to_field */ \"./lib/rules/special/equal_to_field.js\"),\n url: __webpack_require__(/*! ./rules/special/url */ \"./lib/rules/special/url.js\"),\n iso_date: __webpack_require__(/*! ./rules/special/iso_date */ \"./lib/rules/special/iso_date.js\"),\n\n nested_object: __webpack_require__(/*! ./rules/meta/nested_object */ \"./lib/rules/meta/nested_object.js\"),\n variable_object: __webpack_require__(/*! ./rules/meta/variable_object */ \"./lib/rules/meta/variable_object.js\"),\n list_of: __webpack_require__(/*! ./rules/meta/list_of */ \"./lib/rules/meta/list_of.js\"),\n list_of_objects: __webpack_require__(/*! ./rules/meta/list_of_objects */ \"./lib/rules/meta/list_of_objects.js\"),\n or: __webpack_require__(/*! ./rules/meta/or */ \"./lib/rules/meta/or.js\"),\n list_of_different_objects: __webpack_require__(/*! ./rules/meta/list_of_different_objects */ \"./lib/rules/meta/list_of_different_objects.js\"),\n\n default: __webpack_require__(/*! ./rules/modifiers/default */ \"./lib/rules/modifiers/default.js\"),\n trim: __webpack_require__(/*! ./rules/modifiers/trim */ \"./lib/rules/modifiers/trim.js\"),\n to_lc: __webpack_require__(/*! ./rules/modifiers/to_lc */ \"./lib/rules/modifiers/to_lc.js\"),\n to_uc: __webpack_require__(/*! ./rules/modifiers/to_uc */ \"./lib/rules/modifiers/to_uc.js\"),\n remove: __webpack_require__(/*! ./rules/modifiers/remove */ \"./lib/rules/modifiers/remove.js\"),\n leave_only: __webpack_require__(/*! ./rules/modifiers/leave_only */ \"./lib/rules/modifiers/leave_only.js\")\n};\n\nValidator.registerDefaultRules(rules);\n\nmodule.exports = { Validator, rules, util };\n\n\n//# sourceURL=webpack://livr/./lib/LIVR.js?"); | ||
eval("const Validator = __webpack_require__(/*! ./Validator */ \"./lib/Validator.js\");\nconst util = __webpack_require__(/*! ./util */ \"./lib/util.js\");\n\nconst rules = {\n required: __webpack_require__(/*! ./rules/common/required */ \"./lib/rules/common/required.js\"),\n not_empty: __webpack_require__(/*! ./rules/common/not_empty */ \"./lib/rules/common/not_empty.js\"),\n not_empty_list: __webpack_require__(/*! ./rules/common/not_empty_list */ \"./lib/rules/common/not_empty_list.js\"),\n any_object: __webpack_require__(/*! ./rules/common/any_object */ \"./lib/rules/common/any_object.js\"),\n\n string: __webpack_require__(/*! ./rules/string/string */ \"./lib/rules/string/string.js\"),\n eq: __webpack_require__(/*! ./rules/string/eq */ \"./lib/rules/string/eq.js\"),\n one_of: __webpack_require__(/*! ./rules/string/one_of */ \"./lib/rules/string/one_of.js\"),\n max_length: __webpack_require__(/*! ./rules/string/max_length */ \"./lib/rules/string/max_length.js\"),\n min_length: __webpack_require__(/*! ./rules/string/min_length */ \"./lib/rules/string/min_length.js\"),\n length_equal: __webpack_require__(/*! ./rules/string/length_equal */ \"./lib/rules/string/length_equal.js\"),\n length_between: __webpack_require__(/*! ./rules/string/length_between */ \"./lib/rules/string/length_between.js\"),\n like: __webpack_require__(/*! ./rules/string/like */ \"./lib/rules/string/like.js\"),\n\n integer: __webpack_require__(/*! ./rules/numeric/integer */ \"./lib/rules/numeric/integer.js\"),\n positive_integer: __webpack_require__(/*! ./rules/numeric/positive_integer */ \"./lib/rules/numeric/positive_integer.js\"),\n decimal: __webpack_require__(/*! ./rules/numeric/decimal */ \"./lib/rules/numeric/decimal.js\"),\n positive_decimal: __webpack_require__(/*! ./rules/numeric/positive_decimal */ \"./lib/rules/numeric/positive_decimal.js\"),\n max_number: __webpack_require__(/*! ./rules/numeric/max_number */ \"./lib/rules/numeric/max_number.js\"),\n min_number: __webpack_require__(/*! ./rules/numeric/min_number */ \"./lib/rules/numeric/min_number.js\"),\n number_between: __webpack_require__(/*! ./rules/numeric/number_between */ \"./lib/rules/numeric/number_between.js\"),\n\n email: __webpack_require__(/*! ./rules/special/email */ \"./lib/rules/special/email.js\"),\n equal_to_field: __webpack_require__(/*! ./rules/special/equal_to_field */ \"./lib/rules/special/equal_to_field.js\"),\n url: __webpack_require__(/*! ./rules/special/url */ \"./lib/rules/special/url.js\"),\n iso_date: __webpack_require__(/*! ./rules/special/iso_date */ \"./lib/rules/special/iso_date.js\"),\n\n default: __webpack_require__(/*! ./rules/modifiers/default */ \"./lib/rules/modifiers/default.js\"),\n trim: __webpack_require__(/*! ./rules/modifiers/trim */ \"./lib/rules/modifiers/trim.js\"),\n to_lc: __webpack_require__(/*! ./rules/modifiers/to_lc */ \"./lib/rules/modifiers/to_lc.js\"),\n to_uc: __webpack_require__(/*! ./rules/modifiers/to_uc */ \"./lib/rules/modifiers/to_uc.js\"),\n remove: __webpack_require__(/*! ./rules/modifiers/remove */ \"./lib/rules/modifiers/remove.js\"),\n leave_only: __webpack_require__(/*! ./rules/modifiers/leave_only */ \"./lib/rules/modifiers/leave_only.js\"),\n\n nested_object: __webpack_require__(/*! ./rules/meta/nested_object */ \"./lib/rules/meta/nested_object.js\"),\n variable_object: __webpack_require__(/*! ./rules/meta/variable_object */ \"./lib/rules/meta/variable_object.js\"),\n list_of: __webpack_require__(/*! ./rules/meta/list_of */ \"./lib/rules/meta/list_of.js\"),\n list_of_objects: __webpack_require__(/*! ./rules/meta/list_of_objects */ \"./lib/rules/meta/list_of_objects.js\"),\n or: __webpack_require__(/*! ./rules/meta/or */ \"./lib/rules/meta/or.js\"),\n list_of_different_objects: __webpack_require__(/*! ./rules/meta/list_of_different_objects */ \"./lib/rules/meta/list_of_different_objects.js\"),\n};\n\nValidator.registerDefaultRules(rules);\n\nmodule.exports = { Validator, rules, util };\n\n\n//# sourceURL=webpack://livr/./lib/LIVR.js?"); | ||
@@ -31,3 +42,3 @@ /***/ }), | ||
"use strict"; | ||
eval("\n\nconst util = __webpack_require__(/*! ./util */ \"./lib/util.js\");\n\nconst DEFAULT_RULES = {};\nlet IS_DEFAULT_AUTO_TRIM = 0;\n\nclass Validator {\n constructor(livrRules, isAutoTrim) {\n this.isPrepared = false;\n this.livrRules = livrRules;\n this.validators = {};\n this.validatorBuilders = {};\n this.errors = null;\n\n if (isAutoTrim !== null && isAutoTrim !== undefined) {\n this.isAutoTrim = isAutoTrim;\n } else {\n this.isAutoTrim = IS_DEFAULT_AUTO_TRIM;\n }\n\n this.registerRules(DEFAULT_RULES);\n }\n\n static getDefaultRules() {\n return DEFAULT_RULES;\n }\n\n static registerAliasedDefaultRule(alias) {\n if (!alias.name) throw 'Alias name required';\n\n DEFAULT_RULES[alias.name] = this._buildAliasedRule(alias.rules, alias.error);\n }\n\n static registerDefaultRules(rules) {\n for (const ruleName in rules) {\n DEFAULT_RULES[ruleName] = rules[ruleName];\n }\n }\n\n static defaultAutoTrim(isAutoTrim) {\n IS_DEFAULT_AUTO_TRIM = !!isAutoTrim;\n }\n\n static _buildAliasedRule(rules, errorCode) {\n if (!rules) throw 'Alias rules required';\n\n const livr = { value: rules };\n\n return ruleBuilders => {\n // ruleBuilders comes always as a last argument\n // we register them to support custom rules in aliases\n const validator = new Validator(livr).registerRules(ruleBuilders).prepare();\n\n return (value, undefined, outputArr) => {\n const result = validator.validate({ value });\n\n if (result) {\n outputArr.push(result.value);\n return;\n } else {\n return errorCode || validator.getErrors().value;\n }\n };\n };\n }\n\n prepare() {\n const allRules = this.livrRules;\n\n for (const field in allRules) {\n let fieldRules = allRules[field];\n\n if (!Array.isArray(fieldRules)) {\n fieldRules = [fieldRules];\n }\n\n const validators = [];\n\n for (const fieldRule of fieldRules) {\n const parsed = this._parseRule(fieldRule);\n validators.push(this._buildValidator(parsed.name, parsed.args));\n }\n\n this.validators[field] = validators;\n }\n\n this.isPrepared = true;\n return this;\n }\n\n validate(data) {\n if (!this.isPrepared) this.prepare();\n\n if (!util.isObject(data)) {\n this.errors = 'FORMAT_ERROR';\n return;\n }\n\n if (this.isAutoTrim) {\n data = this._autoTrim(data);\n }\n\n const errors = {};\n const result = {};\n\n for (const fieldName in this.validators) {\n const validators = this.validators[fieldName];\n if (!validators || !validators.length) continue;\n\n const value = data[fieldName];\n\n for (const validator of validators) {\n const fieldResultArr = [];\n\n const errCode = validator(\n result.hasOwnProperty(fieldName) ? result[fieldName] : value,\n data,\n fieldResultArr\n );\n\n if (errCode) {\n errors[fieldName] = errCode;\n break;\n } else if (fieldResultArr.length) {\n result[fieldName] = fieldResultArr[0];\n } else if (data.hasOwnProperty(fieldName) && !result.hasOwnProperty(fieldName)) {\n result[fieldName] = value;\n }\n }\n }\n\n if (util.isEmptyObject(errors)) {\n this.errors = null;\n return result;\n } else {\n this.errors = errors;\n return false;\n }\n }\n\n getErrors() {\n return this.errors;\n }\n\n registerRules(rules) {\n for (const ruleName in rules) {\n this.validatorBuilders[ruleName] = rules[ruleName];\n }\n\n return this;\n }\n\n registerAliasedRule(alias) {\n if (!alias.name) throw 'Alias name required';\n\n this.validatorBuilders[alias.name] = this.constructor._buildAliasedRule(\n alias.rules,\n alias.error\n );\n\n return this;\n }\n\n getRules() {\n return this.validatorBuilders;\n }\n\n _parseRule(livrRule) {\n let name;\n let args;\n\n if (util.isObject(livrRule)) {\n name = Object.keys(livrRule)[0];\n args = livrRule[name];\n\n if (!Array.isArray(args)) args = [args];\n } else {\n name = livrRule;\n args = [];\n }\n\n return { name, args };\n }\n\n _buildValidator(name, args) {\n if (!this.validatorBuilders[name]) {\n throw 'Rule [' + name + '] not registered';\n }\n\n const allArgs = [];\n\n allArgs.push.apply(allArgs, args);\n allArgs.push(this.getRules());\n\n return this.validatorBuilders[name].apply(null, allArgs);\n }\n\n _autoTrim(data) {\n const dataType = typeof data;\n\n if (dataType !== 'object' && data) {\n if (data.replace) {\n return data.replace(/^\\s*/, '').replace(/\\s*$/, '');\n } else {\n return data;\n }\n } else if (dataType == 'object' && Array.isArray(data)) {\n const trimmedData = [];\n\n for (const item of data) {\n trimmedData.push(this._autoTrim(item));\n }\n\n return trimmedData;\n } else if (dataType == 'object' && util.isObject(data)) {\n const trimmedData = {};\n\n for (const key in data) {\n if (data.hasOwnProperty(key)) {\n trimmedData[key] = this._autoTrim(data[key]);\n }\n }\n\n return trimmedData;\n }\n\n return data;\n }\n}\n\nmodule.exports = Validator;\n\n\n//# sourceURL=webpack://livr/./lib/Validator.js?"); | ||
eval("\n\nconst BaseValidator = __webpack_require__(/*! ./BaseValidator */ \"./lib/BaseValidator.js\");\nconst util = __webpack_require__(/*! ./util */ \"./lib/util.js\");\n\nconst DEFAULT_RULES = {};\nlet IS_DEFAULT_AUTO_TRIM = 0;\n\nclass Validator extends BaseValidator {\n constructor(...args) {\n super(...args);\n this.errors = null;\n }\n\n static buildAliasedRule(rules, errorCode) {\n if (!rules) throw 'Alias rules required';\n\n const livr = { value: rules };\n\n return ruleBuilders => {\n // ruleBuilders comes always as a last argument\n // we register them to support custom rules in aliases\n const validator = new Validator(livr).registerRules(ruleBuilders).prepare();\n\n return (value, undefined, outputArr) => {\n const result = validator.validate({ value });\n\n if (result) {\n outputArr.push(result.value);\n return;\n } else {\n return errorCode || validator.getErrors().value;\n }\n };\n };\n }\n\n validate(data) {\n if (!this.isPrepared) this.prepare();\n\n if (!util.isObject(data)) {\n this.errors = 'FORMAT_ERROR';\n return;\n }\n\n if (this.isAutoTrim) {\n data = this._autoTrim(data);\n }\n\n const errors = {};\n const result = {};\n\n for (const fieldName in this.validators) {\n const validators = this.validators[fieldName];\n if (!validators || !validators.length) continue;\n\n const value = data[fieldName];\n\n for (const validator of validators) {\n const fieldResultArr = [];\n\n const errCode = validator(\n result.hasOwnProperty(fieldName) ? result[fieldName] : value,\n data,\n fieldResultArr\n );\n\n if (errCode) {\n errors[fieldName] = errCode;\n break;\n } else if (fieldResultArr.length) {\n result[fieldName] = fieldResultArr[0];\n } else if (data.hasOwnProperty(fieldName) && !result.hasOwnProperty(fieldName)) {\n result[fieldName] = value;\n }\n }\n }\n\n if (util.isEmptyObject(errors)) {\n this.errors = null;\n return result;\n } else {\n this.errors = errors;\n return false;\n }\n }\n\n getErrors() {\n return this.errors;\n }\n}\n\nmodule.exports = Validator;\n\n\n//# sourceURL=webpack://livr/./lib/Validator.js?"); | ||
@@ -396,9 +407,9 @@ /***/ }), | ||
/***/ "./scripts/browser_build_entry.js": | ||
/*!****************************************!*\ | ||
!*** ./scripts/browser_build_entry.js ***! | ||
\****************************************/ | ||
/***/ "./scripts/browser_build_entry-sync.js": | ||
/*!*********************************************!*\ | ||
!*** ./scripts/browser_build_entry-sync.js ***! | ||
\*********************************************/ | ||
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { | ||
eval("window.LIVR = __webpack_require__(/*! ../lib/LIVR */ \"./lib/LIVR.js\");\n\n\n//# sourceURL=webpack://livr/./scripts/browser_build_entry.js?"); | ||
eval("window.LIVR = __webpack_require__(/*! ../lib/LIVR */ \"./lib/LIVR.js\");\n\n\n//# sourceURL=webpack://livr/./scripts/browser_build_entry-sync.js?"); | ||
@@ -438,5 +449,5 @@ /***/ }) | ||
/******/ // This entry module can't be inlined because the eval devtool is used. | ||
/******/ var __webpack_exports__ = __webpack_require__("./scripts/browser_build_entry.js"); | ||
/******/ var __webpack_exports__ = __webpack_require__("./scripts/browser_build_entry-sync.js"); | ||
/******/ | ||
/******/ })() | ||
; |
@@ -1,1 +0,1 @@ | ||
(()=>{var e={601:(e,t,r)=>{const i=r(388),s=r(502),o={required:r(568),not_empty:r(233),not_empty_list:r(956),any_object:r(41),string:r(320),eq:r(10),one_of:r(594),max_length:r(240),min_length:r(932),length_equal:r(402),length_between:r(973),like:r(0),integer:r(238),positive_integer:r(266),decimal:r(814),positive_decimal:r(105),max_number:r(903),min_number:r(118),number_between:r(531),email:r(35),equal_to_field:r(123),url:r(842),iso_date:r(168),nested_object:r(421),variable_object:r(770),list_of:r(794),list_of_objects:r(637),or:r(532),list_of_different_objects:r(93),default:r(33),trim:r(227),to_lc:r(828),to_uc:r(831),remove:r(439),leave_only:r(77)};i.registerDefaultRules(o),e.exports={Validator:i,rules:o,util:s}},388:(e,t,r)=>{"use strict";const i=r(502),s={};let o=0;class n{constructor(e,t){this.isPrepared=!1,this.livrRules=e,this.validators={},this.validatorBuilders={},this.errors=null,this.isAutoTrim=null!=t?t:o,this.registerRules(s)}static getDefaultRules(){return s}static registerAliasedDefaultRule(e){if(!e.name)throw"Alias name required";s[e.name]=this._buildAliasedRule(e.rules,e.error)}static registerDefaultRules(e){for(const t in e)s[t]=e[t]}static defaultAutoTrim(e){o=!!e}static _buildAliasedRule(e,t){if(!e)throw"Alias rules required";const r={value:e};return e=>{const i=new n(r).registerRules(e).prepare();return(e,r,s)=>{const o=i.validate({value:e});return o?void s.push(o.value):t||i.getErrors().value}}}prepare(){const e=this.livrRules;for(const t in e){let r=e[t];Array.isArray(r)||(r=[r]);const i=[];for(const e of r){const t=this._parseRule(e);i.push(this._buildValidator(t.name,t.args))}this.validators[t]=i}return this.isPrepared=!0,this}validate(e){if(this.isPrepared||this.prepare(),!i.isObject(e))return void(this.errors="FORMAT_ERROR");this.isAutoTrim&&(e=this._autoTrim(e));const t={},r={};for(const i in this.validators){const s=this.validators[i];if(!s||!s.length)continue;const o=e[i];for(const n of s){const s=[],u=n(r.hasOwnProperty(i)?r[i]:o,e,s);if(u){t[i]=u;break}s.length?r[i]=s[0]:e.hasOwnProperty(i)&&!r.hasOwnProperty(i)&&(r[i]=o)}}return i.isEmptyObject(t)?(this.errors=null,r):(this.errors=t,!1)}getErrors(){return this.errors}registerRules(e){for(const t in e)this.validatorBuilders[t]=e[t];return this}registerAliasedRule(e){if(!e.name)throw"Alias name required";return this.validatorBuilders[e.name]=this.constructor._buildAliasedRule(e.rules,e.error),this}getRules(){return this.validatorBuilders}_parseRule(e){let t,r;return i.isObject(e)?(t=Object.keys(e)[0],r=e[t],Array.isArray(r)||(r=[r])):(t=e,r=[]),{name:t,args:r}}_buildValidator(e,t){if(!this.validatorBuilders[e])throw"Rule ["+e+"] not registered";const r=[];return r.push.apply(r,t),r.push(this.getRules()),this.validatorBuilders[e].apply(null,r)}_autoTrim(e){const t=typeof e;if("object"!==t&&e)return e.replace?e.replace(/^\s*/,"").replace(/\s*$/,""):e;if("object"==t&&Array.isArray(e)){const t=[];for(const r of e)t.push(this._autoTrim(r));return t}if("object"==t&&i.isObject(e)){const t={};for(const r in e)e.hasOwnProperty(r)&&(t[r]=this._autoTrim(e[r]));return t}return e}}e.exports=n},41:(e,t,r)=>{const i=r(502);e.exports=function(){return e=>{if(!i.isNoValue(e))return i.isObject(e)?void 0:"FORMAT_ERROR"}}},233:e=>{e.exports=function(){return e=>{if(null!=e&&""===e)return"CANNOT_BE_EMPTY"}}},956:e=>{e.exports=function(){return e=>void 0===e||""===e?"CANNOT_BE_EMPTY":Array.isArray(e)?e.length<1?"CANNOT_BE_EMPTY":void 0:"FORMAT_ERROR"}},568:(e,t,r)=>{const i=r(502);e.exports=function(){return e=>{if(i.isNoValue(e))return"REQUIRED"}}},794:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t){Array.isArray(e)||(t=(e=Array.prototype.slice.call(arguments)).pop());const r={field:e},o=new i(r).registerRules(t).prepare();return(e,t,r)=>{if(s.isNoValue(e))return;if(!Array.isArray(e))return"FORMAT_ERROR";const i=[],n=[];let u=!1;for(const t of e){const e=o.validate({field:t});e?(i.push(e.field),n.push(null)):(u=!0,n.push(o.getErrors().field),i.push(null))}return u?n:void r.push(i)}}},93:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t,r){const o={};for(const e in t){const s=new i(t[e]).registerRules(r).prepare();o[e]=s}return(t,r,i)=>{if(s.isNoValue(t))return;if(!Array.isArray(t))return"FORMAT_ERROR";const n=[],u=[];let l=!1;for(const r of t){if("object"!=typeof r||!r[e]||!o[r[e]]){u.push("FORMAT_ERROR");continue}const t=o[r[e]],i=t.validate(r);i?(n.push(i),u.push(null)):(l=!0,u.push(t.getErrors()),n.push(null))}return l?u:void i.push(n)}}},637:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t){const r=new i(e).registerRules(t).prepare();return(e,t,i)=>{if(s.isNoValue(e))return;if(!Array.isArray(e))return"FORMAT_ERROR";const o=[],n=[];let u=!1;for(const t of e){const e=r.validate(t);e?(o.push(e),n.push(null)):(u=!0,n.push(r.getErrors()),o.push(null))}return u?n:void i.push(o)}}},421:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t){const r=new i(e).registerRules(t).prepare();return(e,t,i)=>{if(s.isNoValue(e))return;if(!s.isObject(e))return"FORMAT_ERROR";const o=r.validate(e);return o?void i.push(o):r.getErrors()}}},532:(e,t,r)=>{const i=r(388);e.exports=function(){const e=Array.prototype.slice.call(arguments),t=e.pop(),r=e.map((e=>new i({field:e}).registerRules(t).prepare()));return(e,t,i)=>{let s;for(const t of r){const r=t.validate({field:e});if(r)return void i.push(r.field);s=t.getErrors().field}return s}}},770:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t,r){const o={};for(const e in t){const s=new i(t[e]).registerRules(r).prepare();o[e]=s}return(t,r,i)=>{if(s.isNoValue(t))return;if(!s.isObject(t)||!t[e]||!o[t[e]])return"FORMAT_ERROR";const n=o[t[e]],u=n.validate(t);return u?void i.push(u):n.getErrors()}}},33:(e,t,r)=>{const i=r(502);e.exports=e=>(t,r,s)=>{i.isNoValue(t)&&s.push(e)}},77:(e,t,r)=>{const i=r(502);e.exports=function(e){e=i.escapeRegExp(e);const t=new RegExp("[^"+e+"]","g");return(e,r,s)=>{i.isNoValue(e)||"object"==typeof e||(e+="",s.push(e.replace(t,"")))}}},439:(e,t,r)=>{const i=r(502);e.exports=function(e){e=i.escapeRegExp(e);const t=new RegExp("["+e+"]","g");return(e,r,s)=>{i.isNoValue(e)||"object"==typeof e||(e+="",s.push(e.replace(t,"")))}}},828:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{i.isNoValue(e)||"object"==typeof e||(e+="",r.push(e.toLowerCase()))}}},831:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{i.isNoValue(e)||"object"==typeof e||(e+="",r.push(e.toUpperCase()))}}},227:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{i.isNoValue(e)||"object"==typeof e||(e+="",r.push(e.replace(/^\s*/,"").replace(/\s*$/,"")))}}},814:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e)){if(!i.isPrimitiveValue(e))return"FORMAT_ERROR";if(!i.looksLikeNumber(e))return"NOT_DECIMAL";if(!/^(?:\-?(?:(?:[0-9]+\.[0-9]+)|(?:[0-9]+)))$/.test(e+=""))return"NOT_DECIMAL";r.push(+e)}}}},238:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?i.looksLikeNumber(e)&&Number.isInteger(+e)?void r.push(+e):"NOT_INTEGER":"FORMAT_ERROR"}}},903:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?i.looksLikeNumber(t)?+t>+e?"TOO_HIGH":void s.push(+t):"NOT_NUMBER":"FORMAT_ERROR"}}},118:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?i.looksLikeNumber(t)?+t<+e?"TOO_LOW":void s.push(+t):"NOT_NUMBER":"FORMAT_ERROR"}}},531:(e,t,r)=>{const i=r(502);e.exports=function(e,t){return(r,s,o)=>{if(!i.isNoValue(r))return i.isPrimitiveValue(r)?i.looksLikeNumber(r)?+r<+e?"TOO_LOW":+r>+t?"TOO_HIGH":void o.push(+r):"NOT_NUMBER":"FORMAT_ERROR"}}},105:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?i.looksLikeNumber(e)?Number.isNaN(+e)||+e<=0?"NOT_POSITIVE_DECIMAL":void r.push(+e):"NOT_POSITIVE_DECIMAL":"FORMAT_ERROR"}}},266:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?i.looksLikeNumber(e)?!Number.isInteger(+e)||+e<1?"NOT_POSITIVE_INTEGER":void r.push(+e):"NOT_POSITIVE_INTEGER":"FORMAT_ERROR"}}},35:(e,t,r)=>{const i=r(502);e.exports=function(){var e=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return t=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?(t+="",e.test(t)?/\@.*\@/.test(t)||/\@.*_/.test(t)?"WRONG_EMAIL":void 0:"WRONG_EMAIL"):"FORMAT_ERROR"}}},123:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?t!=r[e]?"FIELDS_NOT_EQUAL":void 0:"FORMAT_ERROR"}}},168:(e,t,r)=>{const i=r(502);e.exports=function(){return e=>{if(i.isNoValue(e))return;if(!i.isPrimitiveValue(e))return"FORMAT_ERROR";const t=e.match(/^(\d{4})-([0-1][0-9])-([0-3][0-9])$/);if(t){const r=Date.parse(e);if(!r&&0!==r)return"WRONG_DATE";const i=new Date(r);if(i.setTime(i.getTime()+60*i.getTimezoneOffset()*1e3),i.getFullYear()==t[1]&&i.getMonth()+1==+t[2]&&i.getDate()==+t[3])return}return"WRONG_DATE"}}},842:(e,t,r)=>{const i=r(502);e.exports=function(){const 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 t=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if(!(t.length<2083&&e.test(t)))return"WRONG_URL"}}}},10:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if(t+""!=e+"")return"NOT_ALLOWED_VALUE";s.push(e)}}}},973:(e,t,r)=>{const i=r(502);e.exports=function(e,t){return(r,s,o)=>{if(!i.isNoValue(r))return i.isPrimitiveValue(r)?(r+="").length<e?"TOO_SHORT":r.length>t?"TOO_LONG":void o.push(r):"FORMAT_ERROR"}}},402:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?(t+="").length<e?"TOO_SHORT":t.length>e?"TOO_LONG":void s.push(t):"FORMAT_ERROR"}}},0:(e,t,r)=>{const i=r(502);e.exports=function(e,t){const r=3===arguments.length&&t.match("i"),s=new RegExp(e,r?"i":"");return(e,t,r)=>{if(!i.isNoValue(e)){if(!i.isPrimitiveValue(e))return"FORMAT_ERROR";if(!(e+="").match(s))return"WRONG_FORMAT";r.push(e)}}}},240:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if((t+="").length>e)return"TOO_LONG";s.push(t)}}}},932:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if((t+="").length<e)return"TOO_SHORT";s.push(t)}}}},594:(e,t,r)=>{const i=r(502);e.exports=function(e){return Array.isArray(e)||(e=Array.prototype.slice.call(arguments)).pop(),(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";for(const r of e)if(t+""==r+"")return void s.push(r);return"NOT_ALLOWED_VALUE"}}}},320:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?void r.push(e+""):"FORMAT_ERROR"}}},502:e=>{e.exports={isPrimitiveValue:e=>"string"==typeof e||!("number"!=typeof e||!isFinite(e))||"boolean"==typeof e,looksLikeNumber:e=>!isNaN(+e),isObject:e=>Object(e)===e&&Object.getPrototypeOf(e)===Object.prototype,isEmptyObject(e){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0},escapeRegExp:e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),isNoValue:e=>null==e||""===e}}},t={};window.LIVR=function r(i){var s=t[i];if(void 0!==s)return s.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,r),o.exports}(601)})(); | ||
(()=>{var e={866:(e,t,r)=>{"use strict";const i=r(502),s={};let o=0;e.exports=class{constructor(e,t){this.isPrepared=!1,this.livrRules=e,this.validators={},this.validatorBuilders={},this.isAutoTrim=null!=t?t:o,this.registerRules(s)}static getDefaultRules(){return s}static registerAliasedDefaultRule(e){if(!e.name)throw"Alias name required";s[e.name]=this.buildAliasedRule(e.rules,e.error)}static registerDefaultRules(e){for(const t in e)s[t]=e[t]}static defaultAutoTrim(e){o=!!e}prepare(){const e=this.livrRules;for(const t in e){let r=e[t];Array.isArray(r)||(r=[r]);const i=[];for(const e of r){const t=this._parseRule(e);i.push(this._buildValidator(t.name,t.args))}this.validators[t]=i}return this.isPrepared=!0,this}registerRules(e){for(const t in e)this.validatorBuilders[t]=e[t];return this}registerAliasedRule(e){if(!e.name)throw"Alias name required";return this.validatorBuilders[e.name]=this.constructor.buildAliasedRule(e.rules,e.error),this}getRules(){return this.validatorBuilders}_parseRule(e){let t,r;return i.isObject(e)?(t=Object.keys(e)[0],r=e[t],Array.isArray(r)||(r=[r])):(t=e,r=[]),{name:t,args:r}}_buildValidator(e,t){if(!this.validatorBuilders[e])throw"Rule ["+e+"] not registered";const r=[];return r.push.apply(r,t),r.push(this.getRules()),this.validatorBuilders[e].apply(null,r)}_autoTrim(e){const t=typeof e;if("object"!==t&&e)return e.replace?e.replace(/^\s*/,"").replace(/\s*$/,""):e;if("object"==t&&Array.isArray(e)){const t=[];for(const r of e)t.push(this._autoTrim(r));return t}if("object"==t&&i.isObject(e)){const t={};for(const r in e)e.hasOwnProperty(r)&&(t[r]=this._autoTrim(e[r]));return t}return e}}},601:(e,t,r)=>{const i=r(388),s=r(502),o={required:r(568),not_empty:r(233),not_empty_list:r(956),any_object:r(41),string:r(320),eq:r(10),one_of:r(594),max_length:r(240),min_length:r(932),length_equal:r(402),length_between:r(973),like:r(0),integer:r(238),positive_integer:r(266),decimal:r(814),positive_decimal:r(105),max_number:r(903),min_number:r(118),number_between:r(531),email:r(35),equal_to_field:r(123),url:r(842),iso_date:r(168),default:r(33),trim:r(227),to_lc:r(828),to_uc:r(831),remove:r(439),leave_only:r(77),nested_object:r(421),variable_object:r(770),list_of:r(794),list_of_objects:r(637),or:r(532),list_of_different_objects:r(93)};i.registerDefaultRules(o),e.exports={Validator:i,rules:o,util:s}},388:(e,t,r)=>{"use strict";const i=r(866),s=r(502);class o extends i{constructor(...e){super(...e),this.errors=null}static buildAliasedRule(e,t){if(!e)throw"Alias rules required";const r={value:e};return e=>{const i=new o(r).registerRules(e).prepare();return(e,r,s)=>{const o=i.validate({value:e});return o?void s.push(o.value):t||i.getErrors().value}}}validate(e){if(this.isPrepared||this.prepare(),!s.isObject(e))return void(this.errors="FORMAT_ERROR");this.isAutoTrim&&(e=this._autoTrim(e));const t={},r={};for(const i in this.validators){const s=this.validators[i];if(!s||!s.length)continue;const o=e[i];for(const n of s){const s=[],u=n(r.hasOwnProperty(i)?r[i]:o,e,s);if(u){t[i]=u;break}s.length?r[i]=s[0]:e.hasOwnProperty(i)&&!r.hasOwnProperty(i)&&(r[i]=o)}}return s.isEmptyObject(t)?(this.errors=null,r):(this.errors=t,!1)}getErrors(){return this.errors}}e.exports=o},41:(e,t,r)=>{const i=r(502);e.exports=function(){return e=>{if(!i.isNoValue(e))return i.isObject(e)?void 0:"FORMAT_ERROR"}}},233:e=>{e.exports=function(){return e=>{if(null!=e&&""===e)return"CANNOT_BE_EMPTY"}}},956:e=>{e.exports=function(){return e=>void 0===e||""===e?"CANNOT_BE_EMPTY":Array.isArray(e)?e.length<1?"CANNOT_BE_EMPTY":void 0:"FORMAT_ERROR"}},568:(e,t,r)=>{const i=r(502);e.exports=function(){return e=>{if(i.isNoValue(e))return"REQUIRED"}}},794:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t){Array.isArray(e)||(t=(e=Array.prototype.slice.call(arguments)).pop());const r={field:e},o=new i(r).registerRules(t).prepare();return(e,t,r)=>{if(s.isNoValue(e))return;if(!Array.isArray(e))return"FORMAT_ERROR";const i=[],n=[];let u=!1;for(const t of e){const e=o.validate({field:t});e?(i.push(e.field),n.push(null)):(u=!0,n.push(o.getErrors().field),i.push(null))}return u?n:void r.push(i)}}},93:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t,r){const o={};for(const e in t){const s=new i(t[e]).registerRules(r).prepare();o[e]=s}return(t,r,i)=>{if(s.isNoValue(t))return;if(!Array.isArray(t))return"FORMAT_ERROR";const n=[],u=[];let l=!1;for(const r of t){if("object"!=typeof r||!r[e]||!o[r[e]]){u.push("FORMAT_ERROR");continue}const t=o[r[e]],i=t.validate(r);i?(n.push(i),u.push(null)):(l=!0,u.push(t.getErrors()),n.push(null))}return l?u:void i.push(n)}}},637:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t){const r=new i(e).registerRules(t).prepare();return(e,t,i)=>{if(s.isNoValue(e))return;if(!Array.isArray(e))return"FORMAT_ERROR";const o=[],n=[];let u=!1;for(const t of e){const e=r.validate(t);e?(o.push(e),n.push(null)):(u=!0,n.push(r.getErrors()),o.push(null))}return u?n:void i.push(o)}}},421:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t){const r=new i(e).registerRules(t).prepare();return(e,t,i)=>{if(s.isNoValue(e))return;if(!s.isObject(e))return"FORMAT_ERROR";const o=r.validate(e);return o?void i.push(o):r.getErrors()}}},532:(e,t,r)=>{const i=r(388);e.exports=function(){const e=Array.prototype.slice.call(arguments),t=e.pop(),r=e.map((e=>new i({field:e}).registerRules(t).prepare()));return(e,t,i)=>{let s;for(const t of r){const r=t.validate({field:e});if(r)return void i.push(r.field);s=t.getErrors().field}return s}}},770:(e,t,r)=>{const i=r(388),s=r(502);e.exports=function(e,t,r){const o={};for(const e in t){const s=new i(t[e]).registerRules(r).prepare();o[e]=s}return(t,r,i)=>{if(s.isNoValue(t))return;if(!s.isObject(t)||!t[e]||!o[t[e]])return"FORMAT_ERROR";const n=o[t[e]],u=n.validate(t);return u?void i.push(u):n.getErrors()}}},33:(e,t,r)=>{const i=r(502);e.exports=e=>(t,r,s)=>{i.isNoValue(t)&&s.push(e)}},77:(e,t,r)=>{const i=r(502);e.exports=function(e){e=i.escapeRegExp(e);const t=new RegExp("[^"+e+"]","g");return(e,r,s)=>{i.isNoValue(e)||"object"==typeof e||(e+="",s.push(e.replace(t,"")))}}},439:(e,t,r)=>{const i=r(502);e.exports=function(e){e=i.escapeRegExp(e);const t=new RegExp("["+e+"]","g");return(e,r,s)=>{i.isNoValue(e)||"object"==typeof e||(e+="",s.push(e.replace(t,"")))}}},828:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{i.isNoValue(e)||"object"==typeof e||(e+="",r.push(e.toLowerCase()))}}},831:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{i.isNoValue(e)||"object"==typeof e||(e+="",r.push(e.toUpperCase()))}}},227:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{i.isNoValue(e)||"object"==typeof e||(e+="",r.push(e.replace(/^\s*/,"").replace(/\s*$/,"")))}}},814:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e)){if(!i.isPrimitiveValue(e))return"FORMAT_ERROR";if(!i.looksLikeNumber(e))return"NOT_DECIMAL";if(!/^(?:\-?(?:(?:[0-9]+\.[0-9]+)|(?:[0-9]+)))$/.test(e+=""))return"NOT_DECIMAL";r.push(+e)}}}},238:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?i.looksLikeNumber(e)&&Number.isInteger(+e)?void r.push(+e):"NOT_INTEGER":"FORMAT_ERROR"}}},903:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?i.looksLikeNumber(t)?+t>+e?"TOO_HIGH":void s.push(+t):"NOT_NUMBER":"FORMAT_ERROR"}}},118:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?i.looksLikeNumber(t)?+t<+e?"TOO_LOW":void s.push(+t):"NOT_NUMBER":"FORMAT_ERROR"}}},531:(e,t,r)=>{const i=r(502);e.exports=function(e,t){return(r,s,o)=>{if(!i.isNoValue(r))return i.isPrimitiveValue(r)?i.looksLikeNumber(r)?+r<+e?"TOO_LOW":+r>+t?"TOO_HIGH":void o.push(+r):"NOT_NUMBER":"FORMAT_ERROR"}}},105:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?i.looksLikeNumber(e)?Number.isNaN(+e)||+e<=0?"NOT_POSITIVE_DECIMAL":void r.push(+e):"NOT_POSITIVE_DECIMAL":"FORMAT_ERROR"}}},266:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?i.looksLikeNumber(e)?!Number.isInteger(+e)||+e<1?"NOT_POSITIVE_INTEGER":void r.push(+e):"NOT_POSITIVE_INTEGER":"FORMAT_ERROR"}}},35:(e,t,r)=>{const i=r(502);e.exports=function(){var e=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return t=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?(t+="",e.test(t)?/\@.*\@/.test(t)||/\@.*_/.test(t)?"WRONG_EMAIL":void 0:"WRONG_EMAIL"):"FORMAT_ERROR"}}},123:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?t!=r[e]?"FIELDS_NOT_EQUAL":void 0:"FORMAT_ERROR"}}},168:(e,t,r)=>{const i=r(502);e.exports=function(){return e=>{if(i.isNoValue(e))return;if(!i.isPrimitiveValue(e))return"FORMAT_ERROR";const t=e.match(/^(\d{4})-([0-1][0-9])-([0-3][0-9])$/);if(t){const r=Date.parse(e);if(!r&&0!==r)return"WRONG_DATE";const i=new Date(r);if(i.setTime(i.getTime()+60*i.getTimezoneOffset()*1e3),i.getFullYear()==t[1]&&i.getMonth()+1==+t[2]&&i.getDate()==+t[3])return}return"WRONG_DATE"}}},842:(e,t,r)=>{const i=r(502);e.exports=function(){const 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 t=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if(!(t.length<2083&&e.test(t)))return"WRONG_URL"}}}},10:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if(t+""!=e+"")return"NOT_ALLOWED_VALUE";s.push(e)}}}},973:(e,t,r)=>{const i=r(502);e.exports=function(e,t){return(r,s,o)=>{if(!i.isNoValue(r))return i.isPrimitiveValue(r)?(r+="").length<e?"TOO_SHORT":r.length>t?"TOO_LONG":void o.push(r):"FORMAT_ERROR"}}},402:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t))return i.isPrimitiveValue(t)?(t+="").length<e?"TOO_SHORT":t.length>e?"TOO_LONG":void s.push(t):"FORMAT_ERROR"}}},0:(e,t,r)=>{const i=r(502);e.exports=function(e,t){const r=3===arguments.length&&t.match("i"),s=new RegExp(e,r?"i":"");return(e,t,r)=>{if(!i.isNoValue(e)){if(!i.isPrimitiveValue(e))return"FORMAT_ERROR";if(!(e+="").match(s))return"WRONG_FORMAT";r.push(e)}}}},240:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if((t+="").length>e)return"TOO_LONG";s.push(t)}}}},932:(e,t,r)=>{const i=r(502);e.exports=function(e){return(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";if((t+="").length<e)return"TOO_SHORT";s.push(t)}}}},594:(e,t,r)=>{const i=r(502);e.exports=function(e){return Array.isArray(e)||(e=Array.prototype.slice.call(arguments)).pop(),(t,r,s)=>{if(!i.isNoValue(t)){if(!i.isPrimitiveValue(t))return"FORMAT_ERROR";for(const r of e)if(t+""==r+"")return void s.push(r);return"NOT_ALLOWED_VALUE"}}}},320:(e,t,r)=>{const i=r(502);e.exports=function(){return(e,t,r)=>{if(!i.isNoValue(e))return i.isPrimitiveValue(e)?void r.push(e+""):"FORMAT_ERROR"}}},502:e=>{e.exports={isPrimitiveValue:e=>"string"==typeof e||!("number"!=typeof e||!isFinite(e))||"boolean"==typeof e,looksLikeNumber:e=>!isNaN(+e),isObject:e=>Object(e)===e&&Object.getPrototypeOf(e)===Object.prototype,isEmptyObject(e){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0},escapeRegExp:e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),isNoValue:e=>null==e||""===e}}},t={};window.LIVR=function r(i){var s=t[i];if(void 0!==s)return s.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,r),o.exports}(601)})(); |
@@ -32,2 +32,9 @@ const Validator = require('./Validator'); | ||
default: require('./rules/modifiers/default'), | ||
trim: require('./rules/modifiers/trim'), | ||
to_lc: require('./rules/modifiers/to_lc'), | ||
to_uc: require('./rules/modifiers/to_uc'), | ||
remove: require('./rules/modifiers/remove'), | ||
leave_only: require('./rules/modifiers/leave_only'), | ||
nested_object: require('./rules/meta/nested_object'), | ||
@@ -39,9 +46,2 @@ variable_object: require('./rules/meta/variable_object'), | ||
list_of_different_objects: require('./rules/meta/list_of_different_objects'), | ||
default: require('./rules/modifiers/default'), | ||
trim: require('./rules/modifiers/trim'), | ||
to_lc: require('./rules/modifiers/to_lc'), | ||
to_uc: require('./rules/modifiers/to_uc'), | ||
remove: require('./rules/modifiers/remove'), | ||
leave_only: require('./rules/modifiers/leave_only') | ||
}; | ||
@@ -48,0 +48,0 @@ |
'use strict'; | ||
const BaseValidator = require('./BaseValidator'); | ||
const util = require('./util'); | ||
@@ -8,40 +9,9 @@ | ||
class Validator { | ||
constructor(livrRules, isAutoTrim) { | ||
this.isPrepared = false; | ||
this.livrRules = livrRules; | ||
this.validators = {}; | ||
this.validatorBuilders = {}; | ||
class Validator extends BaseValidator { | ||
constructor(...args) { | ||
super(...args); | ||
this.errors = null; | ||
if (isAutoTrim !== null && isAutoTrim !== undefined) { | ||
this.isAutoTrim = isAutoTrim; | ||
} else { | ||
this.isAutoTrim = IS_DEFAULT_AUTO_TRIM; | ||
} | ||
this.registerRules(DEFAULT_RULES); | ||
} | ||
static getDefaultRules() { | ||
return DEFAULT_RULES; | ||
} | ||
static registerAliasedDefaultRule(alias) { | ||
if (!alias.name) throw 'Alias name required'; | ||
DEFAULT_RULES[alias.name] = this._buildAliasedRule(alias.rules, alias.error); | ||
} | ||
static registerDefaultRules(rules) { | ||
for (const ruleName in rules) { | ||
DEFAULT_RULES[ruleName] = rules[ruleName]; | ||
} | ||
} | ||
static defaultAutoTrim(isAutoTrim) { | ||
IS_DEFAULT_AUTO_TRIM = !!isAutoTrim; | ||
} | ||
static _buildAliasedRule(rules, errorCode) { | ||
static buildAliasedRule(rules, errorCode) { | ||
if (!rules) throw 'Alias rules required'; | ||
@@ -69,26 +39,2 @@ | ||
prepare() { | ||
const allRules = this.livrRules; | ||
for (const field in allRules) { | ||
let fieldRules = allRules[field]; | ||
if (!Array.isArray(fieldRules)) { | ||
fieldRules = [fieldRules]; | ||
} | ||
const validators = []; | ||
for (const fieldRule of fieldRules) { | ||
const parsed = this._parseRule(fieldRule); | ||
validators.push(this._buildValidator(parsed.name, parsed.args)); | ||
} | ||
this.validators[field] = validators; | ||
} | ||
this.isPrepared = true; | ||
return this; | ||
} | ||
validate(data) { | ||
@@ -147,89 +93,4 @@ if (!this.isPrepared) this.prepare(); | ||
} | ||
registerRules(rules) { | ||
for (const ruleName in rules) { | ||
this.validatorBuilders[ruleName] = rules[ruleName]; | ||
} | ||
return this; | ||
} | ||
registerAliasedRule(alias) { | ||
if (!alias.name) throw 'Alias name required'; | ||
this.validatorBuilders[alias.name] = this.constructor._buildAliasedRule( | ||
alias.rules, | ||
alias.error | ||
); | ||
return this; | ||
} | ||
getRules() { | ||
return this.validatorBuilders; | ||
} | ||
_parseRule(livrRule) { | ||
let name; | ||
let 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, args }; | ||
} | ||
_buildValidator(name, args) { | ||
if (!this.validatorBuilders[name]) { | ||
throw 'Rule [' + name + '] not registered'; | ||
} | ||
const allArgs = []; | ||
allArgs.push.apply(allArgs, args); | ||
allArgs.push(this.getRules()); | ||
return this.validatorBuilders[name].apply(null, allArgs); | ||
} | ||
_autoTrim(data) { | ||
const 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)) { | ||
const trimmedData = []; | ||
for (const item of data) { | ||
trimmedData.push(this._autoTrim(item)); | ||
} | ||
return trimmedData; | ||
} else if (dataType == 'object' && util.isObject(data)) { | ||
const trimmedData = {}; | ||
for (const key in data) { | ||
if (data.hasOwnProperty(key)) { | ||
trimmedData[key] = this._autoTrim(data[key]); | ||
} | ||
} | ||
return trimmedData; | ||
} | ||
return data; | ||
} | ||
} | ||
module.exports = Validator; |
{ | ||
"name": "livr", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Lightweight validator supporting Language Independent Validation Rules Specification", | ||
@@ -15,5 +15,7 @@ "homepage": "https://github.com/koorchik/js-validator-livr", | ||
"size": "size-limit", | ||
"build:min": "webpack --entry ./scripts/browser_build_entry.js --mode production -o ./dist/production/", | ||
"build:debug": "webpack --entry ./scripts/browser_build_entry.js --mode development -o ./dist/development/", | ||
"build": "npm run build:min && npm run build:debug" | ||
"build-sync:min": "webpack --entry ./scripts/browser_build_entry-sync.js --mode production -o ./dist/production/", | ||
"build-sync:debug": "webpack --entry ./scripts/browser_build_entry-sync.js --mode development -o ./dist/development/", | ||
"build-async:min": "webpack --entry ./scripts/browser_build_entry-async.js --mode production -o ./dist/production-async/", | ||
"build-async:debug": "webpack --entry ./scripts/browser_build_entry-async.js --mode development -o ./dist/development-async/", | ||
"build": "npm run build-sync:min && npm run build-sync:debug && npm run build-async:min && npm run build-async:debug" | ||
}, | ||
@@ -45,12 +47,13 @@ "repository": { | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^7.0.8", | ||
"ava": "^4.3.0", | ||
"@size-limit/preset-small-lib": "^8.1.0", | ||
"ava": "^5.0.1", | ||
"nyc": "^15.1.0", | ||
"size-limit": "^7.0.8", | ||
"webpack": "^5.73.0", | ||
"webpack-cli": "^4.9.2" | ||
"size-limit": "^8.1.0", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^4.10.0" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"t/*.js" | ||
"t/tests-sync/*.js", | ||
"t/tests-async/*.js" | ||
] | ||
@@ -66,5 +69,5 @@ }, | ||
"exclude": [ | ||
"t/*.js" | ||
"t/**/*.js" | ||
] | ||
} | ||
} |
111
README.md
@@ -11,2 +11,7 @@ # LIVR Validator | ||
There are 2 implemnations: | ||
1. "Validator" supports only synchronous rules. All built-in rules are synchronous. | ||
2. "AsyncValidator" (_experimental_) supports both synchronous and asynchronous rules. | ||
Common usage: | ||
@@ -36,2 +41,25 @@ | ||
Common usage of async version: | ||
```javascript | ||
import LIVR from 'livr/async'; | ||
LIVR.AsyncValidator.defaultAutoTrim(true); | ||
const validator = new LIVR.AsyncValidator({ | ||
name: 'required', | ||
email: ['required', 'email'], | ||
gender: { one_of: ['male', 'female'] }, | ||
phone: { max_length: 10 }, | ||
password: ['required', { min_length: 10 }], | ||
password2: { equal_to_field: 'password' } | ||
}); | ||
try { | ||
const validData = await validator.validate(userData); | ||
saveUser(validData); | ||
} catch(errors) { | ||
console.log('errors', errors); | ||
} | ||
``` | ||
You can use modifiers separately or can combine them with validation: | ||
@@ -82,2 +110,25 @@ | ||
Or you can write more sophisticated **async** rules as well: | ||
```javascript | ||
const validator = new LIVR.AsyncValidator({ | ||
userId: ['required', 'valid_user_id'] | ||
}); | ||
validator.registerRules({ | ||
valid_user_id() { | ||
return async value => { | ||
// We already have "required" rule to check that the value is present | ||
if (value === undefined || value === null || value === '') return; | ||
const user = await Users.findUserById(value); | ||
if (!user) { | ||
return 'WRONG_USER_ID'; | ||
} | ||
}; | ||
} | ||
}); | ||
``` | ||
If you use LIVR in browser, you can import only the rules you use (it can reduce budle size a little bit): | ||
@@ -121,3 +172,2 @@ | ||
# DESCRIPTION | ||
@@ -139,2 +189,3 @@ | ||
- Multipurpose (user input validation, configs validation, contracts programming etc) | ||
- Supports sync and async validation | ||
@@ -149,5 +200,35 @@ **JavaScript version extra features:** | ||
# ASYNC VALIDATION (NEW) | ||
LIVR supports async validation but it was added only in v2.5. So, it uses a little bit different API. | ||
What you need to know about implementation: | ||
1. All simple sync rules are supported out of the box. | ||
2. Meta rules (rules that construct a new validator instance inside them) were rewritten to use AsyncValidator. | ||
If you import "livr/async" they will be automatically used | ||
3. Fields validation is done in parallel but rules for one field are processed one after another. | ||
Usage example: | ||
```javascript | ||
import LIVR from 'livr/async'; | ||
LIVR.AsyncValidator.defaultAutoTrim(true); | ||
const validator = new LIVR.AsyncValidator({ | ||
name: 'required', | ||
email: ['required', 'email'], | ||
}); | ||
try { | ||
const validData = await validator.validate(userData); | ||
saveUser(validData); | ||
} catch(errors) { | ||
console.log('errors', errors); | ||
} | ||
``` | ||
# INSTALL | ||
#### nodejs/npm | ||
### nodejs/npm | ||
@@ -158,6 +239,11 @@ ```bash | ||
#### Browser (if you do not use npm) | ||
### Browser (if you do not use npm) | ||
You can find prebuilt browser versions in "dist" folder (development/main.js - not minified development version with source maps, production/main.js - minified production version). Possible you will need some polyfills ("isInteger" etc) for older browsers. | ||
You can find prebuilt browser versions in "dist" folder | ||
* development/main.js - not minified development version with source maps | ||
* production/main.js - minified production version. Possible you will need some polyfills ("isInteger" etc) for older browsers. | ||
* development-async/main.js - not minified development version with source maps of "AsyncValidator" | ||
* production-async/main.js - minified production version of "AsyncValidator" | ||
# CLASS METHODS | ||
@@ -269,3 +355,3 @@ | ||
List of useful utils for writing your rules (see source code) | ||
List of useful utils for writing your rules (see [source code](./lib/util.js)) | ||
@@ -288,6 +374,17 @@ # OBJECT METHODS | ||
## validator.getErrors() | ||
for AsyncValidator | ||
Returns errors object. | ||
```javascript | ||
try { | ||
const validData = await validator.validate(input); | ||
// use validData | ||
} catch(errors) { | ||
// handle errors | ||
} | ||
``` | ||
## validator.getErrors() (only for sync version of validator) | ||
Returns errors object. | ||
```javascript | ||
@@ -294,0 +391,0 @@ { |
@@ -10,2 +10,4 @@ { | ||
"should_not_be_errored": "", | ||
"should_be_empty": { | ||
@@ -12,0 +14,0 @@ "extra_field": "will be removed" |
@@ -9,2 +9,3 @@ { | ||
"should_not_be_errored": "", | ||
"should_be_empty": { | ||
@@ -11,0 +12,0 @@ |
@@ -9,2 +9,6 @@ { | ||
"should_not_be_errored": { "nested_object": { | ||
"zip": "positive_integer" | ||
}}, | ||
"should_be_empty": [ "required", { "nested_object": { | ||
@@ -11,0 +15,0 @@ "country": [{ "one_of": [["Ukraine", "USA"]] } ], |
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
253489
284
4653
427
2