(value = '', options = {})
| 186 | } |
| 187 | |
| 188 | function quotedPrintableToBytes(value = '', options = {}) { |
| 189 | const { headerMode = false } = options; |
| 190 | const source = String(value || '') |
| 191 | .replace(/=\r?\n/g, '') |
| 192 | .replace(headerMode ? /_/g : /$^/, ' '); |
| 193 | |
| 194 | const bytes = []; |
| 195 | for (let index = 0; index < source.length; index += 1) { |
| 196 | const char = source[index]; |
| 197 | if (char === '=' && /^[0-9A-Fa-f]{2}$/.test(source.slice(index + 1, index + 3))) { |
| 198 | bytes.push(parseInt(source.slice(index + 1, index + 3), 16)); |
| 199 | index += 2; |
| 200 | continue; |
| 201 | } |
| 202 | bytes.push(char.charCodeAt(0)); |
| 203 | } |
| 204 | return Uint8Array.from(bytes); |
| 205 | } |
| 206 | |
| 207 | function decodeBytesToString(bytes, charset = 'utf-8') { |
| 208 | const normalizedCharset = String(charset || 'utf-8').trim().toLowerCase(); |
no outgoing calls
no test coverage detected