add jsdoc comments

This commit is contained in:
lchen committed 2026-11-18 10:14:21 +08:00
1 parent 6de354ad47
commit 8c1205bc13
24 files changed
+1228 -425

No files matched your search

+41 -7
View File
@@ -1,7 +1,17 @@
/**
* @param {string | null} [s]
* @returns {s is null | undefined | ""}
*/
export function nullOrEmpty(s) {
return s == null || typeof s !== 'string' || s.length === 0;
}
/**
* @param {string} s
* @param {string} key
* @param {boolean} [ignoreCase]
* @returns {boolean}
*/
export function contains(s, key, ignoreCase) {
if (nullOrEmpty(s) || key == null) {
return false;
@@ -15,6 +25,11 @@ export function contains(s, key, ignoreCase) {
return s.includes(key);
}
/**
* @param {string} s
* @param {string} suffix
* @returns {boolean}
*/
export function endsWith(s, suffix) {
if (nullOrEmpty(s) || nullOrEmpty(suffix)) {
return false;
@@ -22,6 +37,12 @@ export function endsWith(s, suffix) {
return s.endsWith(suffix); // === s.length - suffix.length;
}
/**
* @param {string} s
* @param {number} num
* @param {string} char
* @returns {string}
*/
export function padStart(s, num, char) {
if (nullOrEmpty(s) || isNaN(num) || num <= s.length) {
return s;
@@ -29,6 +50,10 @@ export function padStart(s, num, char) {
return (char ?? ' ').repeat(num - s.length);
}
/**
* @param {string} msg
* @returns {string}
*/
export function formatUrl(msg) {
//const urlReg = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ig;
//const urlArrray = str.match(urlReg);
@@ -36,7 +61,7 @@ export function formatUrl(msg) {
const r = msg.match(p);
msg = escapeHtml(msg);
if (r?.length > 0) {
if (r != null && r.length > 0) {
const rs = [];
for (let t of r) {
t = t.replace(/["'\r\n ]/g, '');
@@ -45,13 +70,14 @@ export function formatUrl(msg) {
}
}
const win = typeof window !== 'undefined' ? window : self;
let path;
if (typeof consts !== 'undefined') {
path = consts.path;
} else if (typeof _network !== 'undefined') {
path = _network.root;
} else if (typeof _net !== 'undefined') {
path = _net.root;
if (typeof win.consts !== 'undefined') {
path = win.consts.path;
} else if (typeof win._network !== 'undefined') {
path = win._network.root;
} else if (typeof win._net !== 'undefined') {
path = win._net.root;
}
for (let r of rs) {
msg = msg.replaceAll(r, `<a target="_blank" href="${r}"><svg><use xlink:href="${path || ''}fonts/fa-regular.svg#link"></use></svg></a>`);
@@ -61,6 +87,10 @@ export function formatUrl(msg) {
return msg;
}
/**
* @param {string} text
* @returns {string}
*/
export function escapeHtml(text) {
if (text == null) {
return '';
@@ -74,6 +104,10 @@ export function escapeHtml(text) {
.replaceAll(' ', '&nbsp;');
}
/**
* @param {string} text
* @returns {string}
*/
export function escapeEmoji(text) {
if (text == null) {
return '';