This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
is.min.js
7 lines (7 loc) · 5.22 KB
/
is.min.js
1
2
3
4
5
6
7
/*
is.js 1.4 ~ Copyright (c) 2012-2014 Cedrik Boudreau
https://github.com/Cedriking/is.js
http://isjs.quipoapps.com
is.js may be freely distributed under the MIT Licence.
*/
(function(){var t;null==Array.prototype.forEach&&(Array.prototype.forEach=function(t,n){var e,r,i;if("function"!=typeof t)throw new TypeError;for(r=0,i=this.length;i>r;r++)e=this[r],t.call(n,e,r,this)}),t=this,t.is=function(){var t,n,e,r,i,s,u,o,a,c;return u=Object,o=u.prototype,c=window.navigator&&navigator.userAgent||"",t=window.navigator&&navigator.appVersion||"",n=Date.prototype,a=String.prototype,i=function(t,n){return o.toString.call(t)==="[object "+n+"]"},r=function(t){return Array.prototype.slice.call(arguments,1).forEach(function(n){var e;for(e in n)t[e]=n[e];return t})},e=function(t,n){var e,r,i,s;if("array"==typeof t){for(i=0,s=t.length;s>i;i++)if(e=t[i],!n.call(e,i,e))return t}else for(r in t)if(!n.call(t[r],r,t[r]))return t;return t},s={},e(["Object","Array","Boolean","Date","Function","Number","String","RegExp"],function(t,n){return s["is"+n]=function(){return i(this,n)}}),r(s,{isInteger:function(){return this%1===0},isFloat:function(){return!this.isInteger()},isOdd:function(){return!this.isEven()},isEven:function(){return this.isMultipleOf(2)},isMultipleOf:function(t){return this%t===0},isNaN:function(){return!this.isNumber()},isEmpty:function(){return null===this||"object"!=typeof this?!(this&&this.length>0):0===u.keys(this).length},isSameType:function(t){return o.toString.call(this)===o.toString.call(t)},isOwnProperty:function(t){return o.hasOwnProperty.call(this,t)},isType:function(t){return i(this,t)},isBlank:function(){return 0===this.trim().length}}),r(n,{isPast:function(t){return null==t&&(t=this),this.getTime()<t.getTime()},isFuture:function(t){return null==t&&(t=this),this.getTime()>t.getTime()},isWeekday:function(){return this.getUTCDay()>0&&this.getUTCDay()<6},isWeekend:function(){return 0===this.getUTCDay()||6===this.getUTCDay()},isBefore:function(t){return null==t&&(t=this),this.isPast(t)},isAfter:function(t){return null==t&&(t=this),this.isFuture(t)},isLeapYear:function(){var t;return t=this.getFullYear(),t%4===0&&t%100!==0||t%400===0},isValid:function(){return!this.getTime().isNaN()}}),r(a,{isCC:function(t){var n;return null==t&&(t="any"),n=function(){switch(t){case"any":return/^[0-9]{15,16}$/;case"ae":return/^(34)|(37)\d{14}$/;case"Discover":return/^6011\d{12}$/;case"mc":return/^5[1-5]\d{14}$/;case"Visa":return/^4\d{15}$/}}(),n.test(this)},isCreditCard:function(t){return null==t&&(t="any"),this.isCC(t)},isEmail:function(){return/^(([^<>()[\]\\.,;:\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,}))$/.test(this)},isLatLng:function(){return/-?\d{1,3}\.\d+/.test(this)},isLatLong:function(){return this.isLatLng()},isPhone:function(t){var n;return null==t&&(t="us"),n=function(){switch(t){case"ar":return/^(?:\+|[0]{2})?(54)?(:?[\s-])*\d{4}(:?[\s-])*\d{4}$/;case"au":return/^(?:\+|0)?(?:61)?\s?[2-478](?:[ -]?[0-9]){8}$/;case"ca":return/^(1-?)?(([2-9]\d{2})|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/;case"fr":return/^(?:0|\(?\+33\)?\s?|0033\s?)[1-79](?:[\.\-\s]?\d\d){4}$/;case"is":return/^(?:\+|[0]{2})?(354)?(:?[\s-])*\d{3}(:?[\s-])*\d{4}$/;case"uk":return/^(?:\+|044)?(?:\s+)?\(?(\d{1,5}|\d{4}\s*\d{1,2})\)?\s+|-(\d{1,4}(\s+|-)?\d{1,4}|(\d{6}))\d{6}$/;case"us":return/^(1-?)?(\d{3})(:?[\s\-])*(\d{3})(:?[\s\-])*(\d{4})$/}}(),n.test(this)},isZip:function(t){var n;return null==t&&(t="us"),n=function(){switch(t){case"ar":return/^\d{4}$/;case"au":return/^\d{4}$/;case"at":return/^\d{4}$/;case"be":return/^\d{4}$/;case"br":return/^\d{5}[\-]?\d{3}$/;case"ca":return/^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/;case"dk":return/^\d{3,4}$/;case"de":return/^\d{5}$/;case"es":return/^((0[1-9]|5[0-2])|[1-4]\d)\d{3}$/;case"gb":return/^[A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]? \d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/;case"hu":return/^\d{4}$/;case"is":return/^\d{3}$/;case"it":return/^\d{5}$/;case"jp":return/^\d{3}-\d{4}$/;case"nl":return/^\d{4}$/;case"pl":return/^\d{2}\-\d{3}$/;case"se":return/^\d{3}\s?\d{2}$/;case"us":return/^(\d{5}([\-]\d{4})?)$/}}(),n.test(this)}}),r(o,s),{ie:function(){return/msie/i.test(c)},ie6:function(){return/msie 6/i.test(c)},ie7:function(){return/msie 7/i.test(c)},ie8:function(){return/msie 8/i.test(c)},ie9:function(){return/msie 9/i.test(c)},ie10:function(){return/msie 10/i.test(c)},ie11:function(){return/Trident.*rv[ :]*11\./.test(c)},firefox:function(){return/firefox/i.test(c)},gecko:function(){return/gecko/i.test(c)},opera:function(){return/opera/i.test(c)},safari:function(){return/webkit\W(?!.*chrome).*safari\W/i.test(c)},chrome:function(){return/webkit\W.*(chrome|chromium)\W/i.test(c)},webkit:function(){return/webkit\W/i.test(c)},mobile:function(){return/iphone|ipod|(android.*?mobile)|blackberry|nokia/i.test(c)},tablet:function(){return/ipad|android(?!.*mobile)/i.test(c)},desktop:function(){return!this.mobile()&&!this.tablet()},kindle:function(){return/kindle|silk/i.test(c)},tv:function(){return/googletv|sonydtv|appletv|roku|smarttv/i.test(c)},online:function(){return navigator.onLine},offline:function(){return!this.online()},windows:function(){return/win/i.test(t)},mac:function(){return/mac/i.test(t)},unix:function(){return/x11/i.test(t)},linux:function(){return/linux/i.test(t)}}}()}).call(this);