-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagile.min.js
1 lines (1 loc) · 5.93 KB
/
agile.min.js
1
function typecheck(arg,type){switch(type){case"string":if(!arg||"string"!=typeof arg)throw"Data Type Error : Expecting string. Found "+typeof arg+".";break;case"number":if(0!==arg&&(!arg||"number"!=typeof arg))throw"Data Type Error : Expecting number. Found "+typeof arg+".";break;case"array":if(0!==arg&&(!arg||"number"!=typeof arg))throw"Data Type Error : Expecting number. Found "+typeof arg+".";break;case"bulk":if(!(arg&&arg instanceof Array))throw"Data Type Error : Expecting Array. Found "+typeof arg+".";if(0===arg.length)throw"The first argument supplied is an empty Array. Please supply array elements.";var i;for(i=0;i<arg.length;i++){if(void 0===arg[i].arg)throw"Missing Argument "+(i+1)+".";if("array"===arg[i].expected){if(!(arg[i].arg instanceof Array))throw"Data Type Error : Expecting "+arg[i].expected+" for Argument "+(i+1)+", but found "+typeof arg[i].arg+"."}else if(typeof arg[i].arg!==arg[i].expected)throw"Data Type Error : Expecting "+arg[i].expected+" for Argument "+(i+1)+", but found "+typeof arg[i].arg+"."}}}function buildQueryString(object){var i,str="";for(i in object)"function"!=typeof object[i]&&(str+=i+"="+encodeURIComponent(object[i])+"&");return str.rtrim("&")}function chr(asc){return String.fromCharCode(asc)}String.prototype.isEmail=function(){var re,emailArr,i;if(re=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i,this.indexOf(",")>-1){for(emailArr=this.split(","),i=0;i<emailArr.length;i++)if(!re.test(emailArr[i].trim()))return!1;return!0}return re.test(this.trim())},String.prototype.lcfirst=function(){var opStr=this.trim();return opStr.charAt(0).toLowerCase()+opStr.substr(1)},String.prototype.ucfirst=function(){var opStr=this.trim();return opStr.charAt(0).toUpperCase()+opStr.substr(1)},String.prototype.cmp=function(secondStr){return this.trim().localeCompare(secondStr.trim())},String.prototype.pad=function(padCh,padLen,padMode){var result=this;if(padLen=padLen||1,padMode=padMode||"LEFT",padMode=padMode.toUpperCase(),typecheck([{arg:padCh,expected:"string"},{arg:padLen,expected:"number"},{arg:padMode,expected:"string"}],"bulk"),"LEFT"!==padMode&&"RIGHT"!==padMode&&"BOTH"!==padMode)throw"Data Value Error: Expecting LEFT, RIGHT or BOTH for third argument. Found "+padMode+".";return("LEFT"===padMode||"BOTH"===padMode)&&(result=padCh.repeat(padLen)+result),("RIGHT"===padMode||"BOTH"===padMode)&&(result+=padCh.repeat(padLen)),result},String.prototype.repeat=function(len){return new Array(len+1).join(this)},String.prototype.ucwords=function(){var i,strArray=this.trim().split(" ");for(i=0;i<strArray.length;i++)strArray[i]=strArray[i].charAt(0).toUpperCase()+strArray[i].slice(1);return strArray.join(" ")},String.prototype.htmlspecialchars=function(){var map={"&":"&","<":"<",">":">",'"':""","'":"'"};return this.replace(/[&<>"']/g,function(m){return map[m]})},String.prototype.html_entities_decode=function(){var t;return t=document.createElement("textarea"),t.style.display="none",t.innerHTML=this,t.innerText},String.prototype.reverse=function(){return this.split("").reverse().join("")},String.prototype.rtrim=function(c){c&&typecheck(c,"string");var a=this.replace(/\s+$/,"");return c=c?c:"s",a.replace(new RegExp("["+c+"]+$"),"")},String.prototype.ltrim=function(c){var str=this.reverse();c&&typecheck(c,"string");var a=str.replace(/\s+$/,"");return c=c?c:"s",a.replace(new RegExp("["+c+"]+$"),"").reverse()},String.prototype.strstr=function(needle,bool){var pos=0,string=this;if(string+="",pos=string.indexOf(needle),-1==pos)throw"Needle string should not be empty!";return bool?string.substr(0,pos):string.slice(pos)},String.prototype.chunk_split=function(length,character){return length=parseInt(length,10)||76,character=character||"\r\n",1>length?!1:this.match(new RegExp(".{0,"+length+"}","g")).join(character)},String.prototype.shuffle=function(){function shuffle(str){var i,j,tmp,a=str.split(""),n=a.length;if(1==n)return a.join("");for(single=!1,i=n-1;i>0;i--)j=Math.floor(Math.random()*(i+1)),tmp=a[i],a[i]=a[j],a[j]=tmp;return a.join("").trim()}var same,op,single=!0;return op=shuffle(this),single||op==this&&(same=!0),same?this.shuffle():op},String.prototype.nl2br=function(is_xhtml){return this.replace(/\r\n|\n\r|\n|\r|/g,"<br"+(void 0!==typeof is_xhtml&&is_xhtml===!0?" /":"")+">")},String.prototype.substr_replace=function(replace,start,length){if(!start)throw"Please enter starting index.";if(0>start&&(start+=this.length),length=void 0!==length?length:this.length,0>length&&(length=length+this.length-start),start>this.length)throw"Please enter valid index.";return this.slice(0,start)+replace.substr(0,length)+replace.slice(length)+this.slice(start+length)},Array.prototype.unique=function(){var i,l,u={},a=[];for(i=0,l=this.length;l>i;++i)u.hasOwnProperty(this[i])||(a.push(this[i]),u[this[i]]=1);return a},Array.prototype.has_duplicates=function(){var i,status,j,obj={};for(i=0,j=this.length;j>i;i++)obj[this[i]]=(obj[this[i]]||0)+1;for(var key in obj)if(obj[key]>1){status=!0;break}return status},Array.prototype.has_duplicates_assoc=function(key){typecheck(key,"string");var i,k,j,obj={},status=!1;for(i=0,j=this.length;j>i;i++)obj[this[i][key]]=(obj[this[i][key]]||0)+1;for(k in obj)if(obj[k]>1){status=!0;break}return status},Array.prototype.duplicates=function(){var i,j,obj={};for(i=0,j=this.length;j>i;i++)obj[this[i]]=(obj[this[i]]||0)+1;return obj},Array.prototype.duplicates_assoc=function(key){if(typecheck(key,"string"),!key)throw"Please provide a key to find duplicates.";var i,j,obj={};for(i=0,j=this.length;j>i;i++)obj[this[i][key]]=(obj[this[i][key]]||0)+1;return obj},Array.prototype.indexOfAssoc=function(value,key){if(!key&&0!==key)throw"Please provide a key to find index of.";var i;for(i=0;i<this.length;i++)if(typecheck([{arg:this[i],expected:"object"}],"bulk"),this[i][key]===value)return i},Array.prototype.lastIndexOfAssoc=function(value,key){typecheck(key,"string");var i;if(!key&&0!==key)throw"Please provide a key to find index of.";for(i=this.length-1;i>=0;i--)if(this[i][key]===value)return i};