Reference · Rules, tiles and records
kumimojiFromJSONfunction
A game from JSON that kumimojiToJSON wrote. Nothing in it is trusted: the
bag is dealt again from the seed, and the game opens only if every tile held
is one that came out of that bag. Resolves to null when the text is not
JSON, is of a later format than this version reads, is another game's, or
holds a hand or a grid that this bag never dealt.
The word list of the game's language is loaded first, since dealing needs
it; where there is no browser, import @johnmorrisdotca/kumimoji/words
once, or the promise is rejected as loadTileWords rejects it.
Import it
import { kumimojiFromJSON } from "@johnmorrisdotca/kumimoji";
Definition
function kumimojiFromJSON(text: string): Promise<KumimojiSaved | null>
Parameters
| Name | Type | Description |
|---|---|---|
text | string | The saved JSON text to validate. |
Returns
Promise<KumimojiSaved | null>
A game from JSON that kumimojiToJSON wrote. Nothing in it is trusted: the bag is dealt again from the seed, and the game opens only if every tile held is one that came out of that bag. Resolves to null when the text is not JSON, is of a later format than this version reads, is another game's, or holds a hand or a grid that this bag never dealt.
Examples
import { deal, generateKumimoji, kumimojiFromJSON, kumimojiToJSON } from "@johnmorrisdotca/kumimoji";
import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
await loadTileWordsFromModule("english");
const play = deal("catdog",3);
const dealt = generateKumimoji(3,"hard",44);
const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
console.log((await kumimojiFromJSON(kumimojiToJSON(saved)))?.deal.seed);44What it prints (run when this page was built)