upload, string extensions, lgres
This commit is contained in:
40
lib/utility/strings.js
Normal file
40
lib/utility/strings.js
Normal file
@ -0,0 +1,40 @@
|
||||
function nullOrEmpty(s) {
|
||||
return s == null || typeof s !== 'string' || s.length === 0;
|
||||
}
|
||||
|
||||
function contains(s, key, ignoreCase) {
|
||||
if (nullOrEmpty(s) || key == null) {
|
||||
return false;
|
||||
}
|
||||
if (typeof key !== 'string') {
|
||||
key = String(key);
|
||||
}
|
||||
if (ignoreCase) {
|
||||
return s.toLowerCase().indexOf(key.toLowerCase()) >= 0;
|
||||
}
|
||||
return s.indexOf(key) >= 0;
|
||||
}
|
||||
|
||||
function endsWith(s, suffix) {
|
||||
if (nullOrEmpty(s) || nullOrEmpty(suffix)) {
|
||||
return false;
|
||||
}
|
||||
return s.indexOf(suffix) === s.length - suffix.length;
|
||||
}
|
||||
|
||||
function padStart(s, num, char) {
|
||||
if (nullOrEmpty(s) || isNaN(num) || num <= s.length) {
|
||||
return s;
|
||||
}
|
||||
if (char == null) {
|
||||
char = ' ';
|
||||
}
|
||||
return char.repeat(num - s.length);
|
||||
}
|
||||
|
||||
export {
|
||||
nullOrEmpty,
|
||||
contains,
|
||||
endsWith,
|
||||
padStart
|
||||
}
|
Reference in New Issue
Block a user