@taraflex/decode-html
Advanced tools
+1
-1
| { | ||
| "name": "@taraflex/decode-html", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
-15
| import { decode } from 'iconv-lite'; | ||
| import lastMatch from 'last-match'; | ||
| const CHARSET_RE = /charset\s*=\s*"*\s*([-a-z0-9]+)/i; | ||
| export default (buf: Buffer, mime?: string) => { | ||
| let charset = mime ? lastMatch(mime, CHARSET_RE) : null; | ||
| let uBuf: string = null; | ||
| if (!charset) { | ||
| uBuf = buf.toString('utf-8'); | ||
| charset = lastMatch(uBuf, CHARSET_RE) || 'utf-8'; | ||
| } | ||
| charset = charset.toLowerCase(); | ||
| return charset === 'utf-8' && uBuf ? uBuf : decode(buf, charset); | ||
| } |
1681
-23.38%4
-20%36
-25%