Skip to the content

Korokoroコロコロ

Roll mixed dice or type notation, compare exact probabilities, keep a history and replay seeded rolls.

Korokoro describes something small rolling in Japanese. About the name

Contents

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

NameTypeDescription
storageStorageLike | undefined

Storage with getItem, setItem and removeItem, or undefined when unavailable.

keystring

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);
1

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/korokoro 1.16.0.