diff --git a/types/i18n-abide/i18n-abide-tests.ts b/types/i18n-abide/i18n-abide-tests.ts new file mode 100644 index 0000000000..6e95f52475 --- /dev/null +++ b/types/i18n-abide/i18n-abide-tests.ts @@ -0,0 +1,38 @@ +import * as i18n from 'i18n-abide'; + +const emptyAbideOptions: i18n.AbideOptions = {}; +const fullAbideOptions: i18n.AbideOptions = { + gettext_alias: 'gettext', + supported_languages: ['en-US'], + default_lang: 'en-US', + debug_lang: 'it-CH', + disable_locale_check: false, + translation_directory: 'l18n/', + logger: { warn(msg: string) {}, error(msg: string) {} }, +}; + +i18n.abide(); // $ExpectType RequestHandler +i18n.abide(emptyAbideOptions); // $ExpectType RequestHandler +i18n.abide(fullAbideOptions); // $ExpectType RequestHandler + +i18n.parseAcceptLanguage(""); // $ExpectType { lang: string; quality: number; }[] + +i18n.bestLanguage([{lang: 'en-US', quality: 1.0}], ['en-US'], 'en-US'); // $ExpectType string + +i18n.localeFrom(); // $ExpectType string +i18n.localeFrom(""); // $ExpectType string + +i18n.languageFrom(); // $ExpectType string +i18n.languageFrom(""); // $ExpectType string + +i18n.normalizeLanguage(); // $ExpectType string +i18n.normalizeLanguage(""); // $ExpectType string + +i18n.normalizeLocale(); // $ExpectType string +i18n.normalizeLocale(""); // $ExpectType string + +i18n.format(""); // $ExpectType string +i18n.format("", {}); // $ExpectType string +i18n.format("", {}, false); // $ExpectType string + +i18n.getLocales(); // $ExpectType string[] diff --git a/types/i18n-abide/index.d.ts b/types/i18n-abide/index.d.ts new file mode 100644 index 0000000000..9f824b695b --- /dev/null +++ b/types/i18n-abide/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for i18n-abide 0.0 +// Project: https://github.com/mozilla/i18n-abide +// Definitions by: Steven Bell +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { RequestHandler } from 'express'; + +export function abide(options?: AbideOptions): RequestHandler; +export function parseAcceptLanguage(header?: string): Array<{ lang: string, quality: number }>; +export function bestLanguage(languages: Array<{ lang: string, quality: number}>, supported_languages: string[], defaultLanguage: string): string; +export function localeFrom(language?: string): string; +export function languageFrom(locale?: string): string; +export function normalizeLanguage(language?: string): string; +export function normalizeLocale(locale?: string): string; +export function format(fmt: string, obj?: any, named?: boolean): string; +export function getLocales(): string[]; + +export interface AbideOptions { + gettext_alias?: string; + supported_languages?: string[]; + default_lang?: string; + debug_lang?: string; + disable_locale_check?: boolean; + translation_directory?: string; + logger?: { warn(msg: string): void, error(msg: string): void }; +} diff --git a/types/i18n-abide/tsconfig.json b/types/i18n-abide/tsconfig.json new file mode 100644 index 0000000000..43310061aa --- /dev/null +++ b/types/i18n-abide/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "i18n-abide-tests.ts" + ] +} diff --git a/types/i18n-abide/tslint.json b/types/i18n-abide/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/i18n-abide/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }