Reference · Rolls and exact odds
loadHistoryfunction
Read a kept history. A storage that throws (a private window, blocked cookies) reads as empty.
Import it
import { loadHistory } from "@johnmorrisdotca/korokoro";
Definition
function loadHistory(storage: StorageLike | undefined, key: string): Roll[]
Parameters
| Name | Type | Description |
|---|---|---|
storage | StorageLike | undefined | Storage with getItem, setItem and removeItem, or undefined when unavailable. |
key | string | The storage key to read or write. |
Returns
Roll[]
Read a kept history. A storage that throws (a private window, blocked cookies) reads as empty.
Examples
import { loadHistory } from "@johnmorrisdotca/korokoro";
import { normalizeSpec, rollFrom, saveHistory } from "@johnmorrisdotca/korokoro";
const values = new Map<string, string>();
const storage = {
getItem: (key: string) => values.get(key) ?? null,
setItem: (key: string, value: string) => { values.set(key, value); },
removeItem: (key: string) => { values.delete(key); },
};
const spec = normalizeSpec({ count: 2, sides: 6 });
const sample = rollFrom(spec, [2, 5], "saved", 0, null)!;
saveHistory(storage, "history", [sample]);
console.log(loadHistory(storage, "history").length);1What it prints (run when this page was built)