1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-26 10:32:32 +02:00
TableFilter/src/string.js
2015-06-14 01:00:31 +10:00

53 lines
1 KiB
JavaScript

/**
* String utilities
*/
export default {
lower(text){
return text.toLowerCase();
},
upper(text){
return text.toUpperCase();
},
trim(text){
if (text.trim){
return text.trim();
}
return text.replace(/^\s*|\s*$/g, '');
},
isEmpty(text){
return this.trim(text) === '';
},
rgxEsc(text){
// function escape(e){
// let a = new RegExp('\\'+e, 'g');
// text = text.replace(a, '\\'+e);
// }
// let chars = ['\\','[','^','$','.','|','?','*','+','(',')'];
// cache escape + match String
// for(let e=0, len=chars.length; e<len; e++){
// escape(chars[e]);
// }
// return text;
let chars = /[-\/\\^$*+?.()|[\]{}]/g;
let escMatch = '\\$&';
return String(text).replace(chars, escMatch);
},
matchCase(text, mc){
if(!mc){
return this.lower(text);
}
return text;
}
};