This repository has been archived by the owner on Jan 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
string.min.js
executable file
·5 lines (5 loc) · 1.78 KB
/
string.min.js
1
2
3
4
5
/*! js-methods (https://github.com/harrydeluxe/js-methods) */
(function(){function c(a,b,d){if(!String.prototype[a]||d)String.prototype[a]=b}c("trim",function(a){a=!a?" \\s\u00a0":(a+"").replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,"$1");return this.replace(RegExp("^["+a+"]+|["+a+"]+$","g"),"")},!0);c("ltrim",function(a){a=!a?" \\s\u00a0":(a+"").replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,"$1");return this.replace(RegExp("^["+a+"]+","g"),"")});c("rtrim",function(a){a=!a?" \\s\u00a0":(a+"").replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,"\\$1");return this.replace(RegExp("["+
a+"]+$","g"),"")});c("collapseSpaces",function(){return this.trim().replace(/\s{2,}/g," ").replace(/{(Keyword):\s*(.*?)\s*}/gi,"{$1:$2}")});c("format",function(a){var b=/(?:%(\d+))/mg,d=0,c=[];do{var e=b.exec(this);e&&e[1]&&(e.index>d&&c.push(this.substring(d,e.index)),c.push(a[parseInt(e[1])]),d=b.lastIndex)}while(e);d<this.length&&c.push(this.substring(d,this.length));return c.join("")});c("remove",function(a,b){var d="";0<a&&(d=this.substring(0,a));a+b<this.length&&(d+=this.substring(a+b,this.length));
return d});c("reverse",function(){if(!this)return"";var a=(this+"").split("");a.reverse();return a.join("")});c("repeat",function(a,b){for(var d="";0<--a+1;)d+=b&&0!=a?this+b:this;return d});c("pad",function(a,b,d){for(var a=a||30,d=d||0,b=b||" ",c=this;c.length<a;)c=1==d?c+=b:b+c;return c});c("capitalize",function(){for(var a=this.split(" "),b=0;b<a.length;b++)a[b]=a[b].charAt(0).toUpperCase()+a[b].substring(1).toLowerCase();return a.join(" ")});c("camelize",function(){return this.replace(/[-_]([a-z])/ig,
function(a,b){return b.toUpperCase()})});c("truncate",function(a,b){a=a||50;b=void 0===b?"...":b;return this.length>a?this.slice(0,a-b.length)+b:this});c("stripTags",function(){return this.replace(/<\/?[^>]+>/gi,"")})})();