Reference · Streams, draws and seeds
fromJSONfunction
A position from JSON that toJSON wrote. Nothing in it is trusted: the
seed and the draws must be whole numbers in range, the algorithm (when
named) must be mulberry32, and the state (when given) must be the one that
seed and those draws come to. Null when the text is not JSON, is not a
position, does not add up, or is of a later format than this version reads.
Import it
import { fromJSON } from "@johnmorrisdotca/tane";
Definition
function fromJSON(text: string): StreamPosition | null
Parameters
| Name | Type | Description |
|---|---|---|
text | string | Text to hash, validate or decode. |
Returns
StreamPosition | null
A position from JSON that toJSON wrote. Nothing in it is trusted: the seed and the draws must be whole numbers in range, the algorithm (when named) must be mulberry32, and the state (when given) must be the one that seed and those draws come to. null when the text is not JSON, is not a position, does not add up, or is of a later format than this version reads.
Examples
import { fromJSON, toJSON } from "@johnmorrisdotca/tane";
const position = { seed: 42, draws: 3 };
console.log(fromJSON(toJSON(position)));{ seed: 42, draws: 3 }What it prints (run when this page was built)