https://github.com/mcountryman/uci-parser-ts
A UCI parser written in Typescript.
https://github.com/mcountryman/uci-parser-ts
chess nodejs typescript uci
Last synced: 7 months ago
JSON representation
A UCI parser written in Typescript.
- Host: GitHub
- URL: https://github.com/mcountryman/uci-parser-ts
- Owner: mcountryman
- License: mit
- Created: 2022-08-21T02:54:09.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-22T20:40:28.000Z (about 3 years ago)
- Last Synced: 2025-03-15T04:06:54.610Z (7 months ago)
- Topics: chess, nodejs, typescript, uci
- Language: TypeScript
- Homepage: https://mcountryman.github.io/uci-parser-ts
- Size: 532 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# uci-parser-ts
  
A [UCI](https://en.wikipedia.org/wiki/Universal_Chess_Interface) parser written in TypeScript.
## install
npm
```bash
npm i uci-parser-ts
```yarn
```bash
yarn add uci-parser-ts
```pnpm
```bash
pnpm i uci-parser-ts
```cdn
- production: https://unpkg.com/uci-parser-ts@latest/umd/uci-parser-ts.production.js
- development: https://unpkg.com/uci-parser-ts@latest/umd/uci-parser-ts.development.js## examples
> [stockfish.ts](examples/src/stockfish.ts)
```typescript
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](examples/src/cdn.html)
```html
alert(JSON.stringify(uci.parseOne("bestmove e2e4")));
```