Notation
Locale-aware rank parsing and formatting, rank and suit mappings, and the pre-configured engine.notation module.
Notation converts between the internal rank letters (A K Q J T 9 … 2) and what a player types or reads in a given locale and variant. The classic variant uses the 13-card deck and locale letters (French R D V, German D B, Swedish E D Kn…). The petit-bridge variant uses a 10-card deck displayed as numbers 10 … 1 in every locale.
Supported locales come from LOCALES in @workspace/bridge/constants: en, fr, es, it, ca, de, pt, el, nl, sv, pl.
Parsing and formatting depend on the variant and the locale, so they are only reachable through engine.notation, which binds both from the BridgeContext. The context-free pieces (rank orders, the rank mapping reader and the suit mapping tables) are exported by @workspace/bridge/card (DEFAULT_RANK_ORDER), @workspace/bridge/notation (PETIT_BRIDGE_RANK_ORDER, the types) and @workspace/bridge/locale (the mappings).
engine.notation
createBridgeEngine exposes the notation operations with the variant and locale already bound from the context. The variant is petit-bridge for the petit-bridge teaching mode and classic otherwise.
| Member | Type | Description |
|---|---|---|
variant | SuitVariant | Active variant. |
locale | Locale | Active locale. |
parseRanks(input) | (string) => Rank[] | Reads a typed string into standard ranks. Case-insensitive, ignores whitespace, matches longer tokens first (10, Kn), skips characters that match nothing. |
formatRanks(ranks) | (readonly Rank[]) => string | Sorts the ranks by DEFAULT_RANK_ORDER and joins their preferred display value with a space. Ranks absent from the variant's mapping are dropped. |
formatRank | RankFormatter | First display value of the rank mapping (K → "R" in French, A → "10" in petit-bridge); null for a rank outside the variant's deck. |
sortRanks(ranks) | (readonly Rank[]) => Rank[] | Sorter on PETIT_BRIDGE_RANK_ORDER or DEFAULT_RANK_ORDER. |
validRanks | readonly Rank[] | Ranks of the mode's deck (13 or 10). |
const engine = createBridgeEngine(
createBridgeContext({ teachingMode: "auction", locale: "fr" }),
);
engine.notation.locale; // => "fr"
engine.notation.variant; // => "classic"
engine.notation.parseRanks("RDV"); // => ["K", "Q", "J"]
engine.notation.formatRanks(["K", "Q", "J"]); // => "R D V"
engine.notation.formatRank("K"); // => "R"
engine.notation.sortRanks(["Q", "A", "J"]); // => ["A", "Q", "J"]
engine.notation.validRanks; // => ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2"]const petitBridge = createBridgeEngine(
createBridgeContext({ teachingMode: "petit-bridge", locale: "fr" }),
);
petitBridge.notation.variant; // => "petit-bridge"
petitBridge.notation.formatRank("A"); // => "10"
petitBridge.notation.formatRank("5"); // => "1"
petitBridge.notation.parseRanks("987"); // => ["K", "Q", "J"]
petitBridge.notation.validRanks; // => ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5"]Rank orders
Import DEFAULT_RANK_ORDER from @workspace/bridge/card and PETIT_BRIDGE_RANK_ORDER from @workspace/bridge/notation.
| Export | Signature | Description |
|---|---|---|
DEFAULT_RANK_ORDER | readonly Rank[] | 13 ranks, highest first. |
PETIT_BRIDGE_RANK_ORDER | readonly Rank[] | 10 ranks, A to 5, highest first. |
DEFAULT_RANK_ORDER.length; // => 13
PETIT_BRIDGE_RANK_ORDER.length; // => 10Rank mappings
Import from @workspace/bridge/locale.
| Export | Signature | Description |
|---|---|---|
getRankMapping | (variant: SuitVariant, locale: Locale) => RankMapping | The mapping for a variant and locale. Petit-bridge has one numeric mapping, so the locale is ignored there; classic reads the locale's table. |
A RankMapping lists, for each rank, the accepted inputs. The first entry is the display value. Only the honours and the ten vary; 9 to 2 are always the digit itself.
Classic mappings
| Locale | A | K | Q | J | T |
|---|---|---|---|---|---|
en | A | K | Q | J | 10, T |
fr | A | R, K | D, Q | V, J | 10, T |
es | A | R, K | D, Q | V, J | 10, T |
it | A | K, R | Q, D | J, F | 10, T |
ca | A | K | Q | J | 10, T |
de | A | K | D, Q | B, J | 10, T |
pt | A | R, K | D, Q | V, J | 10, T |
el | Α, A | Ρ, K | Ν, Q | Β, J | 10, Τ, T |
nl | A | H, K | V, Q | B, J | 10, T |
sv | E, A | K | D, Q | Kn, J | 10, T |
pl | A | K | D, Q | W, J | 10, T |
Petit-bridge mapping (all locales)
| Rank | A | K | Q | J | T | 9 | 8 | 7 | 6 | 5 |
|---|---|---|---|---|---|---|---|---|---|---|
| Inputs | 10, T | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
Suit mappings
Import from @workspace/bridge/locale.
| Export | Signature | Description |
|---|---|---|
CLASSIC_SUIT_MAPPINGS | Record<Locale, Record<string, readonly string[]>> | Accepted suit letters per locale, display value first. |
PETIT_BRIDGE_SUIT_MAPPINGS | Record<string, readonly string[]> | Colour letters: S→R (rouge), H→V (vert), D→J (jaune), C→B (bleu). |
| Locale | S | H | D | C |
|---|---|---|---|---|
en | S | H | D | C |
fr | P, S | C, H | K, D | T |
es | P, S | C, H | D | T |
it | P, S | C, H | Q, D | F, C |
ca | P, S | C, H | D | T |
de | P, S | H | K, D | T |
pt | E, S | C, H | O, D | P |
el | Π, S | Κ, H | Κα, D | Σ, C |
nl | S | H | R, D | K, C |
sv | S | Hj, H | R, D | K, C |
pl | P, S | K, H | K, D | T, C |
const french: RankMapping = getRankMapping("classic", "fr");
french.K; // => ["R", "K"] — first entry is the display preference
getRankMapping("petit-bridge", "fr").A; // => ["10", "T"] (same mapping in every locale)
CLASSIC_SUIT_MAPPINGS.de; // => { S: ["P", "S"], H: ["H"], D: ["K", "D"], C: ["T"] }
CLASSIC_SUIT_MAPPINGS.pt.S; // => ["E", "S"]Types
Import from @workspace/bridge/notation.
| Type | Definition |
|---|---|
RankMapping | Partial<Record<Rank, readonly string[]>> — accepted inputs per rank, first entry is the display preference. |
RankFormatter | (rank: Rank) => string | null — display string for one rank, null when the rank is not displayable in the variant. |
Translated labels for players, bids, vulnerability or scoring are not part of this package. UI packages receive them through a Strings Provider.