@echecs/pgn 3.6.2 → 3.8.0

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.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,46 @@ and this project adheres to
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [3.8.0] - 2026-03-15
12
+
13
+ ### Added
14
+
15
+ - `onWarning` now fires for move number mismatches (e.g. `5. e4` appearing as
16
+ the first move). Previously emitted unconditionally to `console.warn`; now
17
+ routed through `onWarning` when provided. `console.warn` is no longer called
18
+ for move number mismatches — if you relied on it, add an `onWarning` callback.
19
+ - `onWarning` fires when the `[Result "..."]` tag value does not match the game
20
+ termination marker at the end of the movetext (e.g. `[Result "1/2-1/2"]` with
21
+ a `1-0` termination marker).
22
+ - `onWarning` fires for duplicate tag names (same tag appearing more than once
23
+ in the tag pair section). The `line` and `column` fields point to the opening
24
+ `[` of the duplicate — exact source position, not a nominal placeholder.
25
+
26
+ ### Changed
27
+
28
+ - Move number mismatch no longer emits to `console.warn` when `onWarning` is not
29
+ provided. It is now silently ignored, consistent with how missing STR tag
30
+ warnings are handled.
31
+
32
+ ## [3.7.0] - 2026-03-15
33
+
34
+ ### Added
35
+
36
+ - `onWarning` option for `parse()` and `stream()`: fires once per missing STR
37
+ tag. Emitted in alphabetical key order: `Black`, `Date`, `Event`, `Result`,
38
+ `Round`, `Site`, `White`.
39
+ - `ParseWarning` is now an exported type with the same shape as `ParseError`.
40
+
41
+ ### Fixed
42
+
43
+ - `parse()` and `stream()` now strip a UTF-8 BOM (`\uFEFF`) at the start of
44
+ input. Chessbase and Windows editors commonly produce BOM-prefixed PGN files
45
+ that previously failed silently.
46
+ - Tag values containing escaped quotes (`\"`) or escaped backslashes (`\\`) now
47
+ parse correctly per PGN spec section 7.
48
+ - Games with no tag pairs (bare move list + result) now parse correctly per PGN
49
+ spec section 8.1 ("zero or more tag pairs"). These games return `meta: {}`.
50
+
11
51
  ## [3.6.2] - 2026-03-15
12
52
 
13
53
  ### Performance
package/README.md CHANGED
@@ -135,6 +135,37 @@ for await (const game of stream(chunks, { onError: console.error })) {
135
135
  > (truncated input). Incomplete input at end-of-stream is treated as expected
136
136
  > behaviour, not a parse error.
137
137
 
138
+ ### Warnings
139
+
140
+ Pass `onWarning` to observe spec-compliance issues that do not prevent parsing:
141
+
142
+ ```typescript
143
+ import parse, { type ParseWarning } from '@echecs/pgn';
144
+
145
+ const games = parse(input, {
146
+ onWarning(warn: ParseWarning) {
147
+ console.warn(warn.message);
148
+ },
149
+ });
150
+ ```
151
+
152
+ `onWarning` receives a `ParseWarning` with the same fields as `ParseError`:
153
+ `message`, `offset`, `line`, `column`.
154
+
155
+ Currently fires for:
156
+
157
+ - Missing STR tags (`Black`, `Date`, `Event`, `Result`, `Round`, `Site`,
158
+ `White`) — emitted in alphabetical key order; position fields are nominal
159
+ placeholders
160
+ - Move number mismatch (declared move number in the PGN text doesn't match the
161
+ move's actual position) — position fields are nominal placeholders
162
+ - Result tag mismatch (`[Result "..."]` tag value differs from the game
163
+ termination marker) — position fields are nominal placeholders
164
+ - Duplicate tag names — `line` and `column` point to the opening `[` of the
165
+ duplicate tag
166
+
167
+ The same option is accepted by `stream()`.
168
+
138
169
  ### PGN object
139
170
 
140
171
  ```typescript