fromJSONfunction
A game from text that toJSON or toCode wrote, whichever game it is.
Nothing in it is trusted: every move is played through the rules again, and
a move the rules refuse means the text is not a game. Null for text that is
not JSON, names no game, is of a later format than this version reads, or
cannot be played out.
Import it
import { fromJSON } from "@johnmorrisdotca/toranpu";
Definition
function fromJSON(text: string): ReadGame | null
Parameters
| Name | Type | Description |
|---|---|---|
text | string | The notation, encoded state or saved text to read. |
Returns
ReadGame | null
A game from text that toJSON or toCode wrote, whichever game it is. Nothing in it is trusted: every move is played through the rules again, and a move the rules refuse means the text is not a game. null for text that is not JSON, names no game, is of a later format than this version reads, or cannot be played out.
Examples
import { fromJSON, newGame, toJSON } from "@johnmorrisdotca/toranpu";
const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!;
console.log(fromJSON(toJSON("hearts", game))?.kind);heartsWhat it prints (run when this page was built)