Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor decodefield function and enhance JSDoc comments #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,24 @@ function format (obj) {
*
* @param {string} str
* @return {string}
* @throws {TypeError}
* @private
*/

function decodefield (str) {
var match = EXT_VALUE_REGEXP.exec(str)
const match = EXT_VALUE_REGEXP.exec(str)

if (!match) {
throw new TypeError('invalid extended field value')
}

var charset = match[1].toLowerCase()
var encoded = match[2]
var value
const [, charset, encoded] = match
let value

// to binary string
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode)
const binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode)

switch (charset) {
switch (charset.toLowerCase()) {
case 'iso-8859-1':
value = getlatin1(binary)
break
Expand Down