From 72194cc4b5cd13b804eeef5711f1bbbf8c32271d Mon Sep 17 00:00:00 2001 From: Lorent Lempereur Date: Wed, 1 Apr 2020 00:27:23 +0200 Subject: [PATCH] [gettext-parser] Create @types (#43325) --- types/gettext-parser/gettext-parser-tests.ts | 21 ++++++++++ types/gettext-parser/index.d.ts | 42 ++++++++++++++++++++ types/gettext-parser/tsconfig.json | 23 +++++++++++ types/gettext-parser/tslint.json | 1 + 4 files changed, 87 insertions(+) create mode 100644 types/gettext-parser/gettext-parser-tests.ts create mode 100644 types/gettext-parser/index.d.ts create mode 100644 types/gettext-parser/tsconfig.json create mode 100644 types/gettext-parser/tslint.json diff --git a/types/gettext-parser/gettext-parser-tests.ts b/types/gettext-parser/gettext-parser-tests.ts new file mode 100644 index 0000000000..804749a284 --- /dev/null +++ b/types/gettext-parser/gettext-parser-tests.ts @@ -0,0 +1,21 @@ +import { po, mo } from 'gettext-parser'; + +let parsed = po.parse("foo", "utf-8"); +let compiled = po.compile(parsed, {}); +parsed = po.parse(Buffer.from("bar")); +compiled = po.compile(parsed, { anyOption: false }); + +parsed = mo.parse(compiled, "wrong-charset"); +compiled = mo.compile(parsed, { noOption: 3 }); + +const charset: string = parsed.charset; + +const firstHeader: string = parsed.headers["firstHeader"]; +const firstHeaderAsString: string = firstHeader; + +const firstTranslation = parsed.translations["firstContext"]["firstTranslation"]; +firstTranslation.msgctxt = firstHeaderAsString; +firstTranslation.msgid = charset; +firstTranslation.msgid_plural; +firstTranslation.msgstr; +firstTranslation.comments; diff --git a/types/gettext-parser/index.d.ts b/types/gettext-parser/index.d.ts new file mode 100644 index 0000000000..e78f53bf7c --- /dev/null +++ b/types/gettext-parser/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for gettext-parser 4.0 +// Project: https://github.com/smhg/gettext-parser +// Definitions by: Lorent Lempereur +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export interface GetTextComment { + translator: string; + reference: string; + extracted: string; + flag: string; + previous: string; +} + +export interface GetTextTranslation { + msgctxt?: string; + msgid: string; + msgid_plural?: any; + msgstr: string[]; + comments?: GetTextComment; +} + +export interface GetTextTranslations { + charset: string; + headers: { [headerName: string]: string }; + translations: { [msgctxt: string]: { [msgId: string]: GetTextTranslation } }; +} + +export interface PoParser { + parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations; + compile: (table: GetTextTranslations, options?: any) => Buffer; + createParseStream: (buffer: any, defaultCharset?: string) => any; +} + +export interface MoParser { + parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations; + compile: (table: GetTextTranslations, options?: any) => Buffer; +} + +export const po: MoParser; +export const mo: MoParser; diff --git a/types/gettext-parser/tsconfig.json b/types/gettext-parser/tsconfig.json new file mode 100644 index 0000000000..b1387d6eb0 --- /dev/null +++ b/types/gettext-parser/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gettext-parser-tests.ts" + ] +} \ No newline at end of file diff --git a/types/gettext-parser/tslint.json b/types/gettext-parser/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gettext-parser/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }