chess-moments 1.6.3 → 1.6.4

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.
@@ -155,8 +155,17 @@ const momentsToPgn = (moments) => {
155
155
  }
156
156
  }
157
157
 
158
- // Add move number for white moves or when starting a variation
159
- if (moveWasByWhite || (depth > 1 && pgn.endsWith('('))) {
158
+ // Add move number for white moves, when starting a variation, or for a
159
+ // black move that follows a variation close ')' or a comment '}' — PGN
160
+ // requires the "N..." indicator whenever a black move isn't immediately
161
+ // preceded by its white pair, else the move text is unparseable.
162
+ const prev = pgn.trimEnd();
163
+ const afterBreak = prev.endsWith(')') || prev.endsWith('}');
164
+ if (
165
+ moveWasByWhite ||
166
+ (depth > 1 && pgn.endsWith('(')) ||
167
+ (!moveWasByWhite && afterBreak)
168
+ ) {
160
169
  pgn += `${moveNumber}.`;
161
170
  if (!moveWasByWhite) {
162
171
  pgn += '..';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "PGN parser that transforms PGN files into chess \"moments\"",
5
5
  "main": "index.js",
6
6
  "files": [