communications app, popup lib

This commit is contained in:
2023-04-08 11:46:20 +08:00
parent 449196b491
commit f85d4c9903
25 changed files with 746 additions and 279 deletions

View File

@ -2,4 +2,5 @@ export function nullOrEmpty(s?: string | any | null): boolean
export function contains(s: string, key: string | any, ignoreCase?: boolean): boolean
export function endsWith(s: string, suffix: string): boolean
export function padStart(s: string, num: Number, char: string): boolean
export function formatUrl(msg: string): string
export function formatUrl(msg: string): string
export function escapeHtml(text: string): string

View File

@ -54,6 +54,12 @@
<p>
把超链接解析替换为图标
</p>
<h2>escapeHtml</h2>
<code>function escapeHtml(text: string): string</code>
<h3>text: string</h3>
<p>
解析转换 html 代码为显示内容
</p>
<hr />
<h2>用法</h2>
<pre>const util = window["lib-utility"];

View File

@ -34,7 +34,7 @@ function formatUrl(msg) {
//const urlArrray = str.match(urlReg);
const p = /(http|ftp|https):\/\/.+?(\s|\r\n|\r|\n|\"|\'|\*|$)/g;
const r = msg.match(p);
msg = htmlencode(msg);
msg = escapeHtml(msg);
if (r?.length > 0) {
const rs = [];
@ -50,7 +50,17 @@ function formatUrl(msg) {
}
}
return msg
return msg;
}
function escapeHtml(text) {
if (text == null) {
return '';
}
return String(text)
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('\r\n', '<br/>')
.replaceAll('\n', '<br/>')
.replaceAll(' ', '&nbsp;');
@ -61,5 +71,6 @@ export {
contains,
endsWith,
padStart,
formatUrl
formatUrl,
escapeHtml
}