-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalidate-chain-browser.min.js
1 lines (1 loc) · 16.7 KB
/
validate-chain-browser.min.js
1
!function t(e,r,i){function n(a,u){if(!r[a]){if(!e[a]){var h="function"==typeof require&&require;if(!u&&h)return h(a,!0);if(s)return s(a,!0);throw new Error("Cannot find module '"+a+"'")}var o=r[a]={exports:{}};e[a][0].call(o.exports,function(t){var r=e[a][1][t];return n(r?r:t)},o,o.exports,t,e,r,i)}return r[a].exports}for(var s="function"==typeof require&&require,a=0;a<i.length;a++)n(i[a]);return n}({1:[function(t,e,r){function i(){}var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var r=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),r.length>0)){var i=r.shift();i()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=i,n.addListener=i,n.once=i,n.off=i,n.removeListener=i,n.removeAllListeners=i,n.emit=i,n.binding=function(t){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(t){throw new Error("process.chdir is not supported")}},{}],2:[function(t,e,r){(function(i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var s=function(){function t(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,r,i){return r&&t(e.prototype,r),i&&t(e,i),e}}();!function(t,i){"undefined"!=typeof r&&"undefined"!=typeof e?e.exports=i():"function"==typeof define&&"object"==typeof define.amd?define(i):this[t]=i()}("VC",function(){function e(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date)}function r(t,r){var i=t[r];return Array.isArray(i)?i.slice():e(i)?Object.assign({},i):i}function a(t){return Array.isArray(t)?t.slice():e(t)?Object.assign({},t):t}function u(t,e,i,n){for(var s=!0;s;){var a=t,u=e,h=i,o=n;if(s=!1,!a||!u)return;if(!h&&u.indexOf(".")>-1)h=u.split("."),t=a[h[0]],e=h[0],i=h,n=1,s=!0;else{if(!h||!h[o+1])return h&&h[o]?r(a,h[o]):r(a,u);t=a[h[o]],e=h[o],i=h,n=o+1,s=!0}}}function h(t,e,r){if(!t||!e)throw new Error("objectSetMethod 需要object和key参数");var i=e.split(".");try{return i.reduce(function(t,e,n){return void 0!==i[n+1]?(t[e]||(t[e]=o.regx.numeric.test(i[n+1])?[]:{}),t[e]):(t[e]=r,t)},t),!0}catch(n){return!1}}var o=t("./validator.js"),l=function(){function t(e,r){n(this,t),this.key=null,this._errs=[],this.errorFields=[],this._san={},this._alias={},this.opt=!!r,this.target=e,this.takeWhatWeHave=r,this.inArrayMode=!1,this.inArray={index:0,arrayKey:null},this.getter=u,this.setter=h}return s(t,[{key:"addError",value:function(t){if(Array.isArray(t))return void(this._errs=this._errs.concat(t));if(this.inArrayMode){var e=this.inArray,r=e.index,i=e.arrayKey,n=this._alias[i],s=u(this.target,i)[r],a=this._alias[i+"."+r+"."+this.key],o=s&&!u(s,this.key);a=o?(n||i)+"."+r:(n||i)+"."+r+"."+(a||this.key),this.errorFields.push(i+"."+r+(o?"":"."+this.key)),u(this._san,i)[r]&&h(this._san,i+"."+r+(o?"":this.key),void 0)}else{u(this._san,this.key)&&h(this._san,this.key,void 0);var a=this._alias[this.key];this.errorFields.push(this.key)}a&&(t=a+": "+t.replace(/\S+\:\s/,"")),this._errs.push(t)}},{key:"alias",value:function(t){if(!this.key)return this.next=!1,this;if(this.inArrayMode){var e=this.inArray,r=e.index,i=e.arrayKey;this._alias[i+"."+r+"."+this.key]=t}else this._alias[this.key]=t;return this}},{key:"check",value:function(t){this.key=t,this.next=!0,this.opt=!1;var e=this.currentVal;return void 0!==e?this.inArrayMode||h(this._san,t,a(e)):this.opt=!0,this}},{key:"array",value:function(t,e){if(!this.next)return this;var r=this.currentVal;if(this.opt&&!r)return this;if(Array.isArray(r)){if("function"==typeof t){this.inArrayMode=!0,this.inArray.arrayKey=this.key,h(this._san,this.key,a(r));var i=this;r.forEach(function(e,r){i.inArray.index=r,t(i,r)}),this.inArrayMode=!1}}else this.addError(e||this.key+": 需要为一个数组");return this}},{key:"defaultValueOrError",value:function(t,e){void 0!==t?this.setSanitizedVal(t):this.addError(e)}},{key:"required",value:function(t,e){return this.takeWhatWeHave?(this.opt=!0,this):this.next?(this.opt=!1,void 0!==this.currentVal&&""!==this.currentVal||(this.defaultValueOrError(e,t||this.key+": 为必填字段"),void 0===e&&(this.next=!1)),this):this}},{key:"optional",value:function(){return this.next?(this.opt=!0,this):this}},{key:"between",value:function(t,e,r,i){if(!this.next)return this;var n=this.currentVal;if(this.opt&&!n)return this;var s=typeof n;return("string"===s||Array.isArray(n))&&(n.length>e||n.length<t)?this.defaultValueOrError(i,r||this.key+": 长度应该在"+t+"-"+e+"个字符之间"):"number"===s&&(n>e||n<t)&&this.defaultValueOrError(i,r||this.key+": 大小应该在"+t+"-"+e+"之间"),this}},{key:"max",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;if(this.opt&&!i)return this;var n=typeof i;return("string"===n||Array.isArray(i))&&i.length>t?this.defaultValueOrError(r,e||this.key+": 最多"+t+"个字符"):"number"===n&&i>t&&this.defaultValueOrError(r,e||this.key+": 最大值为"+t),this}},{key:"min",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;if(this.opt&&!i)return this;var n=typeof i;return("string"===n||Array.isArray(i))&&i.length<t?this.defaultValueOrError(r,e||this.key+": 最少"+t+"个字符"):"number"===n&&i<t&&this.defaultValueOrError(r,e||this.key+": 最小值为"+t),this}},{key:"regx",value:function(t,e,r,i){if(!this.next)return this;var n=this.currentVal;return this.opt&&!n?this:("[object RegExp]"!==Object.prototype.toString.call(t)&&(t=new RegExp(t,r)),t.test(n)||this.defaultValueOrError(i,e||this.key+": 不合格"+t.toString()+"的格式"),this)}},{key:"$apply",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;if(this.opt&&!i)return this;if("function"!=typeof t)throw new Error("$apply第一个参数必须为function");return t(i)||this.defaultValueOrError(r,e||this.key+": "+i+"不是正确的格式"),this}},{key:"date",value:function(t,e){if(!this.next)return this;var r=this.currentVal;return this.opt&&!r?this:(o.isDate(r)||this.defaultValueOrError(e,t||this.key+": "+r+"不符合日期格式"),this)}},{key:"before",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;return this.opt&&!i?this:(o.isBefore(i,t)||this.defaultValueOrError(r,e||this.key+": "+i+"需要在"+t+"之前"),this)}},{key:"after",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;return this.opt&&!i?this:(o.isAfter(i,t)||this.defaultValueOrError(r,e||this.key+": "+i+"需要在"+t+"之后"),this)}},{key:"in",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;return this.opt&&!i?this:(o.isIn(i,t)||this.defaultValueOrError(r,e||this.key+": "+i+"需要在["+t.toString()+"]之中"),this)}},{key:"email",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;return this.opt&&!i?this:(o.isEmail(i,e)||this.defaultValueOrError(r,t||this.key+": "+i+"不是常规的email"),this)}},{key:"JSON",value:function(t,e){if(!this.next)return this;var r=this.currentVal;return this.opt&&!r?this:(o.isJSON(r)||this.defaultValueOrError(e,t||this.key+": "+r+"不是JSON格式字符串"),this)}},{key:"URL",value:function(t,e,r){if(!this.next)return this;var i=this.currentVal;return this.opt&&!i?this:(o.isURL(i,e)||this.defaultValueOrError(r,t||this.key+": "+i+"不符合URL的格式"),this)}},{key:"phone",value:function(t,e){return this.regx(o.regx.phone,t||this.key+": "+this.currentVal+"不是常规的手机号码",null,e)}},{key:"numeric",value:function(t,e){return this.regx(o.regx.numeric,t||this.key+": "+this.currentVal+"必须为纯数字",null,e)}},{key:"decimal",value:function(t,e){return this.regx(o.regx.decimal,t||this.key+": "+this.currentVal+"必须为小数格式数字",null,e)}},{key:"float",value:function(t,e){return this.regx(o.regx["float"],t||this.key+": "+this.currentVal+"必须为float格式数字",null,e)}},{key:"hex",value:function(t,e){return this.regx(o.regx.hexadecimal,t||this.key+": "+this.currentVal+"必须为16进制数字",null,e)}},{key:"alpha",value:function(t,e){return this.regx(o.regx.alpha,t||this.key+": "+this.currentVal+"必须为纯字母",null,e)}},{key:"alphanumeric",value:function(t,e){return this.regx(o.regx.alphanumeric,t||this.key+": "+this.currentVal+"必须为纯字母和数字的组合",null,e)}},{key:"ascii",value:function(t,e){return this.regx(o.regx.ascii,t||this.key+": "+this.currentVal+"必须为符合规范的ASCII码",null,e)}},{key:"objectId",value:function(t,e){return this.regx(o.regx.objectId,t||this.currentVal+"不是常规的ObjectId",null,e)}},{key:"base64",value:function(t,e){return this.regx(o.regx.base64,t||this.key+": "+this.currentVal+"必须为符合规范的Base64编码",null,e)}},{key:"creditCard",value:function(t,e){if(!this.next)return this;var r=this.currentVal;return this.opt&&!r?this:(o.isCreditCard(r)||this.defaultValueOrError(e,t||this.key+": "+r+"不符合信用卡的格式"),this)}},{key:"setSanitizedVal",value:function(t){if(this.inArrayMode){var e=this.inArray,r=e.index,i=e.arrayKey,n=u(this.target,i)[r],s=n&&!u(n,this.key);s?h(this._san,i+"."+r,t):h(this._san,i+"."+r+"."+this.key,t)}else h(this._san,this.key,t)}},{key:"sanitize",value:function(t){if(!this.next)return this;var e=this.currentVal;if(this.opt&&!e)return this;if("function"!=typeof t)throw new Error("sanitize第一个参数必须为function");return this.setSanitizedVal(t(e)),this}},{key:"trim",value:function(){if(!this.next)return this;var t=this.currentVal;return this.opt&&!t?this:(this.setSanitizedVal(t.trim?t.trim():t),this)}},{key:"whitelist",value:function(t){if(!this.next)return this;var e=this.currentVal;return this.opt&&!e?this:(this.setSanitizedVal(e.replace(new RegExp("[^"+t+"]+","g"),"")),this)}},{key:"blacklist",value:function(t,e){if(!this.next)return this;var r=this.currentVal;return this.opt&&!r?this:(this.setSanitizedVal(r.replace(new RegExp("["+t+"]+","g"),e||"")),this)}},{key:"noSpecialChar",value:function(t){if(!this.next)return this;var e=this.currentVal;return this.opt&&!e?this:(this.setSanitizedVal(e.replace(o.regx.specialChars,t||"_")),this)}},{key:"escape",value:function(){if(!this.next)return this;var t=this.currentVal;return this.opt&&!t?this:(this.setSanitizedVal(t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/\//g,"/").replace(/\`/g,"`")),this)}},{key:"toBoolean",value:function(t){if(!this.next)return this;var e=this.currentVal;return this.opt&&!e?this:(t&&this.setSanitizedVal("1"===e||"true"===e),this.setSanitizedVal("0"!==e&&"false"!==e&&""!==e),this)}},{key:"toDate",value:function(){if(!this.next)return this;var t=this.currentVal;if(this.opt&&!t)return this;if("[object Date]"===Object.prototype.toString.call(t))this.setSanitizedVal(t);else{var e=Date.parse(t);this.setSanitizedVal(isNaN(e)?null:new Date(e))}return this}},{key:"toFloat",value:function(){if(!this.next)return this;var t=this.currentVal;return this.opt&&!t?this:(this.setSanitizedVal(parseFloat(t)),this)}},{key:"toInt",value:function(t){if(!this.next)return this;var e=this.currentVal;return this.opt&&!e?this:(this.setSanitizedVal(parseInt(e,t||10)),this)}},{key:"toString",value:function(){if(!this.next)return this;var t=this.currentVal;return this.opt&&!t?this:("object"==typeof t&&null!==t&&t.toString?this.setSanitizedVal(t.toString()):null===t||"undefined"==typeof t||isNaN(t)&&!t.length?this.setSanitizedVal(""):"string"!=typeof t&&this.setSanitizedVal(t+""),this)}},{key:"compose",value:function(e,r){this.key=e;var i=new t(this.currentVal,this.takeWhatWeHave),n=r(i),s=n||i,a=s.sanitized,u=s.errors;if(this.setSanitizedVal(a),u&&u.length>0){var h=this._alias[e]||e;this.addError(u.map(function(t){return h+"."+t}))}return this}},{key:"flatedArray",value:function(e,r){var i=this;if("string"==typeof e){this.key=e;var n=this.currentVal;Object.keys(n).forEach(function(s,a){var u=new t(n[s],i.takeWhatWeHave),o=r(u,n[s]),l=o||u,f=l.sanitized,c=l.errors;if(h(i._san,e+"."+s,f),c&&c.length>0){var y=(i._alias[e]||e)+"."+s;i.addError(c.map(function(t){return y+"."+t}))}})}else Object.keys(this.target).forEach(function(r,n){i.key=r;var s=new t(i.currentVal,i.takeWhatWeHave),a=e(s,i.currentVal),u=a||s,h=u.sanitized,o=u.errors;i.setSanitizedVal(h),o&&o.length>0&&i.addError(o.map(function(t){return r+"."+t}))});return this}},{key:"errors",get:function(){return this._errs[0]?this._errs:null}},{key:"sanitized",get:function(){return Object.keys(this._san).length>0?this._san:null}},{key:"currentVal",get:function(){if(this.inArrayMode){var t=u(this.target,this.inArray.arrayKey),e=t[this.inArray.index],r=u(e,this.key);return e&&void 0!==r?r:e}return u(this.target,this.key)}}]),t}();return i.browser&&(window.VC=l,window.Validator=o),l})}).call(this,t("pBGvAp"))},{"./validator.js":3,pBGvAp:1}],3:[function(t,e,r){"use strict";function i(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function n(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t}function s(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))}function a(t){return!isNaN(Date.parse(t))}function u(t,e){var r=s(e||new Date),i=s(t);return!!(i&&r&&i<r)}function h(t,e){var r=s(e||new Date),i=s(t);return!!(i&&r&&i>r)}function o(t,e){var r;if("[object Array]"===Object.prototype.toString.call(e)){var i=[];for(r in e)i[r]=n(e[r]);return i.indexOf(t)>=0}return"object"==typeof e?e.hasOwnProperty(t):!(!e||"function"!=typeof e.indexOf)&&e.indexOf(t)>=0}function l(t){return v.email.test(t)}function f(){try{var t=JSON.parse(str);return!!t&&"object"==typeof t}catch(e){}return!1}function c(t){return v.ipv4Maybe.test(t)||v.ipv6Block.test(t)}function y(t,e){if(!t||t.length>=2083||/\s/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;e=i(e,k);var r,n,s,a,u,h,o;if(o=t.split("://"),o.length>1){if(r=o.shift(),e.require_valid_protocol&&e.protocols.indexOf(r)===-1)return!1}else{if(e.require_protocol)return!1;e.allow_protocol_relative_urls&&"//"===t.substr(0,2)&&(o[0]=t.substr(2))}return t=o.join("://"),o=t.split("#"),t=o.shift(),o=t.split("?"),t=o.shift(),o=t.split("/"),t=o.shift(),o=t.split("@"),!(o.length>1&&(n=o.shift(),n.indexOf(":")>=0&&n.split(":").length>2))&&(a=o.join("@"),o=a.split(":"),s=o.shift(),!(o.length&&(h=o.join(":"),u=parseInt(h,10),!/^[0-9]+$/.test(h)||u<=0||u>65535))&&(!(!c(s)&&!d(s,e)&&"localhost"!==s)&&((!e.host_whitelist||e.host_whitelist.indexOf(s)!==-1)&&(!e.host_blacklist||e.host_blacklist.indexOf(s)===-1))))}function d(t,e){e=i(e,g),e.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var r=t.split(".");if(e.require_tld){var n=r.pop();if(!r.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(n))return!1}for(var s,a=0;a<r.length;a++){if(s=r[a],e.allow_underscores){if(s.indexOf("__")>=0)return!1;s=s.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(s))return!1;if(/[\uff01-\uff5e]/.test(s))return!1;if("-"===s[0]||"-"===s[s.length-1]||s.indexOf("---")>=0)return!1}return!0}function p(t){var e=t.replace(/[^0-9]+/g,"");if(!v.creditCard.test(e))return!1;for(var r,i,n,s=0,a=e.length-1;a>=0;a--)r=e.substring(a,a+1),i=parseInt(r,10),n?(i*=2,s+=i>=10?i%10+1:i):s+=i,n=!n;return!(s%10!==0||!e)}Object.defineProperty(r,"__esModule",{value:!0}),r.toDate=s,r.isDate=a,r.isBefore=u,r.isAfter=h,r.isIn=o,r.isEmail=l,r.isJSON=f,r.isIP=c,r.isURL=y,r.isFQDN=d,r.isCreditCard=p;var v={phone:/^(\+?0?86\-?)?1[3456789]\d{9}$/,phoneStrict:/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/,email:/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,creditCard:/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/,objectId:/^[0-9a-fA-F]{24}$/,specialChars:/[#'$%^&*\/\\\|<>\[\]{}]/g,alpha:/^[A-Z]+$/i,alphanumeric:/^[0-9A-Z]+$/i,numeric:/^[-+]?[0-9\.]+$/,"int":/^(?:[-+]?(?:0|[1-9][0-9]*))$/,"float":/^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/,hexadecimal:/^[0-9A-F]+$/i,decimal:/^[-+]?([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/,hexcolor:/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i,ascii:/^[\x00-\x7F]+$/,base64:/^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i,ipv4Maybe:/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/,ipv6Block:/^[0-9A-F]{1,4}$/i};r.regx=v;var k={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},g={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1}},{}]},{},[2]);