This commit is contained in:
Maciej Caderek
2022-03-13 05:42:26 +01:00
parent bf32e4ae4b
commit a4d7f9711a

View File

@@ -24,6 +24,14 @@ const cleanPGN = (pgn: string) => {
game.load_pgn(pgn); game.load_pgn(pgn);
game.delete_comments(); game.delete_comments();
if (!game.header().Result) {
const result = (pgn.trim().match(/(1-0)|(0-1)|(1\/2-1\/2)$/) || [])[0];
if (result) {
game.header("Result", result);
}
}
const headerEntries = Object.entries(game.header()); const headerEntries = Object.entries(game.header());
const [_, moves] = const [_, moves] =
@@ -37,11 +45,7 @@ const cleanPGN = (pgn: string) => {
.sort() .sort()
.join("\n"); .join("\n");
console.log(header); return [header, moves].join("\n\n");
const cleanedPGN = [header, moves].join("\n\n");
console.log(cleanedPGN);
return cleanedPGN;
}; };
const compressPGN = (pgn: string) => { const compressPGN = (pgn: string) => {