pgn-manager 2.2.0 → 2.2.1

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.
@@ -0,0 +1,5 @@
1
+ import type { ParsedPGN, Move } from "pgn-parser";
2
+ /**
3
+ * Regenerates a PGN string from a ParsedPGN object
4
+ */
5
+ export declare function regeneratePGN(parsedPGN: ParsedPGN, moveColor: Map<Move, "w" | "b">): string;
package/dist/utils.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.regeneratePGN = regeneratePGN;
4
+ /**
5
+ * Regenerates a PGN string from a ParsedPGN object
6
+ */
7
+ function regeneratePGN(parsedPGN, moveColor) {
8
+ const lines = [];
9
+ // Add comments above header
10
+ if (parsedPGN.comments_above_header) {
11
+ parsedPGN.comments_above_header.forEach((comment) => {
12
+ lines.push(`{${comment.text}}`);
13
+ });
14
+ lines.push("");
15
+ }
16
+ // Add headers
17
+ if (parsedPGN.headers) {
18
+ parsedPGN.headers.forEach((header) => {
19
+ lines.push(`[${header.name} "${header.value}"]`);
20
+ });
21
+ lines.push("");
22
+ }
23
+ // Add comments between headers and moves
24
+ if (parsedPGN.comments) {
25
+ parsedPGN.comments.forEach((comment) => {
26
+ lines.push(`{${comment.text}}`);
27
+ });
28
+ lines.push("");
29
+ }
30
+ // Add moves
31
+ const movesText = formatMoves(parsedPGN.moves, moveColor);
32
+ if (movesText) {
33
+ lines.push(movesText);
34
+ }
35
+ // Add result
36
+ lines.push(parsedPGN.result);
37
+ return lines.join("\n");
38
+ }
39
+ /**
40
+ * Formats moves array into PGN move notation
41
+ */
42
+ function formatMoves(moves, moveColor) {
43
+ const parts = [];
44
+ moves.forEach((move) => {
45
+ // Add move number for white moves
46
+ if (move.move_number !== undefined) {
47
+ parts.push(`${move.move_number}.`);
48
+ if (moveColor.get(move) === "b") {
49
+ parts[parts.length - 1] += "..";
50
+ }
51
+ }
52
+ // Add the move
53
+ parts.push(move.move);
54
+ // Add comments after the move
55
+ move.comments.forEach((comment) => {
56
+ parts.push(`{${comment}}`);
57
+ });
58
+ // Add variations (RAVs)
59
+ if (move.ravs) {
60
+ move.ravs.forEach((rav) => {
61
+ const ravMoves = formatMoves(rav.moves, moveColor);
62
+ const ravResult = rav.result ? ` ${rav.result}` : "";
63
+ parts.push(`(${ravMoves}${ravResult})`);
64
+ });
65
+ }
66
+ });
67
+ return parts.join(" ");
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgn-manager",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Libraray built on top of chess.js and pgn-parser to load and process PGN files in typescript.",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -41,8 +41,6 @@
41
41
  "typescript": "^5.8.3"
42
42
  },
43
43
  "files": [
44
- "dist/index.js",
45
- "dist/index.d.ts",
46
- "dist/lib"
44
+ "dist/**"
47
45
  ]
48
46
  }