Skip to content

Commit c2e888a

Browse files
committed
docs: document stringify() in README
1 parent 5ec61bc commit c2e888a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ for await (const game of stream(text)) {
112112
}
113113
```
114114

115+
### `stringify()`
116+
117+
Converts one or more parsed `PGN` objects back into a valid PGN string,
118+
providing semantic round-trip fidelity.
119+
120+
```typescript
121+
stringify(input: PGN | PGN[], options?: ParseOptions): string
122+
```
123+
124+
Reconstructs SAN from `Move` fields, re-serializes annotation commands
125+
(`[%cal]`, `[%csl]`, `[%clk]`, `[%eval]`) back into comment blocks, and
126+
preserves RAVs and NAGs. Pass `onWarning` to observe recoverable issues (e.g.
127+
invalid castling destination, negative clock).
128+
129+
```typescript
130+
import parse, { stringify } from '@echecs/pgn';
131+
132+
const games = parse(pgnString);
133+
const output = stringify(games); // valid PGN string
134+
```
135+
115136
### Error handling
116137

117138
By default, `parse()` and `stream()` silently return `[]` / skip games on parse

0 commit comments

Comments
 (0)