Added decodeHTML
All checks were successful
Build / Publish Docs (push) Successful in 1m6s
Build / Build NPM Project (push) Successful in 1m10s
Build / Tag Version (push) Successful in 11s

This commit is contained in:
2026-03-29 22:33:21 -04:00
parent 681c89d5af
commit 361613f507
2 changed files with 26 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.28.15",
"version": "0.28.16",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@@ -27,6 +27,31 @@ export function camelCase(str?: string): string {
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
}
/**
* Decode HTML escaped characters
* @param html HTML to clean up
* @returns {any}
*/
export function decodeHtml(html: string) {
return html
.replace(/ /g, '\u00A0')
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&cent;/g, '¢')
.replace(/&pound;/g, '£')
.replace(/&yen;/g, '¥')
.replace(/&euro;/g, '€')
.replace(/&copy;/g, '©')
.replace(/&reg;/g, '®')
.replace(/&trade;/g, '™')
.replace(/&times;/g, '×')
.replace(/&divide;/g, '÷')
.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec))
.replace(/&#x([0-9a-fA-F]+);/g, (match, hex) => String.fromCharCode(parseInt(hex, 16)))
.replace(/&amp;/g, '&'); // Always last!
}
/**
* Convert number of bytes into a human-readable size