{
titleCase(value) {
if (value == null || value.length === 0) return value;
return value.replace(/^[a-z]/, (matchStr) => {
return matchStr.toLocaleUpperCase();
});
},
trim(value) {
return value.replace(/(^\s*)|(\s*$)/g, "");
},
trimAll(value) {
return value.replace(/\s+/g, "")
},
replaceAll(value,repstr, newstr) {
return value.replace(new RegExp(repstr, "gm"), newstr);
},
phoneFormatter(value) {
if(!value){
return value;
}
return value.length === 11 ? value.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2') : value;
},
moneyFormatter(value) {
return parseFloat(value).toFixed(2).toString().split('').reverse().join('').replace(/(\d{3})/g, '$1,')
.replace(
/\,$/, '').split('').reverse().join('');
},
moneyFormatter(value) {
return parseFloat(value).toFixed(2).toString().split('').reverse().join('').replace(/(\d{3})/g, '$1,')
.replace(
/\,$/, '').split('').reverse().join('');
},
}
String.prototype.splitString = function(divide){
if(!this){
return [];
}
if(this.indexOf(divide)==-1){
return [this];
}
return this.split(divide);
},
Date.prototype.format = function(fmt) {
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"H+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
.length)));
}
}
return fmt;
}
String.prototype.toDate = function() {
return new Date(this.replace(/\-/g, '/'));
}