validator.js
Version:
Powerful object and string validation in Javascript.
6 lines (5 loc) • 2.33 kB
JavaScript
/*!
* Part of validator.js
* Version 2.0.4 - built Thu Jan 30 2020 15:34:17
*/
!function(a){"function"==typeof define&&define.amd?define(["validator"],a):"object"==typeof exports?module.exports=a(require("./validator.js")):a(window["undefined"!=typeof validatorjs_ns?validatorjs_ns:"Validator"])}(function(a){var b={Eql:function(b){if(this.__class__="Eql","undefined"==typeof b)throw new Error("Equal must be instanciated with an Array or an Object");return this.eql=b,this.validate=function(b){var d="function"==typeof this.eql?this.eql(b):this.eql;if(!c.eql(d,b))throw new a.Violation(this,b,{eql:d});return!0},this},Mac:function(){return this.__class__="Mac",this.validate=function(b){var c=/^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$/i;if("string"!=typeof b)throw new a.Violation(this,b,{value:Validator.errorCode.must_be_a_string});if(!c.test(b))throw new a.Violation(this,b);return!0},this},IPv4:function(){return this.__class__="IPv4",this.validate=function(b){var c=/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;if("string"!=typeof b)throw new a.Violation(this,b,{value:Validator.errorCode.must_be_a_string});if(!c.test(b))throw new a.Violation(this,b);return!0},this}},c={eql:function(a,b){if(a===b)return!0;if("undefined"!=typeof Buffer&&Buffer.isBuffer(a)&&Buffer.isBuffer(b)){if(a.length!==b.length)return!1;for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}return a instanceof Date&&b instanceof Date?a.getTime()===b.getTime():"object"!=typeof a&&"object"!=typeof b?a==b:this.objEquiv(a,b)},isUndefinedOrNull:function(a){return null===a||"undefined"==typeof a},isArguments:function(a){return"[object Arguments]"==Object.prototype.toString.call(a)},keys:function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&b.push(c);return b},objEquiv:function(a,b){if(this.isUndefinedOrNull(a)||this.isUndefinedOrNull(b))return!1;if(a.prototype!==b.prototype)return!1;if(this.isArguments(a))return!!this.isArguments(b)&&eql(pSlice.call(a),pSlice.call(b));try{var c,d,e=this.keys(a),f=this.keys(b);if(e.length!==f.length)return!1;for(e.sort(),f.sort(),d=e.length-1;d>=0;d--)if(e[d]!=f[d])return!1;for(d=e.length-1;d>=0;d--)if(c=e[d],!this.eql(a[c],b[c]))return!1;return!0}catch(g){return!1}}};return a.Assert.extend(b)});