Skip to content

Commit 20b492a

Browse files
authored
feat!(gettext-parser): update types for v8.0.0 (DefinitelyTyped#71749)
1 parent 1791162 commit 20b492a

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

types/gettext-parser/gettext-parser-tests.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import { mo, po } from "gettext-parser";
2+
import { createReadStream } from "node:fs";
23

3-
let parsed = po.parse("foo", "utf-8");
4-
let compiled = po.compile(parsed, {});
4+
let parsed = po.parse("foo", { defaultCharset: "utf-8", validation: true });
5+
parsed = po.parse("foo", { defaultCharset: "utf-8" });
6+
parsed = po.parse("foo", { validation: true });
7+
parsed = po.parse("foo", { validation: false });
58
parsed = po.parse(Buffer.from("bar"));
6-
compiled = po.compile(parsed, { anyOption: false });
7-
const stream = po.createParseStream(Buffer.from("bar"));
8-
stream.on("data", (data) => {
9-
console.log(data);
9+
10+
let compiled = po.compile(parsed, {});
11+
compiled = po.compile(parsed);
12+
compiled = po.compile(parsed, { foldLength: 80 });
13+
compiled = po.compile(parsed, { escapeCharacters: true });
14+
compiled = po.compile(parsed, { escapeCharacters: false });
15+
compiled = po.compile(parsed, { sort: true });
16+
compiled = po.compile(parsed, { sort: false });
17+
compiled = po.compile(parsed, { eol: "\n" });
18+
compiled = po.compile(parsed, { sort: (a, b) => a.msgid.length > b.msgid.length ? 1 : -1 });
19+
20+
const poParseStream = po.createParseStream();
21+
const input = createReadStream("bar");
22+
input.pipe(poParseStream);
23+
poParseStream.on("data", (data) => {
24+
console.log(data.translations[""]);
1025
});
1126

27+
parsed = mo.parse(Buffer.from("bar"), "wrong-charset");
1228
parsed = mo.parse(compiled, "wrong-charset");
13-
compiled = mo.compile(parsed, { noOption: 3 });
1429

1530
const charset: string = parsed.charset;
1631

types/gettext-parser/index.d.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,58 @@
11
/// <reference types="node" />
22

3-
import { Transform } from "readable-stream";
3+
import { Transform, TransformOptions } from "readable-stream";
44

55
export interface GetTextComment {
6-
translator: string;
7-
reference: string;
8-
extracted: string;
9-
flag: string;
10-
previous: string;
6+
translator?: string;
7+
reference?: string;
8+
extracted?: string;
9+
flag?: string;
10+
previous?: string;
1111
}
1212

1313
export interface GetTextTranslation {
14-
msgctxt?: string | undefined;
14+
msgctxt?: string;
1515
msgid: string;
16-
msgid_plural?: any;
16+
msgid_plural?: string;
1717
msgstr: string[];
18-
comments?: GetTextComment | undefined;
18+
comments?: GetTextComment;
19+
obsolete?: boolean;
20+
}
21+
22+
export interface GetTextTranslationRecord {
23+
[msgctxt: string]: {
24+
[msgId: string]: GetTextTranslation;
25+
};
1926
}
2027

2128
export interface GetTextTranslations {
2229
charset: string;
2330
headers: { [headerName: string]: string };
24-
translations: { [msgctxt: string]: { [msgId: string]: GetTextTranslation } };
31+
translations: GetTextTranslationRecord;
32+
obsolete?: GetTextTranslationRecord;
33+
}
34+
35+
export interface GetTextPoParserOptions {
36+
defaultCharset?: string;
37+
validation?: boolean;
38+
}
39+
40+
export interface GetTextPoCompilerOptions {
41+
foldLength?: number;
42+
escapeCharacters?: boolean;
43+
sort?: boolean | ((a: GetTextTranslation, b: GetTextTranslation) => number);
44+
eol?: string;
2545
}
2646

2747
export interface PoParser {
28-
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
29-
compile: (table: GetTextTranslations, options?: any) => Buffer;
30-
createParseStream: (buffer: any, defaultCharset?: string) => Transform;
48+
parse: (buffer: Buffer | string, options?: GetTextPoParserOptions) => GetTextTranslations;
49+
compile: (table: GetTextTranslations, options?: GetTextPoCompilerOptions) => Buffer;
50+
createParseStream: (options?: GetTextPoParserOptions, transformOptions?: TransformOptions) => Transform;
3151
}
3252

3353
export interface MoParser {
3454
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
35-
compile: (table: GetTextTranslations, options?: any) => Buffer;
55+
compile: (table: GetTextTranslations) => Buffer;
3656
}
3757

3858
export const po: PoParser;

types/gettext-parser/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"private": true,
33
"name": "@types/gettext-parser",
4-
"version": "4.0.9999",
4+
"version": "8.0.9999",
5+
"type": "module",
56
"projects": [
67
"https://github.com/smhg/gettext-parser"
78
],

0 commit comments

Comments
 (0)