chess-moments 0.15.0 → 0.15.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.
@@ -35,6 +35,13 @@ const momentsToPgn = (moments) => {
35
35
  if (!moment.move) {
36
36
  // If this is a variation marker (depth > 1) and not the initial position
37
37
  if (depth > 1 && i > 0) {
38
+ // First, close any deeper variations if we're going to a shallower depth
39
+ while (currentDepth > depth) {
40
+ variationStack.pop();
41
+ pgn += ')';
42
+ currentDepth--;
43
+ }
44
+
38
45
  // Check if we need to start a new variation at the same depth
39
46
  if (depth === currentDepth) {
40
47
  // Close current variation and start a new one at the same level
@@ -1,18 +1,10 @@
1
- const makeMoments = require('./make-moments');
1
+ const flat = require('./flat');
2
2
 
3
3
  const mainline = (sloppyPgn) => {
4
- const moments = makeMoments(sloppyPgn);
5
-
6
- let index = 0;
7
- for (const lines of moments) {
8
- for (const moment of lines) {
9
- moment.index = index;
10
- index++;
11
- }
12
- }
4
+ const flatMoments = flat(sloppyPgn);
13
5
 
14
6
  // Only return the mainline moments
15
- const mainlineMoments = moments.filter((move) => {
7
+ const mainlineMoments = flatMoments.filter((move) => {
16
8
  return move.depth === 1 && (move.move || move.index === 0);
17
9
  });
18
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "PGN parser that transforms PGN files into chess \"moments\"",
5
5
  "main": "index.js",
6
6
  "files": [