Skip to content

Commit a41de94

Browse files
authored
🤖 Merge PR DefinitelyTyped#72255 [@sabaki/sgf] Add definitions for "@sabaki/sgf" by @tkzwhr
1 parent 936968b commit a41de94

File tree

10 files changed

+355
-0
lines changed

10 files changed

+355
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
export * from "./src/main";
2+
3+
export namespace Types {
4+
type Primitive = string | number | symbol;
5+
6+
type Property =
7+
| "AB"
8+
| "AE"
9+
| "AN"
10+
| "AP"
11+
| "AR"
12+
| "AS"
13+
| "AW"
14+
| "B"
15+
| "BL"
16+
| "BM"
17+
| "BR"
18+
| "BT"
19+
| "C"
20+
| "CA"
21+
| "CP"
22+
| "CR"
23+
| "DD"
24+
| "DM"
25+
| "DO"
26+
| "DT"
27+
| "EV"
28+
| "FF"
29+
| "FG"
30+
| "GB"
31+
| "GC"
32+
| "GM"
33+
| "GN"
34+
| "GW"
35+
| "HA"
36+
| "HO"
37+
| "IP"
38+
| "IT"
39+
| "IY"
40+
| "KM"
41+
| "KO"
42+
| "LB"
43+
| "LN"
44+
| "MA"
45+
| "MN"
46+
| "N"
47+
| "OB"
48+
| "ON"
49+
| "OT"
50+
| "OW"
51+
| "PB"
52+
| "PC"
53+
| "PL"
54+
| "PM"
55+
| "PW"
56+
| "RE"
57+
| "RO"
58+
| "RU"
59+
| "SE"
60+
| "SL"
61+
| "SO"
62+
| "SQ"
63+
| "ST"
64+
| "SU"
65+
| "SZ"
66+
| "TB"
67+
| "TE"
68+
| "TM"
69+
| "TR"
70+
| "TW"
71+
| "UC"
72+
| "US"
73+
| "V"
74+
| "VW"
75+
| "W"
76+
| "WL"
77+
| "WR"
78+
| "WT";
79+
80+
interface SGFToken {
81+
type: string;
82+
value: string;
83+
row: number;
84+
col: number;
85+
pos: number;
86+
progress: number;
87+
}
88+
89+
interface NodeObject<ID extends Primitive = number> {
90+
id: ID;
91+
data: Partial<Record<Property, string[]>>;
92+
parentId: ID | null;
93+
children: NodeObject<ID>[];
94+
}
95+
96+
type Vertex = [number, number];
97+
98+
type Dates = [number, number?, number?];
99+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"name": "@types/sabaki__sgf",
4+
"version": "3.4.9999",
5+
"projects": [
6+
"https://github.com/SabakiHQ/sgf"
7+
],
8+
"dependencies": {
9+
"@types/node": "*"
10+
},
11+
"devDependencies": {
12+
"@types/sabaki__sgf": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "Hiroki Takizawa",
17+
"githubUsername": "tkzwhr"
18+
}
19+
]
20+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import sgf from "sabaki__sgf";
2+
3+
const genIdString = ((id) => () => "id_" + (id++))(0);
4+
5+
// ===============
6+
// Basic Functions
7+
// ===============
8+
9+
// $ExpectType Generator<SGFToken, void, any> || Generator<SGFToken, void, unknown>
10+
sgf.tokenizeIter("foo");
11+
12+
// $ExpectType SGFToken[]
13+
const tokens = sgf.tokenize("foo");
14+
15+
// $ExpectType Generator<SGFToken, void, any> || Generator<SGFToken, void, unknown>
16+
sgf.tokenizeBufferIter(Buffer.from("foo"));
17+
18+
// $ExpectType SGFToken[]
19+
sgf.tokenizeBuffer(Buffer.from("foo"));
20+
21+
// $ExpectType NodeObject<number>[]
22+
const nodes1 = sgf.parseTokens(tokens);
23+
// $ExpectType number
24+
nodes1[0].id;
25+
// $ExpectType Partial<Record<Property, string[]>>
26+
nodes1[0].data;
27+
// $ExpectType number | null
28+
nodes1[0].parentId;
29+
// $ExpectType NodeObject<number>[]
30+
nodes1[0].children;
31+
32+
// $ExpectType NodeObject<string>[]
33+
const nodes2 = sgf.parseTokens(tokens, {
34+
getId: genIdString,
35+
});
36+
// $ExpectType string
37+
nodes2[0].id;
38+
// $ExpectType Partial<Record<Property, string[]>>
39+
nodes2[0].data;
40+
// $ExpectType string | null
41+
nodes2[0].parentId;
42+
// $ExpectType NodeObject<string>[]
43+
nodes2[0].children;
44+
45+
// $ExpectType NodeObject<number>[]
46+
sgf.parse("foo");
47+
48+
// $ExpectType NodeObject<string>[]
49+
sgf.parse("foo", {
50+
getId: genIdString,
51+
});
52+
53+
// $ExpectType NodeObject<number>[]
54+
sgf.parseBuffer(Buffer.from("foo"));
55+
56+
// $ExpectType NodeObject<string>[]
57+
sgf.parseBuffer(Buffer.from("foo"), {
58+
getId: genIdString,
59+
});
60+
61+
// $ExpectType NodeObject<number>[]
62+
sgf.parseFile("foo");
63+
64+
// $ExpectType NodeObject<string>[]
65+
sgf.parseFile("foo", {
66+
getId: genIdString,
67+
});
68+
69+
// $ExpectType string
70+
sgf.stringify(nodes1);
71+
72+
// ================
73+
// Helper Functions
74+
// ================
75+
76+
// $ExpectType string
77+
const escaped = sgf.escapeString("foo");
78+
79+
// $ExpectType string
80+
sgf.unescapeString(escaped);
81+
82+
// $ExpectType Vertex
83+
const vertex = sgf.parseVertex("foo");
84+
85+
// $ExpectType string
86+
sgf.stringifyVertex(vertex);
87+
88+
// $ExpectType Vertex[]
89+
sgf.parseCompressedVertices("foo");
90+
91+
// $ExpectType Dates[] | null
92+
const dates = sgf.parseDates("foo");
93+
94+
// $ExpectType string
95+
sgf.stringifyDates(dates ?? []);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Types } from "../index";
2+
3+
export function escapeString(input: string): string;
4+
5+
export function unescapeString(input: string): string;
6+
7+
export function parseVertex(input: string): Types.Vertex;
8+
9+
export function stringifyVertex(input: Types.Vertex): string;
10+
11+
export function parseCompressedVertices(input: string): Types.Vertex[];
12+
13+
export function parseDates(input: string): Types.Dates[] | null;
14+
15+
export function stringifyDates(input: readonly Types.Dates[]): string;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
escapeString,
3+
parseCompressedVertices,
4+
parseDates,
5+
parseVertex,
6+
stringifyDates,
7+
stringifyVertex,
8+
unescapeString,
9+
} from "./helper";
10+
import { parse, parseBuffer, parseFile, parseTokens } from "./parse";
11+
import { stringify } from "./stringify";
12+
import { tokenize, tokenizeBuffer, tokenizeBufferIter, tokenizeIter } from "./tokenize";
13+
14+
export {
15+
escapeString,
16+
parse,
17+
parseBuffer,
18+
parseCompressedVertices,
19+
parseDates,
20+
parseFile,
21+
parseTokens,
22+
parseVertex,
23+
stringify,
24+
stringifyDates,
25+
stringifyVertex,
26+
tokenize,
27+
tokenizeBuffer,
28+
tokenizeBufferIter,
29+
tokenizeIter,
30+
unescapeString,
31+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="node" />
2+
3+
import { Types } from "../index";
4+
5+
export interface ParseTokensOptions<ID extends Types.Primitive = number> {
6+
getId?: () => ID;
7+
dictionary?: null;
8+
onProgress?: ({ progress }: { progress: number }) => void;
9+
onNodeCreated?: ({ node }: { node: Types.NodeObject<ID> }) => void;
10+
}
11+
12+
export interface ParseBufferOptions<ID extends Types.Primitive = number> {
13+
encoding?: string;
14+
getId?: () => ID;
15+
dictionary?: null;
16+
onProgress?: ({ progress }: { progress: number }) => void;
17+
}
18+
19+
export function parseTokens<ID extends Types.Primitive = number>(
20+
tokens: readonly Types.SGFToken[],
21+
options?: ParseTokensOptions<ID>,
22+
): Types.NodeObject<ID>[];
23+
24+
export function parse<ID extends Types.Primitive = number>(
25+
contents: string,
26+
options?: ParseTokensOptions<ID>,
27+
): Types.NodeObject<ID>[];
28+
29+
export function parseBuffer<ID extends Types.Primitive = number>(
30+
contents: Buffer,
31+
options?: ParseBufferOptions<ID>,
32+
): Types.NodeObject<ID>[];
33+
34+
export function parseFile<ID extends Types.Primitive = number>(
35+
filename: string,
36+
options?: ParseBufferOptions<ID>,
37+
): Types.NodeObject<ID>[];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Types } from "../index";
2+
3+
export interface StringifyOptions {
4+
linebreak?: string;
5+
indent?: string;
6+
}
7+
8+
export function stringify<ID extends Types.Primitive>(
9+
nodes: Types.NodeObject<ID>[] | Types.NodeObject<ID>,
10+
options?: StringifyOptions,
11+
): string;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference types="node" />
2+
3+
import { Types } from "../index";
4+
5+
export interface TokenizeBufferIterOptions {
6+
encoding?: string;
7+
}
8+
9+
export function tokenizeIter(contents: string): Generator<Types.SGFToken, void>;
10+
11+
export function tokenize(contents: string): Types.SGFToken[];
12+
13+
export function tokenizeBufferIter(
14+
buffer: Buffer,
15+
options?: TokenizeBufferIterOptions,
16+
): Generator<Types.SGFToken, void>;
17+
18+
export function tokenizeBuffer(buffer: Buffer, options?: TokenizeBufferIterOptions): Types.SGFToken[];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"src/main.d.ts",
18+
"src/helper.d.ts",
19+
"src/parse.d.ts",
20+
"src/stringify.d.ts",
21+
"src/tokenize.d.ts",
22+
"sabaki__sgf-tests.ts"
23+
]
24+
}

0 commit comments

Comments
 (0)