37 lines
805 B
JavaScript
37 lines
805 B
JavaScript
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;
|
|
}
|
|
return (char ?? ' ').repeat(num - s.length);
|
|
}
|
|
|
|
export {
|
|
nullOrEmpty,
|
|
contains,
|
|
endsWith,
|
|
padStart
|
|
} |