@echecs/pgn 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +116 -239
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -15,8 +15,63 @@ yarn add @echecs/pgn
15
15
 
16
16
  ## Usage
17
17
 
18
- We just need to provide with a PGN to the parser. It always return an array
19
- because PGN files could contain several games.
18
+ `parse(input: string): PGN[]`
19
+
20
+ **PGN** format:
21
+
22
+ ```json
23
+ {
24
+ meta: Meta,
25
+ moves: Moves,
26
+ result: 1-0 // 1-0 | 0-1 | 1/2-1/2 | ?
27
+ }
28
+ ```
29
+
30
+ **Meta** format:
31
+
32
+ ```json
33
+ {
34
+ // Based on the PGN specification at least the following Tags should be available
35
+ Event: "the name of the tournament or match event"
36
+ Site: "the location of the event"
37
+ Date: "the starting date of the game"
38
+ Round: "the playing round ordinal of the game"
39
+ White: "the player of the white pieces"
40
+ Black: "the player of the black pieces"
41
+ Result: "the result of the game"
42
+ // plus any other additional tags with `key` string
43
+ [key]: "string"
44
+ }
45
+ ```
46
+
47
+ **Moves** is an _array_ of:
48
+
49
+ ```json
50
+ // move number, white move, black move
51
+ [5, Move, Move]
52
+ ```
53
+
54
+ Notice that half move are available for variations of if the last move of the game was white.
55
+
56
+ **Move** format:
57
+
58
+ ```json
59
+ {
60
+ annotations: ["!", "$126"], // (optional) all the annotations for the given move
61
+ capture: false, // (optional) indicates if the move capture any piece
62
+ castling: true, // (optional) indicates if the move was castling
63
+ check: false, // (optional) indicates if the move checks the rival king
64
+ checkmate: false, // (optional) indicates if it is checkmate
65
+ comment: 'Some comment', // (optional) comment of the move
66
+ from: 'e', // (optional) Disambiguation of the move
67
+ piece: 'K', // (required) P (Pawn) | R (Rook) | N (Knight) | B (Bishop) | Q (Queen) | K (King)
68
+ promotion: Piece; // (optional) R (Rook) | N (Knight) | B (Bishop) | Q (Queen)
69
+ to: 'g1', // ending square of the piece
70
+ variants: [...] // moves following Moves format
71
+ }
72
+ ```
73
+
74
+ **Example**
20
75
 
