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

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

NameTypeDescription
textstring

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

What it prints (run when this page was built)

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