Reference · Rolls and exact odds
fromJSONfunction
Rolls from JSON that toJSON wrote, or a history that serializeHistory
did. Nothing in it is trusted: each roll is put together again from its
dice and its faces, and one that does not add up is left out. Null when the
text is not JSON, holds no list of rolls, or is of a later format than this
version reads.
Import it
import { fromJSON } from "@johnmorrisdotca/korokoro";
Definition
function fromJSON(text: string): Roll[] | null
Parameters
| Name | Type | Description |
|---|---|---|
text | string | Text to parse, validate or format. |
Returns
Roll[] | null
Rolls from JSON that toJSON wrote, or a history that serializeHistory did. Nothing in it is trusted: each roll is put together again from its dice and its faces, and one that does not add up is left out. null when the text is not JSON, holds no list of rolls, or is of a later format than this version reads.
Examples
import { fromJSON } from "@johnmorrisdotca/korokoro";
import { normalizeSpec, rollFrom, toJSON } from "@johnmorrisdotca/korokoro";
const spec = normalizeSpec({ count: 2, sides: 6 });
const sample = rollFrom(spec, [2, 5], "saved", 0, null)!;
console.log(fromJSON(toJSON([sample]))?.length);1What it prints (run when this page was built)