Skip to content

Commit

Permalink
linting src
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed May 13, 2024
1 parent d13d01b commit 0c161fe
Show file tree
Hide file tree
Showing 19 changed files with 10,116 additions and 10,069 deletions.
6,758 changes: 3,379 additions & 3,379 deletions src/data/countries-extra.ts

Large diffs are not rendered by default.

3,600 changes: 1,800 additions & 1,800 deletions src/data/countries-geo.ts

Large diffs are not rendered by default.

3,002 changes: 1,501 additions & 1,501 deletions src/data/countries-iso.ts

Large diffs are not rendered by default.

1,820 changes: 910 additions & 910 deletions src/data/lang-iso.ts

Large diffs are not rendered by default.

3,434 changes: 1,717 additions & 1,717 deletions src/data/lang-iso3.ts

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/fallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* @return {string | undefined} - The generated fallback country code or undefined if no fallback is available.
*/
export function tryCountriesFallback(language: string): string | undefined {
// Fallback for specific languages
const fallbackMap: { [key: string]: string } = {
en: 'US', // Fallback English to en_US - the United States
zh: 'CN', // Fallback Chinese (Simplified) to zh_CN - China
ar: 'SA', // Fallback Arabic to ar_SA - Saudi Arabia
ja: 'JP', // Fallback Japanese to ja_JP - Japan
ko: 'KR', // Fallback Korean to ko_KR - South Korea
sv: 'SE', // Fallback Swedish to sv_SE - Sweden
hi: 'IN', // Fallback Hindi to hi_IN - India
}
// Fallback for specific languages
const fallbackMap: { [key: string]: string } = {
en: "US", // Fallback English to en_US - the United States
zh: "CN", // Fallback Chinese (Simplified) to zh_CN - China
ar: "SA", // Fallback Arabic to ar_SA - Saudi Arabia
ja: "JP", // Fallback Japanese to ja_JP - Japan
ko: "KR", // Fallback Korean to ko_KR - South Korea
sv: "SE", // Fallback Swedish to sv_SE - Sweden
hi: "IN", // Fallback Hindi to hi_IN - India
};

// Check if there's a fallback for the given language
if (fallbackMap[language]) {
return fallbackMap[language]
}
// Check if there's a fallback for the given language
if (fallbackMap[language]) {
return fallbackMap[language];
}
}
54 changes: 28 additions & 26 deletions src/formatIso.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getSeparator } from './utils'
import { tryCountriesFallback } from './fallbacks'
import { validateISO } from './validation'
import { getIso } from './getIso'
import { IsoCodeFormat } from './types'
import { tryCountriesFallback } from "./fallbacks";
import { getIso } from "./getIso";
import type { IsoCodeFormat } from "./types";
import { getSeparator } from "./utils";
import { validateISO } from "./validation";

/**
* Formats the language and country into a single string.
Expand All @@ -13,31 +13,33 @@ import { IsoCodeFormat } from './types'
* @returns The formatted string combining the language and country code.
*/
export function formatIso(
language: string | undefined,
country?: string | undefined,
separator?: string | IsoCodeFormat
language: string | undefined,
country?: string | undefined,
separator?: string | IsoCodeFormat,
): string | false {
let isoLanguage = language && validateISO(language, 'language') ? language : undefined
let isoCountry = country && validateISO(country, 'country') ? country : undefined
separator = getSeparator(separator)
let isoLanguage =
language && validateISO(language, "language") ? language : undefined;
let isoCountry =
country && validateISO(country, "country") ? country : undefined;
separator = getSeparator(separator);

if (!isoLanguage && language) {
isoLanguage = (getIso(language, 'language', 'iso2') as string) || undefined
}
if (!isoLanguage && language) {
isoLanguage = (getIso(language, "language", "iso2") as string) || undefined;
}

if (!isoCountry && language) {
isoCountry = tryCountriesFallback(language)
}
if (!isoCountry && language) {
isoCountry = tryCountriesFallback(language);
}

if (!isoCountry && country) {
isoCountry = (getIso(country, 'country', 'iso2') as string) || undefined
}
if (!isoCountry && country) {
isoCountry = (getIso(country, "country", "iso2") as string) || undefined;
}

// Return the formatted string if both language and country are found
if (!!isoLanguage && !!separator && !!isoCountry) {
return isoLanguage + separator + isoCountry
}
// Return the formatted string if both language and country are found
if (!!isoLanguage && !!separator && !!isoCountry) {
return isoLanguage + separator + isoCountry;
}

// Return false if either language or country is not found
return false
// Return false if either language or country is not found
return false;
}
Loading

0 comments on commit 0c161fe

Please sign in to comment.