-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.min.js
1 lines (1 loc) · 12.4 KB
/
validate.min.js
1
function isString(t){return"[object String]"===Object.prototype.toString.call(t)}function isNumber(t){return"[object Number]"===Object.prototype.toString.call(t)}function isArray(t){return"[object Array]"===Object.prototype.toString.call(t)}function isObject(t){return"object"==typeof t}function isStrictObject(t){return"[object Object]"===Object.prototype.toString.call(t)}function isRegExp(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function isStrictBoolean(t){return"[object Boolean]"===Object.prototype.toString.call(t)}function isBoolean(t){return!isNull(t)&&["true","false","1","0"].indexOf(isString(t)?t.toLowerCase().toString():t.toString())>=0}function isFunction(t){return"[object Function]"===Object.prototype.toString.call(t)}function isTrue(t){return!0===t}function isFalse(t){return!1===t}function isLowerCase(t){return!!isString(t)&&t===t.toLowerCase()}function isUpperCase(t){return!!isString(t)&&t===t.toUpperCase()}function isTitleCase(t){var i=!1;if(isString(t)){var e=t.split(" ");i=!0;for(var n=0,r=e.length;n<r;n++)if(e[n].trim().length>0&&!isUpperCase(e[n].charAt(0)))return!1}return i}function isNumeric(t){return!isNaN(parseFloat(t))}function isJSON(t){try{if(isString(t))return"object"==typeof JSON.parse(t);if("object"==typeof t&&null!==t&&isNaN(t))return"object"==typeof JSON.parse(JSON.stringify(t))}catch(t){}return!1}function isBase64(t){return!!isString(t)&&base64.test(t)}function isAlpha(t){return!!isString(t)&&alpha.test(t)}function isAlphanumeric(t){return!!isString(t)&&alphanumeric.test(t)}function isHexadecimal(t){return!!isString(t)&&hexadecimal.test(t)}function isAscii(t){return!!isString(t)&&ascii.test(t)}function isNull(t){return null===t||void 0===t||isNaN(t)&&!t.length}function isValidEmail(t){if(!isString(t)||isString(t)&&0===t.length)return!1;if(t.length>254)return!1;if(!email.test(t))return!1;var i=t.split("@");return!(i[0].length>64)&&!i[1].split(".").some(function(t){return t.length>63})}function isUUID(t,i){if(!isString(t))return!1;var e=uuid[i||"all"];return e&&e.test(t)}function isURIEncoded(t){return!!isString(t)&&decodeURI(t)!==t}function isEmpty(t){return isNull(t)||0==t.length}function isWhiteSpace(t){return isString(t)&&0==t.trim().length}function isBlank(t){return isEmpty(t)||isWhiteSpace(t)}function contains(t,i){return!(!isString(t)||!isString(i))&&t.indexOf(i)>-1}function containsIgnoreCase(t,i){return!(!isString(t)||!isString(i))&&t.toLowerCase().indexOf(i.toLowerCase())>-1}function containsKey(t,i){return!("string"==typeof t&&!isJSON(t))&&("string"==typeof t&&(t=JSON.parse(t)),!!isStrictObject(t)&&t.hasOwnProperty(i))}function containsDeepKey(t){if("string"==typeof t&&!isJSON(t))return!1;if("string"==typeof t&&(t=JSON.parse(t)),!isStrictObject(t))return!1;for(var i=Array.prototype.slice.call(arguments,1),e=0;e<i.length;e++){if(!t||!t.hasOwnProperty(i[e]))return!1;t=t[i[e]]}return!0}function isPalindrome(t){if(!isString(t))return!1;for(var i=t.length-1,e=0;i>e;)if(t.charAt(e++)!==t.charAt(i--))return!1;return!0}function objectEquals(t,i){"use strict";if(null===t||void 0===t||null===i||void 0===i)return t===i;if(t.constructor!==i.constructor)return!1;if(t instanceof Function)return t===i;if(t instanceof RegExp)return t===i;if(t instanceof String&&i instanceof String||t instanceof Number&&i instanceof Number)return t.toString()===i.toString();if(t===i||t.valueOf()===i.valueOf())return!0;if(Array.isArray(t)&&Array.isArray(i)&&t.length!==i.length)return!1;if(t instanceof Date)return!1;if(!(t instanceof Object))return!1;if(!(i instanceof Object))return!1;var e=Object.keys(t);return Object.keys(i).every(function(t){return-1!==e.indexOf(t)})&&e.every(function(e){return objectEquals(t[e],i[e])})}function hasAnyMethod(t){if(isStrictObject(t))for(var i=Object.getOwnPropertyNames(t),e=i.length-1;e>=0;e--)if("function"==typeof t[i[e]])return!0;return!1}function isMethodPresent(t,i){if(!hasAnyMethod(t)||isEmpty(i))return!1;for(var e=Object.getOwnPropertyNames(t),n=e.length-1;n>=0;n--)if("function"==typeof t[e[n]]&&e[n]==i)return!0;return!1}function startsWith(t,i,e,n){if(null==t&&(t=""),null==i&&(i=""),isStrictBoolean(e)&&(n=e,e=null),isArray(t)?i=isArray(i)?i:n?[i]:[""+i]:isArray(i)?t=isArray(t)?t:n?[t]:[""+t]:(t=""+t,i=""+i),e=null!==e&&isNumber(e)&&e>0&&e<=t.length?e:0,isArray(t)){if((t=t.length>=i.length?t.slice(e,i.length+e)||[]:[]).length!==i.length)return!1;for(var r=t.length;r--;)if(n&&t[r]!==i[r]||!n&&t[r]+""!=i[r]+"")return!1;return!0}return t.lastIndexOf(i,e)===e}function endsWith(t,i,e,n){if(null==t&&(t=""),null==i&&(i=""),isStrictBoolean(e)&&(n=e,e=null),isArray(t)?i=isArray(i)?i:n?[i]:[""+i]:isArray(i)?t=isArray(t)?t:n?[t]:[""+t]:(t=""+t,i=""+i),e=isNull(e)||e>=t.length||e<0?t.length>i.length?t.length-i.length:0:e,isArray(t)){if((t=t.slice(e)||[]).length!==i.length)return!1;for(var r=t.length;r--;)if(n&&t[r]!==i[r]||!n&&t[r]+""!=i[r]+"")return!1;return!0}return t.indexOf(i,e)===e}function isMD5(t){return!!isString(t)&&md5.test(t)}function isMACAddress(t){return!!isString(t)&&(macAddress1.test(t)||macAddress2.test(t))}function isHexaColor(t){return!!isString(t)&&hexaColor.test(t)}function isSet(t){return"[object Set]"===Object.prototype.toString.call(t)}function isWeakSet(t){return"[object WeakSet]"===Object.prototype.toString.call(t)}function isUndefined(t){return void 0===t}function isError(t){return!(!isObject(t)||null===t)&&("[object Error]"===Object.prototype.toString.call(t)||"[object DOMException]"===Object.prototype.toString.call(t)||isString(t.message)&&isString(t.name)&&t.constructor!=={}.constructor)}function isSystemError(t){return!!(isError(t)&&t&&t.code)&&SYSTEM_ERROR_CODES[t.code]}function isDate(t){return isObject(t)&&null!==t&&"[object Date]"===Object.prototype.toString.call(t)}function isMap(t){return"[object Map]"===Object.prototype.toString.call(t)}function isWeakMap(t){return"[object WeakMap]"===Object.prototype.toString.call(t)}function isHalfWidth(t){return!!isString(t)&&halfWidth.test(t)}function isFullWidth(t){return!!isString(t)&&fullWidth.test(t)}function containsJapanese(t){return!!isString(t)&&japanese.test(t)}function isPrintableASCII(t){return!!isString(t)&&printableASCII.test(t)}function isVariableWidth(t){return isHalfWidth(t)&&isFullWidth(t)}function isPort(t){var i=filterInt(t);return!isNaN(i)&&(i>0&&i<65536)}function isSemver(t){return!!isString(t)&&semver.test(t)}function isLatitude(t){return!!isString(t)&&latitude.test(t)}function isLongitude(t){return!!isString(t)&&longitude.test(t)}function isWinFilePath(t){return!!isString(t)&&winPath.test(t)}function isUnixFilePath(t){return!!isString(t)&&unixPath.test(t)}function isFilePath(t){return!!isString(t)&&(winPath.test(t)||unixPath.test(t))}function isMultiByte(t){return!!isString(t)&&multiByte.test(t)}function isInRange(t,i,e){return t=filterFloat(t),i=filterFloat(i),e=filterFloat(e),!(isNaN(t)||isNaN(i)||isNaN(e))&&(t>=i&&t<=e)}function isPositive(t){return t=filterFloat(t),!isNaN(t)&&t>0}function isNegative(t){return t=filterFloat(t),!isNaN(t)&&t<0}function isNonPositive(t){return t=filterFloat(t),!isNaN(t)&&t<=0}function isNonNegative(t){return t=filterFloat(t),!isNaN(t)&&t>=0}function isDataURI(t){return!!isString(t)&&dataURI.test(t)}function isISO8601(t){return!!isString(t)&&iso8601.test(t)}function isRGBColor(t){return!!isString(t)&&rgbColor.test(t)}function filterInt(t){return/^(\-|\+)?([0-9]+|Infinity)$/.test(t)?Number(t):NaN}var alpha=/^[A-Z]+$/i,alphanumeric=/^[0-9A-Z]+$/i,ascii=/^[\x00-\x7F]+$/,base64=/^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)$/i,dataURI=/^\s*data:([a-z]+\/[a-z0-9\-\+]+(;[a-z\-]+=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9!\$&',\(\)\*\+,;=\-\._~:@\/\?%\s]*\s*$/i,email=/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,fullWidth=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/,halfWidth=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/,hexaColor=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i,hexadecimal=/^[0-9A-F]+$/i,iso8601=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/,latitude=/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,longitude=/^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,japanese=/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/,macAddress1=/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/,macAddress2=/^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/,md5=/^[A-Fa-f0-9]{32}$/,multiByte=/[^\x00-\x7F]/,printableASCII=/^[\x20-\x7E]+$/,rgbColor=/^rgb\(\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])\s*\)$/,semver=/^v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/,unixPath=/^((?:\/[a-zA-Z0-9\.\:]+(?:_[a-zA-Z0-9\:\.]+)*(?:\-[\:a-zA-Z0-9\.]+)*)+\/?)$/,winPath=/^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$/,uuid={3:/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-3[0-9A-Fa-f]{3}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/i,4:/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$/i,5:/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-5[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$/i,all:/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/i},filterFloat=function(t){return/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/.test(t)?Number(t):NaN};exports=module.exports={contains:contains,containsDeepKey:containsDeepKey,containsIgnoreCase:containsIgnoreCase,containsJapanese:containsJapanese,containsKey:containsKey,endsWith:endsWith,hasAnyMethod:hasAnyMethod,isAlpha:isAlpha,isAlphanumeric:isAlphanumeric,isArray:isArray,isAscii:isAscii,isBase64:isBase64,isBlank:isBlank,isBoolean:isBoolean,isDataURI:isDataURI,isDate:isDate,isEmpty:isEmpty,isError:isError,isFalse:isFalse,isFilePath:isFilePath,isFullWidth:isFullWidth,isFunction:isFunction,isHalfWidth:isHalfWidth,isHexaColor:isHexaColor,isHexadecimal:isHexadecimal,isInRange:isInRange,isISO8601:isISO8601,isJSON:isJSON,isLatitude:isLatitude,isLongitude:isLongitude,isLowerCase:isLowerCase,isMACAddress:isMACAddress,isMap:isMap,isMD5:isMD5,isMethodPresent:isMethodPresent,isMultiByte:isMultiByte,isNegative:isNegative,isNonNegative:isNonNegative,isNonPositive:isNonPositive,isNull:isNull,isNumber:isNumber,isNumeric:isNumeric,isObject:isObject,isPalindrome:isPalindrome,isPort:isPort,isPositive:isPositive,isPrintableASCII:isPrintableASCII,isRegExp:isRegExp,isRGBColor:isRGBColor,isSemver:isSemver,isSet:isSet,isStrictObject:isStrictObject,isStrictBoolean:isStrictBoolean,isString:isString,isSystemError:isSystemError,isTitleCase:isTitleCase,isTrue:isTrue,isUndefined:isUndefined,isUnixFilePath:isUnixFilePath,isUpperCase:isUpperCase,isURIEncoded:isURIEncoded,isUUID:isUUID,isValidEmail:isValidEmail,isVariableWidth:isVariableWidth,isWeakMap:isWeakMap,isWeakSet:isWeakSet,isWhiteSpace:isWhiteSpace,isWinFilePath:isWinFilePath,objectEquals:objectEquals,startsWith:startsWith};var SYSTEM_ERROR_CODES={E2BIG:!0,EACCES:!0,EADDRINUSE:!0,EADDRNOTAVAIL:!0,EAFNOSUPPORT:!0,EAGAIN:!0,EALREADY:!0,EBADE:!0,EBADF:!0,EBADFD:!0,EBADMSG:!0,EBADR:!0,EBADRQC:!0,EBADSLT:!0,EBUSY:!0,ECANCELED:!0,ECHILD:!0,ECHRNG:!0,ECOMM:!0,ECONNABORTED:!0,ECONNREFUSED:!0,ECONNRESET:!0,EDEADLK:!0,EDEADLOCK:!0,EDESTADDRREQ:!0,EDOM:!0,EDQUOT:!0,EEXIST:!0,EFAULT:!0,EFBIG:!0,EHOSTDOWN:!0,EHOSTUNREACH:!0,EIDRM:!0,EILSEQ:!0,EINPROGRESS:!0,EINTR:!0,EINVAL:!0,EIO:!0,EISCONN:!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