Notable changes to opendice. The format follows
Keep a Changelog, and this package follows
semantic versioning: anything that changes the
public API is a major version, and the breaking label on GitHub marks issues and pull
requests that would.
This package was @openfray/dice up to and including 1.1.0, and is opendice from 1.1.0
onward — opendice@1.1.0 carries the same code as @openfray/dice@1.1.0. The old name
stays on npm, deprecated, so nothing that depends on it breaks.
npm uninstall @openfray/dice && npm install opendiceEvery import changes with it: from '@openfray/dice' becomes from 'opendice'.
A rename is not a version, so it has no entry below.
Nothing yet.
2.0.0 — 2026-08-30
Dice-group facts are now complete, formula inputs fail closed, and the default CSPRNG is faster.
- Breaking: required
DieGroup.keptFlagsrecords which occurrence inresultscounted.
- Breaking: advantage state moved from
RollResultto eachDieGroup; equivalentkhandklrules reportnormal. - Breaking: contextual advantage requires one compatible original dice group with at least two dice; ambiguous, conflicting and invalid requests throw before rolling.
- Breaking:
advanddisrequire a written count of at least 2 instead of adding a die. - Formula length counts raw input, recognised tags are bounded, and every grammar number must stay exact.
- The default CSPRNG fetches 256 independent words per platform call, improving complete-roll benchmarks by 1.47× to 10.95× without changing rejection sampling.
rollDierejects malformedRandomSourceoutput withTypeErrororRangeErrorinstead of coercing it.keptFlags(group)uses stored markers; old objects retain best-effort value matching.
1.4.0 — 2026-08-22
Two more ways to read dice, and a README that stops repeating the documentation site.
khandklwith no number after them keep one die, so3d100khis3d100kh1. The count was mandatory and a barekhwas a parse error, which no reading of the formula explained.4d6kh0still throws: leaving the number out is not writing zero.- Floors and ceilings.
2d6min3gives every die a value it has to beat and2d6max5one it may not pass;totalminandtotalmaxset the bound against the group's total instead. The bound goes intoresultsas a value the dice competed against rather than rewriting a face, so nothing rolled is lost andtotalcan still be checked againstkept. A group that kept a bound reports no highest or lowest face, since a bound is not a die. A bound must be at least 1, and does not combine withkh,kl,adv,disor!.
- The README is the short version and rollful.dev/docs is the reference. Keeping a full second copy of the documentation in the README meant two places to update and one of them going stale. Nothing about the package changed with it.
1.3.0 — 2026-08-06
The count written in front of adv and dis is now the count that gets rolled.
advanddisno longer overwrite the count they were written with. The suffix says which one die survives, and the count says how many are thrown, so4d20advrolls four d20 and keeps the highest. It used to roll two whatever the formula asked for:4d20advwas2d20kh1, and the4was discarded without a word.
-
A count of 1 with
advordis.1d20advstill rolls, and still rolls two dice, but it now warns once per suffix that2d20advis the formula it means. One die leaves the suffix nothing to choose between, so the count cannot be taken at face value. A future version will refuse it. The migration is mechanical: every1d20advbecomes2d20adv.The warning goes to
console.warn, once per process per suffix rather than per roll. Note thatformulaon the result stays exactly as you wrote it, so a roll log built from it will show1d20advbeside two dice until the formula is fixed.
The advantage option in RollContext is unchanged, warns nothing, and still takes a plain
1d20: roll('1d20+7', { advantage: 'advantage' }) rolls the second die for you. The option
applies advantage to a formula already written, where the suffix states the dice up front. A
formula already asking for more than two d20 now keeps its own count instead of being cut
back to two.
1.2.0 — 2026-08-06
A way of rolling dice that was missing, and a packaging fault that made the published source maps useless.
- Penetrating dice:
1d6!pexplodes on a top face like1d6!, but every roll after the first counts 1 less. HackMaster uses this. The deduction comes off what a roll is worth and not off the face it landed on, so it never shortens a chain — a second roll showing a 6 on a d6 is recorded as 5 and still rolls again. Only the extra rolls lose a point, so1d6!pis not1d6!minus 1, and a penetrated 1 is recorded as 0, the one case whereresultsholds a number below 1. It takes a multiplier (1d6!px2), and carries the same two limits as!: 100 penetrations per die, and no combining withkh,kl,advordis.DieGroupis unchanged, sokeptstill sums tototal;DiceTermgainedpenetrate, set alongsideexploderather than replacing it, so anything already readingexplodekeeps working.
- The published package includes
src, so the source maps in it point at files that are there. Every.js.mapand.d.ts.mapnames../src/*.ts, andfileslisted onlydist,README.mdandLICENSE, so the sources were left out of the tarball — a bundler reading them warned that the sourcemap for each of the four modules points to missing source files. It also makes the declaration maps work: go to definition onrollnow opensroll.tsrather than the generatedroll.d.ts.
1.1.0 — 2026-08-04
Hardening after an adversarial review of the package, and a group multiplier.
Several entries below are marked Breaking: they refuse input that 1.0.0 accepted. None
of it is input a working caller was likely to be sending on purpose, but read those entries
before upgrading — tags: 'fire', roll('2+5'), 1d0, a formula containing a tab or a
line break, and a bonuses fragment with no dice in it all throw now.
- A formula can no longer hang the process.
1d4294967297used to spin forever — above 2³² sides the rejection ceiling rounds down to zero, so every draw was rejected — and99999999d6rolled dice one at a time until the process ran out of memory. A formula is bounded to 1,000 dice, 2³² sides per die and 1,000 characters, and bonuses count towards the dice limit. rollDiegives up after 1,000 rejected draws in a row rather than redrawing forever. ARandomSourcereturning a value the die always rejects used to hang, which is exactly what the explosion cap exists to prevent — rejection just happens first.- Options and terms are read as own properties. A polluted
Object.prototypecould otherwise supply therandsource for a roll that passed none, force advantage, add bonuses, or forge atagon the result — with the roll reporting all of it as fact. - Parsing no longer slows down quadratically on a formula padded with whitespace.
- A formula may only contain letters, digits, spaces,
+,-and!. Whitespace is stripped before a formula is read butformulakeeps the text verbatim, so a tab, a line break, a non-breaking space, U+2028 or a zero-width space all used to ride through intoRollResult.formula— and a line break there forges an extra line in whatever log or CSV row the caller writes the roll to, which is the one artifact this package exists to make trustworthy. Twenty-five code points could do it, U+212A among them: it lowercases to a plaink, so4d6Kh3parsed and left the sign informula. crypto.getRandomValuesis taken once as the module loads rather than looked up on every call. Anything else sharing the page — an analytics tag, a dependency further down the bundle — could replace it and own every roll from then on, reported by a roll log that still looked honest. This closes the window after load; nothing in JavaScript can close the one before it.rollDienames the type of a non-number instead of repeating it. TypeScript saysnumber, but a JavaScript caller is not bound by that, and the message is as likely to be shown to someone as any other.parseFormularefuses non-text input the same way, rather than failing withinput.trim is not a function.bonusesis capped at 100 entries. Every entry is parsed before the dice limit can refuse the roll, so a million of them burned about 2.4 seconds whatever they added up to.- The publish workflow pins npm instead of installing
@latestbeside the OIDC credential. - An error no longer repeats the input word for word.
roll('<img src=x onerror=…>')threw anErrorwhose message carried that markup verbatim and twice — and a caller putting the message on a page, which is what an error about typed input is for, would have put the markup on the page with it. What is quoted is now shortened, and anything a formula could not contain is replaced. Escaping what you display is still the caller's job.
- A group multiplier:
1d6x10rolls a d6 and multiplies that group by ten, and2d6x3adds both dice then triples them. It binds to one dice group the waykh3does, so it never applies to the whole sum and there is no precedence to get wrong —1d6x10+5is 35 on a 3, not 80. It composes with keep rules, advantage and exploding, always applying last to whatever the group kept.5x2is not a formula: this multiplies dice, not arithmetic.DieGroupgainedmultiplier, so a total can still be checked againstkept.
- A total that cannot be exact is refused instead of quietly rounded.
1d6+99999999999999999999reported a rounded number and1d6+followed by four hundred nines reportedInfinity. - A numeric
bonusesentry must be a whole number that stays exact.NaN, an infinity and1.5used to pass straight through into the total. 4d6kh0is refused rather than keeping no dice and contributing nothing.- Breaking: a formula must roll at least one die.
roll('2+5')answered 7 androll('0d6')answered 0, both handing back a total with an emptydicelist behind it.parseFormulais the documented way to check what someone typed, so it is what refuses them — which also means abonusesfragment has to contain dice, and a plain number should be passed as a number.
- Breaking:
tagstakes a list or aSet, and a bare string is now refused. A string is an iterable of single letters, sotags: 'fire'used to quietly acceptf,i,rande. TypeScript rejects it too. - Breaking:
parseFormularejects a die with no sides (1d0) and one with more sides than a single draw can address, rather than parsing it and failing later at roll time. Checking a formula now catches everything rolling it would. parseFormulaandrollreturn objects with no prototype. Reading, spreading andJSON.stringifyare unchanged;console.loglabels them[Object: null prototype].
- A rigged
randproduces a result identical to a fair one — nothing records which source a roll used. Only pass a source your own code chooses.
1.0.0 — 2026-08-04
First release.
roll(formula, options?)— parses a formula, rolls it, and returns the total along with every die rolled, which of them counted, and each flat modifier separately.- A formula grammar:
2d6,1d20+7,10-1d4,1d8+1d4+3, keep highest or lowest (4d6kh3,4d6kl3), advantage and disadvantage (1d20adv,1d20dis), exploding dice (1d6!), and an optional trailing label (2d10 fire). - Any number of sides.
1d78is as valid as1d20. naturalHighandnaturalLowon each group of dice, reporting whether the single die it kept landed on its highest or lowest face — for any die, not only a d20.parseFormula(text, options?)— reads a formula without rolling it, for checking input before it is used.rollDie(sides, source?)— one die, no formula.cryptoRandom()— the underlying random source, exported so it can be inspected.keptFlags(group)— which dice counted, aligned to the order they were rolled.soleDieGroup(result)— the one group of dice in a roll, when a roll used only one kind.- A
randoption taking anyRandomSource, so rolls can be made deterministic in tests. - TypeScript types, source maps, and npm provenance on every published release.