{"library":"pgn-parser","title":"PGN Parser","description":"pgn-parser is a JavaScript library designed to parse Portable Game Notation (PGN) chess files into a structured JavaScript object and validate their syntax. The package, currently at version 2.2.1, was last published about a year ago, suggesting it is in maintenance mode rather than active development. It provides a straightforward API to convert PGN strings into a detailed data structure, including game headers, moves, variations, comments, and Numerical Annotation Glyphs (NAGs). This library focuses specifically on PGN parsing and outputting a rich JSON object, differentiating it from full-featured chess engines or game state management libraries. It is built using PEG.js for grammar definition, allowing robust and precise parsing of the PGN specification.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install pgn-parser"],"cli":null},"imports":["const pgnParser = require('pgn-parser');","const { parse } = require('pgn-parser');\n// or\nconst pgnParser = require('pgn-parser');\nconst parse = pgnParser.parse;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const pgnParser = require('pgn-parser');\n\nconst pgnString = `\n[Event \"Rated Blitz game\"]\n[Site \"https://lichess.org/123abcde\"]\n[Date \"2024.04.19\"]\n[White \"ChessMaster\"]\n[Black \"BeginnerBot\"]\n[Result \"1-0\"]\n[WhiteElo \"1800\"]\n[BlackElo \"1200\"]\n[ECO \"C42\"]\n[TimeControl \"300+0\"]\n[UTCDate \"2024.04.19\"]\n[UTCTime \"21:00:00\"]\n[Opening \"Russian Game: Three Knights Attack\"]\n\n1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 (3...a6 {is also common}) 4. O-O Nxe4 5. Re1 Nd6 6. Nxe5 Be7 7. Bxc6 dxc6 8. d4 O-O 9. Nc3 Bf5 10. Bf4 Re8 11. h3 Bg5 12. Bg3 Bh4 13. Qd2 Bxg3 14. fxg3 Nb5 15. Nxb5 cxb5 16. Rf1 Be6 17. b3 c5 18. Rad1 cxd4 19. Qxd4 Qg5 20. Kh2 Rac8 21. c4 bxc4 22. Nxc4 Bxc4 23. bxc4 b6 24. Qd7 Rf8 25. Rd5 Qe3 26. Rff5 h6 27. Rde5 Qc3 28. Re7 a5 29. Rfxf7 Rxf7 30. Rxf7 Kh8 31. Re7 Rg8 32. Qg4 Qf6 33. Rb7 Rd8 34. Rd7 Rf8 35. h4 Kh7 36. Rd5 Qf2 37. a4 Re8 38. Rd7 Qf6 39. Rd5 Rf8 40. Rd7 Qf2 41. Rd5 Rf6 42. Rd7 Rg6 43. Qf3 Qxf3 44. gxf3 Rc6 45. Rd4 h5 46. Rd5 Kh6 47. Kg2 Rg6 48. g4 hxg4 49. fxg4 Rc6 50. Rh5+ Kg6 51. Rg5+ Kh6 52. Rd5 Kg6 53. Rd4 Kh6 54. Kf3 Rf6+ 55. Ke4 Rc6 56. Kd5 Rg6 57. Ke5 Rc6 58. Kd5 Rg6 59. Ke5 Rc6 60. Rd6+ Kh7 61. Rxc6 1-0\n`;\n\ntry {\n  const [gameResult] = pgnParser.parse(pgnString);\n  console.log('Parsed Headers:', gameResult.headers);\n  console.log('First Move:', gameResult.moves[0]);\n  console.log('Last Move:', gameResult.moves[gameResult.moves.length - 1]);\n  console.log('Game Result:', gameResult.result);\n} catch (error) {\n  console.error('Failed to parse PGN:', error.message);\n}","lang":"javascript","description":"This quickstart demonstrates how to parse a PGN string into a JavaScript object, extracting headers, moves, and the game result. It highlights the basic usage of the `pgnParser.parse` function and shows the structure of the returned data, including nested move details and annotations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}