An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# uci-parser-ts

![npm](https://img.shields.io/npm/v/uci-parser-ts?style=for-the-badge) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/uci-parser-ts?style=for-the-badge) ![Codecov](https://img.shields.io/codecov/c/github/mcountryman/uci-parser-ts?style=for-the-badge)

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")));

```