1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-12 19:36:41 +02:00
TableFilter/src-es6/string.js

47 lines
792 B
JavaScript
Raw Normal View History

2014-11-16 01:29:07 +01:00
/**
* String utilities
*/
var Str = {};
Str.lower = function(text){
return text.toLowerCase();
};
Str.upper = function(text){
return text.toUpperCase();
};
Str.trim = function(text){
if (text.trim){
return text.trim();
}
return text.replace(/^\s*|\s*$/g, '');
};
Str.isEmpty = function(text){
return this.trim(text) === '';
};
Str.rgxEsc = function(text){
function escape(e){
2015-05-13 12:54:29 +02:00
var a = new RegExp('\\'+e, 'g');
text = text.replace(a, '\\'+e);
2014-11-16 01:29:07 +01:00
}
var chars = ['\\','[','^','$','.','|','?','*','+','(',')'];
for(var e=0; e<chars.length; e++){
escape(chars[e]);
}
return text;
};
Str.matchCase = function(text, mc){
if(!mc){
return this.lower(text);
}
return text;
};
exports.Str = Str;