Bridge Core
PBN Parser
Parse PBN and DUP files into structured bridge deal data.
Import from @workspace/bridge-core/parsers/pbn.
parsePBNFile
Parses a PBN (Portable Bridge Notation) or DUP file into structured deal data. Handles encoding detection, file size limits, and format preprocessing.
import { parsePBNFile } from '@workspace/bridge-core/parsers/pbn';
const result = await parsePBNFile(file);
if (result.status === 'success') {
const { deals, rawDeals, directives, encoding } = result.data;
// deals: Deal[] — converted to app domain format
// rawDeals: PBNDeal[] — raw parsed PBN data
// directives: string[] — PBN directives (e.g., charset)
// encoding: string — detected file encoding
}
if (result.status === 'error') {
// result.error is MaxFileSizeError | PBNTooManyDealsError | PNBAggregateError
}Result Types
Prop
Type
The function returns a discriminated union:
type ParsePBNFileResult =
| { status: 'success'; data: ParsedPBNFile }
| { status: 'error'; error: PNBAggregateError | MaxFileSizeError | PBNTooManyDealsError };Limits
| Limit | Value |
|---|---|
| Max file size | 10 MB |
| Max deals per file | 1000 |
Features
- Encoding detection: Automatically detects UTF-8, ISO-8859-1, windows-1252, and UTF-16LE. Respects
charsetdirectives in the file. - DUP format support: Detects and converts DUP files to PBN before parsing.
- Comment handling: Parses inline comments (
; ...) and block comments ({ ... }). - Error aggregation: Collects all parsing errors into a single
PNBAggregateError.
PBN Types
All PBN domain types are re-exported from the parser module.
import type {
PBNDeal,
PBNAuction,
PBNPlay,
PBNCard,
PBNComment,
PBNNote,
PBNNotes,
PBNNoteTarget,
PBNParseData,
} from '@workspace/bridge-core/parsers/pbn';PBNDeal
Prop
Type
PBNAuction
Prop
Type
PBNPlay
Prop
Type
PBNCard
Prop
Type
PBNNote
Prop
Type
PBNNotes
Prop
Type
PBNComment
Prop
Type