{"id":28197985,"url":"https://github.com/alpacamax/pgn-handler","last_synced_at":"2026-04-16T00:31:38.082Z","repository":{"id":57322703,"uuid":"418032658","full_name":"AlpacaMax/PGN-Handler","owner":"AlpacaMax","description":"A PGN file parser built for a PGN viewer","archived":false,"fork":false,"pushed_at":"2021-12-27T02:45:48.000Z","size":162,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T01:50:22.705Z","etag":null,"topics":["chess","javascript","npm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlpacaMax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-17T05:42:46.000Z","updated_at":"2024-06-20T10:33:30.000Z","dependencies_parsed_at":"2022-09-10T18:21:05.797Z","dependency_job_id":null,"html_url":"https://github.com/AlpacaMax/PGN-Handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlpacaMax/PGN-Handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlpacaMax%2FPGN-Handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlpacaMax%2FPGN-Handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlpacaMax%2FPGN-Handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlpacaMax%2FPGN-Handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlpacaMax","download_url":"https://codeload.github.com/AlpacaMax/PGN-Handler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlpacaMax%2FPGN-Handler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267116481,"owners_count":24038624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chess","javascript","npm"],"created_at":"2025-05-16T17:17:17.511Z","updated_at":"2025-10-30T08:02:28.437Z","avatar_url":"https://github.com/AlpacaMax.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PGN-Handler\n`PGN-Handler` is a package containing a collection of functions for handling `PGN` files, aka **P**ortable **G**ame **N**otaion, including a parser, modification functions, and validation function.\n\n# Development Progress\nThis project is still under development. Currently it only has a parser, a validation function, and some modifier functions for the parsed result, the last two types of functions are essentially wrapper functions for chess.js.\n\n# API\n## parseRaw(filename)\n`parseRaw(filename)` takes a PGN filename and parse the file. It returns the raw output from the parser.\n\n``` js\n\u003e console.log(JSON.stringify(parseRaw('test_pgns/test_legal_moves.pgn'), null, 2));\n{\n  \"header\": {\n    \"event\": \"F/S Return Match\",\n    \"site\": \"Belgrade, Serbia JUG\",\n    \"date\": {\n      \"year\": \"1992\",\n      \"month\": \"11\",\n      \"day\": \"04\"\n    },\n    \"round\": null,\n    \"white\": \"Fischer, Robert J.\",\n    \"black\": \"Spassky, Boris V.\",\n    \"result\": \"Draw\"\n  },\n  \"moves\": [\n    {\n      \"move\": 1,\n      \"white\": {\n        \"type\": 1,\n        \"piece\": \"P\",\n        \"from\": {\n          \"file\": null,\n          \"rank\": null\n        },\n        \"to\": {\n          \"file\": \"e\",\n          \"rank\": \"4\"\n        },\n        \"suffixParsed\": null,\n        \"san\": \"e4\"\n      },\n      \"black\": {\n        \"type\": 1,\n        \"piece\": \"P\",\n        \"from\": {\n          \"file\": null,\n          \"rank\": null\n        },\n        \"to\": {\n          \"file\": \"e\",\n          \"rank\": \"5\"\n        },\n        \"suffixParsed\": null,\n        \"san\": \"e5\",\n        \"rav\": [\n          {\n            \"move\": 1,\n            \"white\": null,\n            \"black\": {\n              \"type\": 1,\n              \"piece\": \"P\",\n              \"from\": {\n                \"file\": null,\n                \"rank\": null\n              },\n              \"to\": {\n                \"file\": \"c\",\n                \"rank\": \"4\"\n              },\n              \"suffixParsed\": null,\n              \"san\": \"c4\"\n            }\n          }\n        ]\n      }\n    },\n    {\n      \"move\": 2,\n      \"white\": {\n        \"type\": 1,\n        \"piece\": \"N\",\n        \"from\": {\n          \"file\": null,\n          \"rank\": null\n        },\n        \"to\": {\n          \"file\": \"f\",\n          \"rank\": \"3\"\n        },\n        \"suffixParsed\": null,\n        \"san\": \"Nf3\"\n      },\n      \"black\": null\n    }\n  ]\n}\n```\n*This PGN file is in this repo*\n\n## parse(filename)\n`parse(filename)` is a wrapper function of `parseRaw(filename)`. In addition to what `parseRaw(filename)` can do, `parse(filename)`:\n- Labels if the current move is legal or not. If it's not then the following moves will not get labeled\n- Fills in the starting position of each move(fills in `from`)\n- Add current FEN after each move\n- Judge the result of game and correct the result in header if necessary\n\n``` js\n\u003e console.log(JSON.stringify(parse('test_pgns/test_legal_moves.pgn'), null, 2));\n{\n  \"header\": {\n    \"event\": \"F/S Return Match\",\n    \"site\": \"Belgrade, Serbia JUG\",\n    \"date\": {\n      \"year\": \"1992\",\n      \"month\": \"11\",\n      \"day\": \"04\"\n    },\n    \"round\": null,\n    \"white\": \"Fischer, Robert J.\",\n    \"black\": \"Spassky, Boris V.\",\n    \"result\": \"Draw\"\n  },\n  \"moves\": [\n    {\n      \"move\": 1,\n      \"white\": {\n        \"type\": 1,\n        \"piece\": \"P\",\n        \"from\": {\n          \"file\": null,\n          \"rank\": null\n        },\n        \"to\": {\n          \"file\": \"e\",\n          \"rank\": \"4\"\n        },\n        \"suffixParsed\": null,\n        \"san\": \"e4\",\n        \"legalMove\": true,\n        \"fen\": \"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1\"\n      },\n      \"black\": {\n        \"type\": 1,\n        \"piece\": \"P\",\n        \"from\": {\n          \"file\": null,\n          \"rank\": null\n        },\n        \"to\": {\n          \"file\": \"e\",\n          \"rank\": \"5\"\n        },\n        \"suffixParsed\": null,\n        \"san\": \"e5\",\n        \"rav\": [\n          {\n            \"move\": 1,\n            \"white\": null,\n            \"black\": {\n              \"type\": 1,\n              \"piece\": \"P\",\n              \"from\": {\n                \"file\": null,\n                \"rank\": null\n              },\n              \"to\": {\n                \"file\": \"c\",\n                \"rank\": \"4\"\n              },\n              \"suffixParsed\": null,\n              \"san\": \"c4\",\n              \"legalMove\": false\n            }\n          }\n        ],\n        \"legalMove\": true,\n        \"fen\": \"rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2\"\n      }\n    },\n    {\n      \"move\": 2,\n      \"white\": {\n        \"type\": 1,\n        \"piece\": \"N\",\n        \"from\": {\n          \"file\": null,\n          \"rank\": null\n        },\n        \"to\": {\n          \"file\": \"f\",\n          \"rank\": \"3\"\n        },\n        \"suffixParsed\": null,\n        \"san\": \"Nf3\",\n        \"legalMove\": true,\n        \"fen\": \"rnbqkbnr/pppp1ppp/8/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2\"\n      },\n      \"black\": null\n    }\n  ],\n  \"resultOnBoard\": \"Unfinished\"\n}\n```\n\n# Contributing\nPlease run `npx eslint changed_file.js` before commiting\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpacamax%2Fpgn-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falpacamax%2Fpgn-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpacamax%2Fpgn-handler/lists"}