Reference · Rolls and exact odds
serializeHistoryfunction
A history as text, to keep in a browser's storage or anywhere else. parseHistory reads it back.
Import it
import { serializeHistory } from "@johnmorrisdotca/korokoro";
Definition
function serializeHistory(history: readonly Roll[]): string
Parameters
| Name | Type | Description |
|---|---|---|
history | readonly Roll[] | Completed rolls, newest first where the history API requires it. |
Returns
string
A history as text, to keep in a browser's storage or anywhere else. parseHistory reads it back.
Examples
import { serializeHistory } from "@johnmorrisdotca/korokoro";
import { normalizeSpec, rollFrom } from "@johnmorrisdotca/korokoro";
const spec = normalizeSpec({ count: 2, sides: 6 });
const sample = rollFrom(spec, [2, 5], "saved", 0, null)!;
console.log(serializeHistory([sample]));{"version":1,"rolls":[{"id":"saved","spec":{"count":2,"sides":6,"modifier":0,"keep":"all"},"faces":[2,5],"kept":[true,true],"total":7,"at":0,"seed":null}]}What it prints (run when this page was built)