pgn-manager 2.3.0 → 2.3.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.
- package/LICENSE +21 -21
- package/README.md +100 -100
- package/package.json +45 -45
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Harsh Kumar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Harsh Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
# PGN Manager 📦♟️
|
|
2
|
-
|
|
3
|
-
A powerful TypeScript/JavaScript library for managing chess PGN (Portable Game Notation) files with support for variations and game traversal.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/pgn-manager)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://www.typescriptlang.org/)
|
|
8
|
-
[](https://www.npmjs.com/package/pgn-manager)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Features ✨
|
|
12
|
-
- Parse PGN strings into manageable objects
|
|
13
|
-
- Navigate through main lines and variations
|
|
14
|
-
- Access FEN positions for any move
|
|
15
|
-
- Handle game headers
|
|
16
|
-
- Traverse moves forward and backward
|
|
17
|
-
- Full TypeScript support
|
|
18
|
-
|
|
19
|
-
## Installation 🚀
|
|
20
|
-
|
|
21
|
-
```console
|
|
22
|
-
npm install pgn-manager
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Usage 💻
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import PGNManager from 'pgn-manager';
|
|
29
|
-
|
|
30
|
-
// Initialize with a PGN string
|
|
31
|
-
const pgn = `1. e4 e5 2. Nf3 Nc6 (2... d6 3. d4) 3. Bb5 *`;
|
|
32
|
-
const manager = new PGNManager(pgn);
|
|
33
|
-
|
|
34
|
-
// Get the first move
|
|
35
|
-
const firstMove = manager.getFirstMove();
|
|
36
|
-
|
|
37
|
-
// Navigate through moves
|
|
38
|
-
const nextMove = manager.nextMove(firstMove);
|
|
39
|
-
const prevMove = manager.previousMove(nextMove);
|
|
40
|
-
|
|
41
|
-
// Get FEN position for a move
|
|
42
|
-
const fen = manager.getMoveFen(firstMove);
|
|
43
|
-
|
|
44
|
-
// Access game headers
|
|
45
|
-
const headers = manager.headers;
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## API Reference 📚
|
|
49
|
-
|
|
50
|
-
### Constructor
|
|
51
|
-
- `new PGNManager(pgn: string)`: Creates a new PGN manager instance
|
|
52
|
-
|
|
53
|
-
### Properties
|
|
54
|
-
- `pgn`: Get the raw PGN string
|
|
55
|
-
- `parsedPGN`: Get the parsed PGN object
|
|
56
|
-
- `headers`: Get game headers array
|
|
57
|
-
|
|
58
|
-
### Methods
|
|
59
|
-
- `getMove(moveNumber: number)`: Get move by number
|
|
60
|
-
- `getMoveNumber(moveOrMoveId: Move | number)`: Get number for a move
|
|
61
|
-
- `nextMove(moveOrMoveId: Move | number)`: Get next move in the sequence
|
|
62
|
-
- `previousMove(moveOrMoveId: Move | number)`: Get previous move
|
|
63
|
-
- `hasNextMove(moveOrMoveId: Move | number)`: Check if move has a next move
|
|
64
|
-
- `getFirstMove()`: Get the first move of the game
|
|
65
|
-
- `getLastMove()`: Get the last move of the game
|
|
66
|
-
- `getMoveFen(moveOrMoveId: Move | number)`: Get FEN position after move
|
|
67
|
-
- `getParentRav(moveOrMoveId: Move | number)`: Get parent variation for move
|
|
68
|
-
- `getMoveColor(moveOrMoveId: Move | number)`: Gets the color of the player who made the move ("w" for white or "b" for black)
|
|
69
|
-
|
|
70
|
-
## Examples 🎯
|
|
71
|
-
|
|
72
|
-
### Traversing Main Line
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
const manager = new PGNManager("1. e4 e5 2. Nf3 Nc6 3. Bb5 *");
|
|
76
|
-
let move = manager.getFirstMove();
|
|
77
|
-
|
|
78
|
-
while (manager.hasNextMove(move)) {
|
|
79
|
-
console.log(move.move);
|
|
80
|
-
move = manager.nextMove(move);
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Working with Variations
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
const manager = new PGNManager("1. e4 e5 2. Nf3 Nc6 (2... d6 3. d4) 3. Bb5 *");
|
|
88
|
-
const move = manager.getMove(2); // Get second move
|
|
89
|
-
const variation = manager.getParentRav(move);
|
|
90
|
-
|
|
91
|
-
if (variation) {
|
|
92
|
-
console.log("Move is part of a variation!");
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Contributing 🤝
|
|
97
|
-
Contributions are welcome! Feel free to submit issues and pull requests.
|
|
98
|
-
|
|
99
|
-
## License 📄
|
|
100
|
-
MIT License - feel free to use this in your projects!
|
|
1
|
+
# PGN Manager 📦♟️
|
|
2
|
+
|
|
3
|
+
A powerful TypeScript/JavaScript library for managing chess PGN (Portable Game Notation) files with support for variations and game traversal.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/pgn-manager)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://www.npmjs.com/package/pgn-manager)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Features ✨
|
|
12
|
+
- Parse PGN strings into manageable objects
|
|
13
|
+
- Navigate through main lines and variations
|
|
14
|
+
- Access FEN positions for any move
|
|
15
|
+
- Handle game headers
|
|
16
|
+
- Traverse moves forward and backward
|
|
17
|
+
- Full TypeScript support
|
|
18
|
+
|
|
19
|
+
## Installation 🚀
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
npm install pgn-manager
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage 💻
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import PGNManager from 'pgn-manager';
|
|
29
|
+
|
|
30
|
+
// Initialize with a PGN string
|
|
31
|
+
const pgn = `1. e4 e5 2. Nf3 Nc6 (2... d6 3. d4) 3. Bb5 *`;
|
|
32
|
+
const manager = new PGNManager(pgn);
|
|
33
|
+
|
|
34
|
+
// Get the first move
|
|
35
|
+
const firstMove = manager.getFirstMove();
|
|
36
|
+
|
|
37
|
+
// Navigate through moves
|
|
38
|
+
const nextMove = manager.nextMove(firstMove);
|
|
39
|
+
const prevMove = manager.previousMove(nextMove);
|
|
40
|
+
|
|
41
|
+
// Get FEN position for a move
|
|
42
|
+
const fen = manager.getMoveFen(firstMove);
|
|
43
|
+
|
|
44
|
+
// Access game headers
|
|
45
|
+
const headers = manager.headers;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API Reference 📚
|
|
49
|
+
|
|
50
|
+
### Constructor
|
|
51
|
+
- `new PGNManager(pgn: string)`: Creates a new PGN manager instance
|
|
52
|
+
|
|
53
|
+
### Properties
|
|
54
|
+
- `pgn`: Get the raw PGN string
|
|
55
|
+
- `parsedPGN`: Get the parsed PGN object
|
|
56
|
+
- `headers`: Get game headers array
|
|
57
|
+
|
|
58
|
+
### Methods
|
|
59
|
+
- `getMove(moveNumber: number)`: Get move by number
|
|
60
|
+
- `getMoveNumber(moveOrMoveId: Move | number)`: Get number for a move
|
|
61
|
+
- `nextMove(moveOrMoveId: Move | number)`: Get next move in the sequence
|
|
62
|
+
- `previousMove(moveOrMoveId: Move | number)`: Get previous move
|
|
63
|
+
- `hasNextMove(moveOrMoveId: Move | number)`: Check if move has a next move
|
|
64
|
+
- `getFirstMove()`: Get the first move of the game
|
|
65
|
+
- `getLastMove()`: Get the last move of the game
|
|
66
|
+
- `getMoveFen(moveOrMoveId: Move | number)`: Get FEN position after move
|
|
67
|
+
- `getParentRav(moveOrMoveId: Move | number)`: Get parent variation for move
|
|
68
|
+
- `getMoveColor(moveOrMoveId: Move | number)`: Gets the color of the player who made the move ("w" for white or "b" for black)
|
|
69
|
+
|
|
70
|
+
## Examples 🎯
|
|
71
|
+
|
|
72
|
+
### Traversing Main Line
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const manager = new PGNManager("1. e4 e5 2. Nf3 Nc6 3. Bb5 *");
|
|
76
|
+
let move = manager.getFirstMove();
|
|
77
|
+
|
|
78
|
+
while (manager.hasNextMove(move)) {
|
|
79
|
+
console.log(move.move);
|
|
80
|
+
move = manager.nextMove(move);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Working with Variations
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const manager = new PGNManager("1. e4 e5 2. Nf3 Nc6 (2... d6 3. d4) 3. Bb5 *");
|
|
88
|
+
const move = manager.getMove(2); // Get second move
|
|
89
|
+
const variation = manager.getParentRav(move);
|
|
90
|
+
|
|
91
|
+
if (variation) {
|
|
92
|
+
console.log("Move is part of a variation!");
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Contributing 🤝
|
|
97
|
+
Contributions are welcome! Feel free to submit issues and pull requests.
|
|
98
|
+
|
|
99
|
+
## License 📄
|
|
100
|
+
MIT License - feel free to use this in your projects!
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pgn-manager",
|
|
3
|
-
"version": "2.3.
|
|
4
|
-
"description": "Libraray built on top of chess.js and pgn-parser to load and process PGN files in typescript.",
|
|
5
|
-
"main": "dist/index",
|
|
6
|
-
"typings": "dist/index",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "jest",
|
|
9
|
-
"test:watch": "jest --watch",
|
|
10
|
-
"test:coverage": "jest --coverage",
|
|
11
|
-
"prepublishOnly": "npm run compile",
|
|
12
|
-
"compile": "npm run clean && tsc -p .",
|
|
13
|
-
"watch": "tsc -w -p .",
|
|
14
|
-
"clean": "rm -rf dist"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/hadron43/pgn-manager.git"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"Chess",
|
|
22
|
-
"PGN",
|
|
23
|
-
"Portal Game Notation"
|
|
24
|
-
],
|
|
25
|
-
"author": "Harsh Kumar <hadron43@yahoo.com>",
|
|
26
|
-
"license": "MIT",
|
|
27
|
-
"bugs": {
|
|
28
|
-
"url": "https://github.com/hadron43/pgn-manager/issues"
|
|
29
|
-
},
|
|
30
|
-
"homepage": "https://github.com/hadron43/pgn-manager#readme",
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"pgn-parser": "2.1.0",
|
|
33
|
-
"void57-chess": "1.0.
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/jest": "^30.0.0",
|
|
37
|
-
"@types/pgn-parser": "^2.1.0",
|
|
38
|
-
"jest": "^30.0.4",
|
|
39
|
-
"ts-jest": "^29.4.0",
|
|
40
|
-
"typescript": "^5.8.3"
|
|
41
|
-
},
|
|
42
|
-
"files": [
|
|
43
|
-
"dist/**"
|
|
44
|
-
]
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "pgn-manager",
|
|
3
|
+
"version": "2.3.2",
|
|
4
|
+
"description": "Libraray built on top of chess.js and pgn-parser to load and process PGN files in typescript.",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"typings": "dist/index",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"test:watch": "jest --watch",
|
|
10
|
+
"test:coverage": "jest --coverage",
|
|
11
|
+
"prepublishOnly": "npm run compile",
|
|
12
|
+
"compile": "npm run clean && tsc -p .",
|
|
13
|
+
"watch": "tsc -w -p .",
|
|
14
|
+
"clean": "rm -rf dist"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/hadron43/pgn-manager.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"Chess",
|
|
22
|
+
"PGN",
|
|
23
|
+
"Portal Game Notation"
|
|
24
|
+
],
|
|
25
|
+
"author": "Harsh Kumar <hadron43@yahoo.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/hadron43/pgn-manager/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/hadron43/pgn-manager#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"pgn-parser": "2.1.0",
|
|
33
|
+
"void57-chess": "^1.0.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/jest": "^30.0.0",
|
|
37
|
+
"@types/pgn-parser": "^2.1.0",
|
|
38
|
+
"jest": "^30.0.4",
|
|
39
|
+
"ts-jest": "^29.4.0",
|
|
40
|
+
"typescript": "^5.8.3"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/**"
|
|
44
|
+
]
|
|
45
|
+
}
|