cxfoot/web/statics/js/site.js
2023-10-24 14:54:18 +08:00

69 lines
1.6 KiB
JavaScript

/*
* Author:Any
* Date:2019/06/17
*/
String.prototype.format = function() {
var str = this.valueOf();
var matches = str.match(/{}/g);
for (var i in matches) {
str = str.replace(/{}/, arguments[i]);
}
return str;
};
String.prototype._trim = function (char, type) {
if (char) {
if (type == 'left') {
return this.replace(new RegExp('^\\' + char + '+', 'g'), '');
} else if (type == 'right') {
return this.replace(new RegExp('\\' + char + '+$', 'g'), '');
}
return this.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), '');
}
return this.replace(/^\s+|\s+$/g, '');
};
window.wrx = window.wrx === undefined ? function(){} : window.wrx;
wrx.trim = function(str){
if(typeof(str) === "string"){
return str.replace(/(^\s*)|(\s*$)/g, "");
} else {
return str;
}
};
wrx.ltrim = function(str){
if(typeof(str) === "string"){
return str.replace(/(^\s*)/g,"");
} else {
return str;
}
};
wrx.rtrim = function(str){
if(typeof(str) === "string"){
return str.replace(/(\s*$)/g, "");
} else {
return str;
}
};
wrx.is_in_array = function(o,arr){
for(var i in arr){
if(arr[i] === o){
return true;
}
}
return false;
};
wrx.trim = function(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
};
wrx.object_to_url_params = function(t){
var r = "";
for (var e in t) r += "&" + e + "=" + t[e];
return r.substr(1);
};
wrx.object_length = function(t){
var c = 0;
for(var i in t){
c++;
}
return c;
}