21
76
  ```js
22
77
  import { readFileSync } from 'fs';
@@ -32,328 +87,150 @@ const pgn = parse(readFile('./games/file.pgn'));
32
87
  // [
33
88
  // {
34
89
  // "meta": {
35
- // "Site": "?",
90
+ // "Black": "Cordts, Ingo",
91
+ // "BlackElo": "2222",
36
92
  // "Date": "2000.10.29",
93
+ // "ECO": "A56",
94
+ // "Result": "0-1",
37
95
  // "Round": "?",
96
+ // "Site": "?",
38
97
  // "White": "Carlsen, Magnus",
39
- // "Black": "Cordts, Ingo",
40
- // "ECO": "A56",
41
98
  // "WhiteElo": "0",
42
- // "BlackElo": "2222",
43
- // "Result": "0-1"
44
99
  // },
45
100
  // "moves": [
46
101
  // [
102
+ // 1,
47
103
  // {
48
104
  // "piece": "P",
49
- // "to": "d4"
105
+ // "to": "d4",
50
106
  // },
51
107
  // {
52
108
  // "piece": "N",
53
- // "to": "f6"
54
- // }
109
+ // "to": "f6",
110
+ // },
55
111
  // ],
56
112
  // [
113
+ // 2,
57
114
  // {
58
115
  // "piece": "P",
59
- // "to": "c4"
116
+ // "to": "c4",
60
117
  // },
61
118
  // {
62
119
  // "piece": "P",
63
- // "to": "c5"
64
- // }
65
- // ],
66
- // [
67
- // {
68
- // "piece": "N",
69
- // "to": "f3"
120
+ // "to": "c5",
70
121
  // },
71
- // {
72
- // "from": "c",
73
- // "piece": "P",
74
- // "to": "d4"
75
- // }
76
122
  // ],
77
123
  // [
124
+ // 3,
78
125
  // {
79
126
  // "piece": "N",
80
- // "to": "d4"
127
+ // "to": "f3",
81
128
  // },
82
129
  // {
130
+ // "capture": true,
131
+ // "from": "c",
83
132
  // "piece": "P",
84
- // "to": "e5"
85
- // }
86
- // ],
87
- // [
88
- // {
89
- // "piece": "N",
90
- // "to": "b5"
133
+ // "to": "d4",
91
134
  // },
92
- // {
93
- // "piece": "P",
94
- // "to": "d5"
95
- // }
96
135
  // ],
136
+ // ...
97
137
  // [
138
+ // 6,
98
139
  // {
140
+ // "capture": true,
99
141
  // "from": "c",
100
142
  // "piece": "P",
101
- // "to": "d5"
143
+ // "to": "d5",
102
144
  // },
103
145
  // {
104
146
  // "piece": "B",
105
- // "to": "c5"
106
- // }
147
+ // "to": "c5",
148
+ // },
107
149
  // ],
108
150
  // [
151
+ // 7,
109
152
  // {
110
153
  // "from": "5",
111
154
  // "piece": "N",
112
- // "to": "c3"
155
+ // "to": "c3",
113
156
  // },
114
157
  // {
115
158
  // "castling": true,
116
159
  // "piece": "K",
117
- // "to": "c8"
118
- // }
119
- // ],
120
- // [
121
- // {
122
- // "piece": "P",
123
- // "to": "e3"
160
+ // "to": "g8",
124
161
  // },
125
- // {
126
- // "piece": "P",
127
- // "to": "e4"
128
- // }
129
- // ],
130
- // [
131
- // {
132
- // "piece": "P",
133
- // "to": "h3"
134
- // },
135
- // {
136
- // "piece": "R",
137
- // "to": "e8"
138
- // }
139
- // ],
140
- // [
141
- // {
142
- // "piece": "P",
143
- // "to": "g4"
144
- // },
145
- // {
146
- // "piece": "R",
147
- // "to": "e5"
148
- // }
149
- // ],
150
- // [
151
- // {
152
- // "piece": "B",
153
- // "to": "c4"
154
- // },
155
- // {
156
- // "from": "b",
157
- // "piece": "N",
158
- // "to": "d7"
159
- // }
160
- // ],
161
- // [
162
- // {
163
- // "piece": "Q",
164
- // "to": "b3"
165
- // },
166
- // {
167
- // "piece": "N",
168
- // "to": "e8"
169
- // }
170
162
  // ],
163
+ // ...
171
164
  // [
165
+ // 21,
172
166
  // {
167
+ // "capture": true,
173
168
  // "piece": "N",
174
- // "to": "d2"
169
+ // "to": "e4",
175
170
  // },
176
171
  // {
177
- // "piece": "N",
178
- // "to": "d6"
179
- // }
180
- // ],
181
- // [
182
- // {
183
172
  // "piece": "B",
184
- // "to": "e2"
185
- // },
186
- // {
187
- // "piece": "Q",
188
- // "to": "h4"
189
- // }
190
- // ],
191
- // [
192
- // {
193
- // "piece": "N",
194
- // "to": "c4"
173
+ // "to": "b7",
195
174
  // },
196
- // {
197
- // "piece": "N",
198
- // "to": "c4"
199
- // }
200
175
  // ],
201
176
  // [
177
+ // 22,
202
178
  // {
179
+ // "capture": true,
203
180
  // "piece": "Q",
204
- // "to": "c4"
205
- // },
206
- // {
207
- // "piece": "P",
208
- // "to": "b5"
209
- // }
210
- // ],
211
- // [
212
- // {
213
- // "piece": "Q",
214
- // "to": "b5"
215
- // },
216
- // {
217
- // "piece": "R",
218
- // "to": "b8"
219
- // }
220
- // ],
221
- // [
222
- // {
223
- // "piece": "Q",
224
- // "to": "a4"
225
- // },
226
- // {
227
- // "piece": "N",
228
- // "to": "f6"
229
- // }
230
- // ],
231
- // [
232
- // {
233
- // "piece": "Q",
234
- // "to": "c6"
235
- // },
236
- // {
237
- // "piece": "N",
238
- // "to": "d7"
239
- // }
240
- // ],
241
- // [
242
- // {
243
- // "piece": "P",
244
- // "to": "d6"
245
- // },
246
- // {
247
- // "piece": "R",
248
- // "to": "e6"
249
- // }
250
- // ],
251
- // [
252
- // {
253
- // "piece": "N",
254
- // "to": "e4"
181
+ // "to": "d7",
255
182
  // },
256
183
  // {
184
+ // "capture": true,
257
185
  // "piece": "B",
258
- // "to": "b7"
259
- // }
260
- // ],
261
- // [
262
- // {
263
- // "piece": "Q",
264
- // "to": "d7"
186
+ // "to": "e4",
265
187
  // },
266
- // {
267
- // "piece": "B",
268
- // "to": "e4"
269
- // }
270
188
  // ],
271
189
  // [
190
+ // 23,
272
191
  // {
273
192
  // "piece": "R",
274
- // "to": "h2"
193
+ // "to": "h2",
275
194
  // },
276
195
  // {
196
+ // "capture": true,
277
197
  // "piece": "B",
278
- // "to": "d6"
279
- // }
280
- // ],
281
- // [
282
- // {
283
- // "piece": "B",
284
- // "to": "c4"
198
+ // "to": "d6",
285
199
  // },
286
- // {
287
- // "piece": "R",
288
- // "to": "d8"
289
- // }
290
200
  // ],
201
+ // ...
291
202
  // [
203
+ // 29,
292
204
  // {
205
+ // "capture": true,
206
+ // "check": true,
293
207
  // "piece": "Q",
294
- // "to": "a7"
208
+ // "to": "e6",
295
209
  // },
296
210
  // {
297
- // "piece": "B",
298
- // "to": "h2"
299
- // }
300
- // ],
301
- // [
302
- // {
303
- // "piece": "B",
304
- // "to": "e6"
211
+ // "piece": "K",
212
+ // "to": "h8",
305
213
  // },
306
- // {
307
- // "from": "f",
308
- // "piece": "P",
309
- // "to": "e6"
310
- // }
311
214
  // ],
312
215
  // [
216
+ // 30,
313
217
  // {
314
218
  // "piece": "Q",
315
- // "to": "a6"
219
+ // "to": "e7",
316
220
  // },
317
221
  // {
318
222
  // "piece": "B",
319
- // "to": "f3"
320
- // }
321
- // ],
322
- // [
323
- // {
324
- // "piece": "B",
325
- // "to": "d2"
326
- // },
327
- // {
328
- // "piece": "Q",
329
- // "to": "h3"
330
- // }
331
- // ],
332
- // [
333
- // {
334
- // "annotations": [
335
- // "check"
336
- // ],
337
- // "piece": "Q",
338
- // "to": "e6"
223
+ // "to": "c7",
339
224
  // },
340
- // {
341
- // "piece": "K",
342
- // "to": "h8"
343
- // }
344
225
  // ],
345
- // [
346
- // {
347
- // "piece": "Q",
348
- // "to": "e7"
349
- // },
350
- // {
351
- // "piece": "B",
352
- // "to": "c7"
353
- // }
354
- // ]
355
226
  // ],
356
- // "result": 0
357
- // }
358
- // ]
227
+ // "result": 0,
228
+ // },
229
+ // ];
359
230
  ```
231
+
232
+ ## Warning
233
+
234
+ **PGN** does not guarantee PGN games are valid. It does only parse the content.
235
+ As part of the **ECHECS** project, it is responsability of **@echecs/game** to
236
+ verify the validity of the game.
package/package.json CHANGED
@@ -42,5 +42,6 @@
42
42
  "test:coverage": "npm run test -- --coverage",
43
43
  "test:watch": "npm run test -- --watch"
44
44
  },
45
- "version": "2.1.1"
45
+ "types": "dist/index.d.ts",
46
+ "version": "2.1.2"
46
47
  }