adjustment

This commit is contained in:
2023-07-27 10:03:53 +08:00
parent 3e9ee59178
commit 29209a3a00
17 changed files with 456 additions and 173 deletions

View File

@ -1,8 +1,8 @@
function nullOrEmpty(s) {
export function nullOrEmpty(s) {
return s == null || typeof s !== 'string' || s.length === 0;
}
function contains(s, key, ignoreCase) {
export function contains(s, key, ignoreCase) {
if (nullOrEmpty(s) || key == null) {
return false;
}
@ -15,21 +15,21 @@ function contains(s, key, ignoreCase) {
return s.indexOf(key) >= 0;
}
function endsWith(s, suffix) {
export function endsWith(s, suffix) {
if (nullOrEmpty(s) || nullOrEmpty(suffix)) {
return false;
}
return s.indexOf(suffix) === s.length - suffix.length;
}
function padStart(s, num, char) {
export function padStart(s, num, char) {
if (nullOrEmpty(s) || isNaN(num) || num <= s.length) {
return s;
}
return (char ?? ' ').repeat(num - s.length);
}
function formatUrl(msg) {
export function formatUrl(msg) {
//const urlReg = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ig;
//const urlArrray = str.match(urlReg);
const p = /(http|ftp|https):\/\/.+?(\s|\r\n|\r|\n|\"|\'|\*|$)/g;
@ -53,7 +53,7 @@ function formatUrl(msg) {
return msg;
}
function escapeHtml(text) {
export function escapeHtml(text) {
if (text == null) {
return '';
}
@ -64,13 +64,4 @@ function escapeHtml(text) {
.replaceAll('\r\n', '<br/>')
.replaceAll('\n', '<br/>')
.replaceAll(' ', '&nbsp;');
}
export {
nullOrEmpty,
contains,
endsWith,
padStart,
formatUrl,
escapeHtml
}