Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#68873 [@ladjs/country-language] add types by
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 authored Mar 4, 2024
1 parent 12e27dc commit 08e6fc4
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/ladjs__country-language/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
87 changes: 87 additions & 0 deletions types/ladjs__country-language/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

export type CountryLanguageCallback<T, R> = (error: Error | null, data: T) => R;
export type CodeType = 1 | 2 | 3;
export type Direction = 'LTR' | 'RTL';

export interface LanguageData {
iso639_1: string;
iso639_2: string;
iso639_3: string;
}

export interface ExtendedLanguageData extends LanguageData {
iso639_2en: string;
name: string[];
nativeName: string[];
direction: Direction;
family: string;
countries: string[];
langCultureMs?: LanguageCultureData[];
}

export type DetailedLanguageData = Omit<ExtendedLanguageData, 'countries'> & {
countries: DetailedCountryData[];
}

export interface LanguageCultureData {
langCultureName: string;
displayName: string;
cultureCode: string;
}

export interface CountryData {
code_2: string;
code_3: string;
numCode: string;
}

export interface ExtendedCountryData extends CountryData {
name: string;
languages: string[];
langCultureMs?: LanguageCultureData[];
}

export type DetailedCountryData = Omit<ExtendedCountryData, 'languages'> & {
languages: ExtendedLanguageData[];
}

export function getLanguageCodes<T>(languageCodeType: CodeType, callback: CountryLanguageCallback<string[], T>): T;
export function getLanguageCodes<T>(callback: CountryLanguageCallback<string[], T>): T;
export function getLanguageCodes(languageCodeType?: CodeType): string[];

export function getCountryCodes<T>(countryCodeType: CodeType, callback: CountryLanguageCallback<string[], T>): T;
export function getCountryCodes<T>(callback: CountryLanguageCallback<string[], T>): T;
export function getCountryCodes(countryCodeType?: CodeType): string[];

export function languageCodeExists(languageCode: string): boolean;

export function countryCodeExists(countryCode: string): boolean;

export function getCountry<T>(countryCode: string, callback: CountryLanguageCallback<DetailedCountryData, T>): T;
export function getCountry(countryCode: string): DetailedCountryData;

export function getLanguage<T>(languageCode: string, callback: CountryLanguageCallback<DetailedLanguageData, T>): T;
export function getLanguage(languageCode: string): DetailedLanguageData;

export function getCountryLanguages<T>(countryCode: string, callback: CountryLanguageCallback<LanguageData[], T>): T;
export function getCountryLanguages(countryCode: string): LanguageData[];

export function getLanguageCountries<T>(languageCode: string, callback: CountryLanguageCallback<CountryData[], T>): T;
export function getLanguageCountries(languageCode: string): CountryData[];

export function getCountryMsLocales<T>(countryCode: string, callback: CountryLanguageCallback<LanguageCultureData[], T>): T;
export function getCountryMsLocales(countryCode: string): LanguageCultureData[];

export function getLanguageMsLocales<T>(languageCode: string, callback: CountryLanguageCallback<LanguageCultureData[], T>): T;
export function getLanguageMsLocales(languageCode: string): LanguageCultureData[];

export function getCountries(): ExtendedCountryData[];

export function getLanguages(): ExtendedLanguageData[];

export function getLanguageFamilies(): string[];

export function getLocales(mode?: boolean): string[];

export function getLanguageFamilyMembers<T>(family: string, callback: CountryLanguageCallback<DetailedLanguageData[], T>): T;
export function getLanguageFamilyMembers(family: string): DetailedLanguageData[];
277 changes: 277 additions & 0 deletions types/ladjs__country-language/ladjs__country-language-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
import CountryLanguage = require('@ladjs/country-language');

// $ExpectType string[]
CountryLanguage.getLanguageCodes(2);

// $ExpectType string[]
CountryLanguage.getLanguageCodes(3);

// $ExpectType string[]
CountryLanguage.getLanguageCodes();

// $ExpectType string[]
CountryLanguage.getLanguageCodes(1);

// @ts-expect-error
CountryLanguage.getLanguageCodes(4);

// $ExpectType number[]
CountryLanguage.getLanguageCodes((error, data) => {
// $ExpectType Error | null
error;
// $ExpectType string[]
data;

return data.map((lang) => lang.length);
});

// $ExpectType string[]
CountryLanguage.getCountryCodes(2);

// $ExpectType string[]
CountryLanguage.getCountryCodes(3);

// $ExpectType string[]
CountryLanguage.getCountryCodes();

// $ExpectType string[]
CountryLanguage.getCountryCodes(1);

// @ts-expect-error
CountryLanguage.getCountryCodes(4);

// $ExpectType number[]
CountryLanguage.getCountryCodes((error, data) => {
// $ExpectType Error | null
error;
// $ExpectType string[]
data;

return data.map((country) => country.length);
});

// @ts-expect-error
CountryLanguage.getCountryCodes('foo');

// $ExpectType boolean
CountryLanguage.languageCodeExists('en');

// $ExpectType boolean
CountryLanguage.countryCodeExists('US');

// @ts-expect-error
CountryLanguage.countryCodeExists(Symbol());

