Skip to content

Commit c65971c

Browse files
committed
make eslint manual fixes
1 parent dee9efb commit c65971c

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ class Internationalization<T extends string> {
4343
// If the DOM isn't accessible the website may be rendered on a server
4444
if (canUseDOM()) {
4545
// Get browser language
46-
let browserLanguage =
47-
(navigator.languages && navigator.languages[0]) || navigator.language
46+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
47+
let browserLanguage = navigator.languages?.[0] || navigator.language
4848

4949
// Check if the browser language is in the format of xx-XX, extract the first part
50-
if (/^[a-zA-z]{2}\-/.test(browserLanguage)) {
50+
if (/^[a-zA-z]{2}-/.test(browserLanguage)) {
5151
browserLanguage = browserLanguage.substring(0, 2)
5252
}
5353

5454
return (
5555
this.supportedLanguages.find((lang) =>
5656
isEqualCaseInsensitive(lang, browserLanguage),
57-
) || this.fallbackLanguage
57+
) ?? this.fallbackLanguage
5858
)
5959
}
6060

@@ -74,7 +74,7 @@ class Internationalization<T extends string> {
7474
const cookieLanguage =
7575
this.supportedLanguages.find((lang) =>
7676
isEqualCaseInsensitive(lang, language),
77-
) || this.fallbackLanguage
77+
) ?? this.fallbackLanguage
7878

7979
setCookie(this.cookieName, cookieLanguage)
8080
}
@@ -103,7 +103,7 @@ class Internationalization<T extends string> {
103103
// Get accept language from request header
104104
const acceptLanguage = request.headers['accept-language']
105105

106-
if (acceptLanguage) {
106+
if (acceptLanguage && typeof acceptLanguage === 'string') {
107107
// Extract the locale string and the priority from header string
108108
const requestedLocales = acceptLanguage.split(',').map((part) => {
109109
const [locale, priority] = part.trim().split(';q=')
@@ -135,15 +135,15 @@ class Internationalization<T extends string> {
135135
const language = getCookieFromDocument(this.cookieName)
136136

137137
// If cookie is undefined get the language form the browser
138-
if (language == undefined) {
138+
if (language === undefined) {
139139
return this.detectBrowserLanguage()
140140
}
141141

142142
// Return found language or fallback language
143143
return (
144144
this.supportedLanguages.find((lang) =>
145145
isEqualCaseInsensitive(lang, language),
146-
) || this.fallbackLanguage
146+
) ?? this.fallbackLanguage
147147
)
148148
}
149149

src/utilities.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getCookieFromRequest(
2929
name: string,
3030
request: IncomingMessage,
3131
): string | undefined {
32-
if (request.headers?.cookie) {
32+
if (request.headers.cookie) {
3333
const pattern = getCookiePattern(name)
3434
const matched = request.headers.cookie.match(pattern)
3535

@@ -59,9 +59,8 @@ function setCookie(name: string, value: string): void {
5959
*/
6060
function canUseDOM(): boolean {
6161
return Boolean(
62-
typeof window !== 'undefined' &&
63-
window.document &&
64-
window.document.createElement,
62+
// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-deprecated
63+
typeof window !== 'undefined' && window.document?.createElement,
6564
)
6665
}
6766

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"declaration": true,
77
"outDir": "./dist",
88
"strict": true,
9-
"esModuleInterop": true
9+
"esModuleInterop": true,
10+
"types": ["node", "jest"]
1011
},
1112
"include": ["src"],
1213
"exclude": ["node_modules", "**/__test__/*", "**/__tests__/*"]

0 commit comments

Comments
 (0)