uci-parser-ts

uci-parser-ts

npm npm bundle size Codecov

A UCI parser written in TypeScript.

install

npm

npm i uci-parser-ts

yarn

yarn add uci-parser-ts

pnpm

pnpm i uci-parser-ts

cdn

examples

stockfish.ts

import { spawn } from "child_process";
import { createInterface } from "readline";
import { tryParseOne, UciOkCommand } from "uci-parser-ts";

/**
* Spawns a Stockfish process and initializes the UCI mode.
*/
async function main() {
const { stdin, stdout } = spawn("stockfish");
const lines = createInterface({ input: stdout });

stdin.write("uci");
stdin.end();

for await (const line of lines) {
const command = tryParseOne(line);
if (!command) {
continue;
}

if (command instanceof UciOkCommand) {
break;
}
}
}

void main();

cdn.html

<html>
<body>
<script src="https://unpkg.com/uci-parser-ts@latest/umd/uci-parser-ts.production.js"></script>
<script>
alert(JSON.stringify(uci.parseOne("bestmove e2e4")));
</script>
</body>
</html>

Generated using TypeDoc