// $ExpectType boolean
CountryLanguage.countryCodeExists('RHB');

// $ExpectType boolean
CountryLanguage.countryCodeExists('test');

// @ts-expect-error
CountryLanguage.countryCodeExists(5);

// $ExpectType DetailedCountryData
const country = CountryLanguage.getCountry('US');

// $ExpectType string
country.code_2;

// @ts-expect-error
country.code_6;

// @ts-expect-error
CountryLanguage.getCountry();

// @ts-expect-error
CountryLanguage.getCountry(5);

CountryLanguage.getCountry('GB', function (err, country) {
if (err) {
// $ExpectType Error
err;
} else {
// $ExpectType ExtendedLanguageData[]
country.languages;
}
});

// $ExpectType DetailedLanguageData
const language = CountryLanguage.getLanguage('en');

// $ExpectType string
language.iso639_1;

// @ts-expect-error
language.iso639_4;

// @ts-expect-error
CountryLanguage.getLanguage();

// @ts-expect-error
CountryLanguage.getLanguage(5);

// $ExpectType number
CountryLanguage.getLanguage('en', (error, data) => {
// $ExpectType Error | null
error;
// $ExpectType DetailedLanguageData
data;

return 5;
});

// $ExpectType void
CountryLanguage.getLanguage('en', function (err, language) {
if (err) {
// $ExpectType Error
err;
} else {
// $ExpectType DetailedCountryData[]
language.countries;
}
});

// $ExpectType LanguageData[]
CountryLanguage.getCountryLanguages('LA');

// $ExpectType LanguageData[]
CountryLanguage.getCountryLanguages('GB');

// $ExpectType void
CountryLanguage.getCountryLanguages('GB', function (err, languages) {
if (err) {
// $ExpectType Error
err;
} else {
languages.forEach((languageCodes) => {
// $ExpectType string
languageCodes.iso639_1;
});
}
});

// @ts-expect-error
CountryLanguage.getCountryLanguages();

// @ts-expect-error
CountryLanguage.getCountryLanguages(5);

// $ExpectType LanguageData[][]
CountryLanguage.getCountryLanguages('US', (error, data) => {
// $ExpectType Error | null
error;
// $ExpectType LanguageData[]
data;

return [data];
});

// $ExpectType CountryData[]
CountryLanguage.getLanguageCountries('en');

// $ExpectType CountryData[]
CountryLanguage.getLanguageCountries('eng');

// $ExpectType void
CountryLanguage.getLanguageCountries('en', function (err, countries) {
if (err) {
// $ExpectType Error
err;
} else {
countries.forEach((countryCodes) => {
// $ExpectType string
countryCodes.code_3;
});
}
});

// @ts-expect-error
CountryLanguage.getLanguageCountries();

// $ExpectType LanguageCultureData[]
CountryLanguage.getCountryMsLocales('US');

// $ExpectType LanguageCultureData[]
CountryLanguage.getCountryMsLocales('USA');

// $ExpectType void
CountryLanguage.getCountryMsLocales('GB', function (err, locales) {
if (err) {
// $ExpectType Error
err;
} else {
locales.forEach(function (locale) {
// $ExpectType string
locale.langCultureName;
});
}
});

// @ts-expect-error
CountryLanguage.getCountryMsLocales();

// $ExpectType LanguageCultureData[]
CountryLanguage.getLanguageMsLocales('en');

// $ExpectType LanguageCultureData[]
CountryLanguage.getCountryMsLocales('en-US');

// $ExpectType void
CountryLanguage.getCountryMsLocales('en', function (err, locales) {
if (err) {
// $ExpectType Error
err;
} else {
locales.forEach(function (locale) {
// $ExpectType string
locale.langCultureName;
});
}
});

// @ts-expect-error
CountryLanguage.getCountryMsLocales();

// $ExpectType ExtendedCountryData[]
CountryLanguage.getCountries();

// @ts-expect-error
CountryLanguage.getCountries('CA');

// $ExpectType ExtendedLanguageData[]
CountryLanguage.getLanguages();

// @ts-expect-error
CountryLanguage.getLanguages('en');

// $ExpectType string[]
CountryLanguage.getLanguageFamilies();

// @ts-expect-error
CountryLanguage.getLanguageFamilies('en');

// $ExpectType string[]
CountryLanguage.getLocales();

// $ExpectType string[]
CountryLanguage.getLocales(true);

// $ExpectType string[]
CountryLanguage.getLocales(false);

// @ts-expect-error
CountryLanguage.getLocales(5);

// $ExpectType void
CountryLanguage.getLanguageFamilyMembers('Indo-European', function (err, languages) {
if (err) {
// $ExpectType Error
err;
} else {
languages.forEach(function (language) {
// $ExpectType string[]
language.name;
});
}
});
17 changes: 17 additions & 0 deletions types/ladjs__country-language/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "@types/ladjs__country-language",
"version": "1.0.9999",
"projects": [
"https://github.com/ladjs/country-language"
],
"devDependencies": {
"@types/ladjs__country-language": "workspace:."
},
"owners": [
{
"name": "Tristan F.",
"githubUsername": "LeoDog896"
}
]
}
Loading

0 comments on commit 08e6fc4

Please sign in to comment.