0.1.0 • Published 7 years ago

slf-parser v0.1.0

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

slf-parser

A Node library for parsing Go diagrams in Sensei's Library Format.

Example

import { toBoard } from "slf-parser";

const diagram =
`$$ A joseki variation
 $$  ------------------
 $$ | . . . . . . . . .
 $$ | . . . . . . . . .
 $$ | . . 7 3 X d . . .
 $$ | . . O 1 O 6 . . .
 $$ | . . 4 2 5 c . . .
 $$ | . . 8 X a . . . .
 $$ | . . . b . . . . .
 $$ | . . . . . . . . .
 $$ | . . . . . . . . .`;

const board = toBoard(diagram);

console.log(board.title);       // "A joseki variation"
console.log(board.cells[2][2]); // { type: "black", label: "7" }
console.log(board.axis.x);      // { labels: "ABCDEFGHJ", position: "north" }
console.log(board.axis.y);      // { labels: [19, 18, 17, 16, 15, 14, 13, 12, 11], position:  "west" }
console.log(board.borders);     // { north: true, east: false, south: false, west: true }

API

toBoard(slfString: string): Board

Parses a diagram in Sensei's Library Format, returning a Board object.

import {toBoard} from "./slf-parser";
const board = toBoard("..."); // => Board object

Board object

PropertyDescription
titleThe title of the board. Undefined if not applicable.
cells[row][col]A 2D array of cells on the board's grid, starting on the north east corner.
cells[][].typeThe type of cell: "black" for a black stone, "white" for a white stone, "intersection" for an intersection with no stone, "star" for a star point/hoshi with no stone, or "empty" for an intersection with no grid.
cells[][].labelA 1 character string label drawn on the cell. Undefined if not applicable. Cells can't have both a label and a mark.
cells[][].linkThe URL that the cell links to. Undefined if not applicable.
cells[][].markThe shape to draw on the cell: "circle", "cross", "square", or "triangle". Undefined if not applicable. Cells can't have both a label and a mark.
lines[i]An array of lines on the board's grid. Undefined if there are no lines.
lines[].typeEither "line" or "arrow". If "arrow", the line ends in an arrow head shape.
lines[].start.rowThe line's starting row.
lines[].start.colThe line's starting column.
lines[].end.rowThe line's ending row.
lines[].end.colThe line's ending column.
bordersAn object specifying which edges have borders.
borders.northWhether the north edge has a border.
borders.eastWhether the east edge has a border.
borders.southWhether the south edge has a border.
borders.westWhether the west edge has a border.
axesAn object describing the axes/coordinate labels. Undefined if the axes are hidden.
axes.x.labelsLabels for the x-axis, starting from the west. Each character in the string is a label.
axes.x.positionWhere to show the x-axis: either "north" or "south".
axes.y.labelsAn array of labels for the y-axis, starting from the north. Each element is a number.
axes.y.positionWhere to show the y-axis: either "east" or "west".