Skip to content

Commit 32e2216

Browse files
authored
style: Minor changes
1 parent 8cbfbc3 commit 32e2216

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* MIT License
55
*
6-
* Copyright (c) 2016 - 1019 The Node Fetch Team
6+
* Copyright (c) 2016 - 2019 The Node Fetch Team
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the 'Software'), to deal
@@ -42,27 +42,21 @@ export function convertBody(buffer: Buffer, headers?: Headers): string {
4242
let charset: string
4343

4444
// Header
45-
if (contentType) {
46-
charset = getCharSet(contentType)
47-
}
45+
if (contentType) charset = getCharSet(contentType)
4846

4947
// No charset in content type, peek at response body for at most 1024 bytes
5048
const res = buffer.slice(0, 1024).toString()
5149

5250
// HTML5, HTML4 and XML
53-
if (!charset && res) {
54-
charset = getCharSet(
55-
$(res)("meta[charset]").attr("charset") || // HTML5
56-
$(res)("meta[http-equiv][content]").attr("content") || // HTML4
57-
$(res.replace(/<\?(.*)\?>/im, "<$1>"), { xmlMode: true }).root().find("xml").attr("encoding") // XML
58-
)
59-
}
51+
if (!charset && res) charset = getCharSet(
52+
$(res)("meta[charset]").attr("charset") || // HTML5
53+
$(res)("meta[http-equiv][content]").attr("content") || // HTML4
54+
$(res.replace(/<\?(.*)\?>/im, "<$1>"), { xmlMode: true }).root().find("xml").attr("encoding") // XML
55+
)
6056

6157
// Prevent decode issues when sites use incorrect encoding
6258
// ref: https://hsivonen.fi/encoding-menu/
63-
if (charset && charset.toLowerCase() in ["gb2312", "gbk"]) {
64-
charset = "gb18030"
65-
}
59+
if (charset && charset.toLowerCase() in ["gb2312", "gbk"]) charset = "gb18030"
6660

6761
// Turn raw buffers into a single utf-8 buffer
6862
return convert(

0 commit comments

Comments
 (0)