0.3.1 • Published 3 years ago

ts-sgf-parser v0.3.1

Weekly downloads
18
License
MIT
Repository
github
Last release
3 years ago

📖 SGF text parser

A SGF text parser written in Typescript

About SGF specification

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.

Use

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()

An excuse to learn Typescript and testing with Jest

Tools

  • Typescript
  • Jest
  • Rollup

TODO:

  • Support for setup properties and list of points values in Properties (AB, AW properties)
  • Improve navegability
  • Try TypeDoc
0.3.1

3 years ago

0.3.0

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago