diff --git a/types/ladjs__country-language/.npmignore b/types/ladjs__country-language/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/ladjs__country-language/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/ladjs__country-language/index.d.ts b/types/ladjs__country-language/index.d.ts new file mode 100644 index 00000000000000..b897d96aa2d034 --- /dev/null +++ b/types/ladjs__country-language/index.d.ts @@ -0,0 +1,87 @@ + +export type CountryLanguageCallback = (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 & { + 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 & { + languages: ExtendedLanguageData[]; +} + +export function getLanguageCodes(languageCodeType: CodeType, callback: CountryLanguageCallback): T; +export function getLanguageCodes(callback: CountryLanguageCallback): T; +export function getLanguageCodes(languageCodeType?: CodeType): string[]; + +export function getCountryCodes(countryCodeType: CodeType, callback: CountryLanguageCallback): T; +export function getCountryCodes(callback: CountryLanguageCallback): T; +export function getCountryCodes(countryCodeType?: CodeType): string[]; + +export function languageCodeExists(languageCode: string): boolean; + +export function countryCodeExists(countryCode: string): boolean; + +export function getCountry(countryCode: string, callback: CountryLanguageCallback): T; +export function getCountry(countryCode: string): DetailedCountryData; + +export function getLanguage(languageCode: string, callback: CountryLanguageCallback): T; +export function getLanguage(languageCode: string): DetailedLanguageData; + +export function getCountryLanguages(countryCode: string, callback: CountryLanguageCallback): T; +export function getCountryLanguages(countryCode: string): LanguageData[]; + +export function getLanguageCountries(languageCode: string, callback: CountryLanguageCallback): T; +export function getLanguageCountries(languageCode: string): CountryData[]; + +export function getCountryMsLocales(countryCode: string, callback: CountryLanguageCallback): T; +export function getCountryMsLocales(countryCode: string): LanguageCultureData[]; + +export function getLanguageMsLocales(languageCode: string, callback: CountryLanguageCallback): 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(family: string, callback: CountryLanguageCallback): T; +export function getLanguageFamilyMembers(family: string): DetailedLanguageData[]; diff --git a/types/ladjs__country-language/ladjs__country-language-tests.ts b/types/ladjs__country-language/ladjs__country-language-tests.ts new file mode 100644 index 00000000000000..00f12483309962 --- /dev/null +++ b/types/ladjs__country-language/ladjs__country-language-tests.ts @@ -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; + }); + } +}); diff --git a/types/ladjs__country-language/package.json b/types/ladjs__country-language/package.json new file mode 100644 index 00000000000000..5ff42b891a7ace --- /dev/null +++ b/types/ladjs__country-language/package.json @@ -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" + } + ] +} diff --git a/types/ladjs__country-language/tsconfig.json b/types/ladjs__country-language/tsconfig.json new file mode 100644 index 00000000000000..382921e1c1fd2e --- /dev/null +++ b/types/ladjs__country-language/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ladjs__country-language-tests.ts" + ] +}