A SGF text parser written in Typescript
SGF is the standard format for go (igo, weiqi, baduk) game records, and is also used for several other games. SGF is a text-only format (not a binary format). It contains game trees, with all their nodes and properties, and nothing more. Thus the file format reflects the regular internal structure of a tree of property lists. There are no exceptions; if a game needs to store some information on file with the document, a (game-specific) property must be defined for that purpose.
npm install ts-sgf-parser
import { Sgfparser } from 'ts-sgf-parser'
const SgfParser = require('ts-sgf-parser').SgfParser
const parser = new SgfParser(String.raw`(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd];B[ad];W[bd])(;B[hh];W[hg]))`)
parser.moveNode().moveNode().currentNode;
// {
// "move": {
// "player": "W",
// "coords": "bb"
// },
// "properties": []
// }
parser.backNode(2).currentSequence
// {id: 1
// nodes: [{ move: undefined, properties: […]},
// { move: {…
// }, properties: []
// }, { move: {…
// }, properties: []
// }],
//
// subSequences: [
// { id: 2, nodes: […
// ], subSequences: [], …
// },
// { id: 3, nodes: […
// ], subSequences: [], …
// }
// ]
// }
parser.getMainLine()
parser.variationsFromCurrentNode()
parser.chooseVariationIndex(2).moveNode(6).currentNode
parser.backToClosestMain()
- Typescript
- Jest
- Rollup
- Support for setup properties and list of points values in Properties (AB, AW properties)
- Improve navegability
- Try TypeDoc