Add html unescape function

This commit is contained in:
lowlighter
2021-02-27 22:23:19 +01:00
parent c2248a2638
commit 08506f7e14

View File

@@ -86,6 +86,16 @@
.replace(/'/g, u["'"] ? "'" : "'") .replace(/'/g, u["'"] ? "'" : "'")
} }
/**Unescape html */
export function htmlunescape(string, u = {"&":true, "<":true, ">":true, '"':true, "'":true}) {
return string
.replace(/&lt;/g, u["<"] ? "<" : "&lt;")
.replace(/&gt;/g, u[">"] ? ">" : "&gt;")
.replace(/&quot;/g, u['"'] ? '"' : '&quot;')
.replace(/&apos;/g, u["'"] ? "'" : "&apos;")
.replace(/&amp;/g, u["&"] ? "&" : "&amp;")
}
/**Run command */ /**Run command */
export async function run(command, options, {prefixed = true} = {}) { export async function run(command, options, {prefixed = true} = {}) {
const prefix = {win32:"wsl"}[process.platform] ?? "" const prefix = {win32:"wsl"}[process.platform] ?? ""