Skip to content

Commit 27f6576

Browse files
authored
Merge pull request #13 from jwyce/fix-load-pgn-bug
fix: load pgn bug
2 parents 4e9e89f + 771f68b commit 27f6576

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.changeset/silent-beers-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gungi.js': patch
3+
---
4+
5+
load pgn was not filtering out empty moves when parsing pgn

src/gungi/pgn.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ export function encodePGN(history: Move[], opts?: PGNOptions) {
6060

6161
export function parsePGN(pgn: string, opts?: Pick<PGNOptions, 'newline'>) {
6262
const newline = opts?.newline ?? '\n';
63-
const moves = pgn.split(newline).flatMap((line) => {
64-
return line.replace(/\d+\.+/g, '').split(' ');
65-
});
63+
const moves = pgn
64+
.split(newline)
65+
.flatMap((line) => {
66+
return line.replace(/\d+\.+/g, '').split(' ');
67+
})
68+
.filter((move) => move !== '');
6669

6770
return moves;
6871
}

0 commit comments

Comments
 (0)