communications app, popup lib
This commit is contained in:
3
lib/utility/strings.d.ts
vendored
3
lib/utility/strings.d.ts
vendored
@ -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
|
@ -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"];
|
||||
|
@ -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('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('\r\n', '<br/>')
|
||||
.replaceAll('\n', '<br/>')
|
||||
.replaceAll(' ', ' ');
|
||||
@ -61,5 +71,6 @@ export {
|
||||
contains,
|
||||
endsWith,
|
||||
padStart,
|
||||
formatUrl
|
||||
formatUrl,
|
||||
escapeHtml
|
||||
}
|
Reference in New Issue
Block a user