pgnify
Version:
A lightning fast [PGN](https://en.wikipedia.org/wiki/Portable_Game_Notation) parser.
98 lines (91 loc) • 2.51 kB
text/typescript
declare const GameResults: {
readonly NONE: "*";
readonly DRAW: "1/2-1/2";
readonly WHITE_WIN: "1-0";
readonly BLACK_WIN: "0-1";
};
interface PieceMove {
type: "piece-move";
pieceInitial: string;
srcX?: number;
srcY?: number;
destX: number;
destY: number;
}
interface PawnMove {
type: "pawn-move";
srcX: number;
destX: number;
destY: number;
promotionInitial?: string;
}
interface CastlingMove {
type: "castling";
isQueenSide: boolean;
}
interface UnknownMove {
type: "unknown";
notation: string;
}
type Move = PieceMove | PawnMove | CastlingMove | UnknownMove;
interface BaseHeaders {
White: string;
Black: string;
Site: string;
Event: string;
/** Should be in the format `YYYY.MM.DD`. */
Date: string;
Result: GameResult;
EventDate: string;
Round: string;
TimeControl: string;
FEN: string;
ECO: string;
Opening: string;
Variation: string;
PlyCount: string;
SetUp: string;
Termination: string;
WhiteElo: string;
BlackElo: string;
BlackTitle: string;
WhiteTitle: string;
}
type PGNHeaders = Partial<BaseHeaders> & {
[key: string]: string;
};
type GameResult = typeof GameResults[keyof typeof GameResults];
type Variation = MoveNode[];
interface MoveNode {
move: Move;
moveNumber: number;
isWhiteMove: boolean;
NAG?: string;
commentBefore?: string;
commentAfter?: string;
variations?: Variation[];
}
type types_public_GameResult = GameResult;
type types_public_Move = Move;
type types_public_MoveNode = MoveNode;
type types_public_PGNHeaders = PGNHeaders;
type types_public_Variation = Variation;
declare namespace types_public {
export type { types_public_GameResult as GameResult, types_public_Move as Move, types_public_MoveNode as MoveNode, types_public_PGNHeaders as PGNHeaders, types_public_Variation as Variation };
}
declare function parseHeaders(pgn: string): {
headers: PGNHeaders;
moveString: string;
};
declare function stringifyHeaders(headers: PGNHeaders): string;
declare function parse(pgn: string): {
headers: PGNHeaders;
mainLine: Variation;
result: GameResult;
};
declare function parseMoveString(moveString: string): {
mainLine: Variation;
result: GameResult | null;
};
declare function splitPGNs(input: string): Generator<string, void, unknown>;
export { GameResults, types_public as PGNify, parse, parseHeaders, parseMoveString, splitPGNs, stringifyHeaders };