npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@character-sheets/dice-lang

v1.0.0

Published

Dice language parser and interpreter with Codemirror support.

Readme

dice-lang

Roll dice using a streamlined and easy to learn language in a modern web app.

Use Online

Try and learn dice-lang using our online demo.

The sources for the demo can be found here:
https://github.com/Mvrlex/dice-lang-website

Installation

You can install the package using npm or yarn:

npm install @character-sheets/dice-lang

Use it in your project like this:

import { roll } from '@character-sheets/dice-lang';
const result = roll('2d6 + 1');
console.log(result.result);

Features

  • Rolling dice of any size
  • Math
  • Success Comparison
  • Filter (highest, lowest, keep, drop, and range of values)
  • Counting
  • Values References

For examples and explanations check out our documentation.

Usage

You can use the roll function to evaluate dice expressions, which can include arithmetic operations, die rolls, and various other operations like keep, drop, and count.

The function will return an expression object that contains the result in a tree-like structure, with the root node being the result of the entire expression.

roll("2d6 + 1").result // => 9
roll("d10 / 2").result // => 3
roll("d6 + @strength", { context: { strength: 2 } }).result // => 8
roll("2d6 keep highest").result // => 6

Syntax

Use d to denote a die roll, followed by the number of sides.

d6

If you want to roll multiple dice, provide a number before the d:

2d6

You can also use arithmetic operations like addition, subtraction, multiplication, and division. Division is always integer division, meaning it will round down to the nearest whole number.

2d6 + 1
(2 + 3) * 4 / 3

Filtering Results

Keep

You can filter the results of a die roll using the keep or drop keywords.

2d6 keep highest

This will keep the highest result of the rolled dice. You can also specify a number of results to keep or drop:

2d6 keep 2 highest

This will keep the two highest results of the rolled dice. You can also use conditions to filter the results:

2d6 keep >3

This will keep all results that are greater than 3.

All of these filters can be combined in a single expression:

2d6 keep 2 lowest >3

The order is important: you first specify the amount of results to keep or drop, then the selector (e.g. highest or lowest), and then the filter condition (e.g. >3). Any of these parts can be omitted, but the order must be preserved.

Drop

Drop has the same syntax as keep, but it will remove the results that match the condition instead of keeping them.

2d6 drop 2 lowest

Combined Filters

You can combine keep and drop filters in a single expression:

2d6 keep highest keep lowest

Filters will always be applied to all dice rolls, meaning that the keep lowest will keep the lowest result in addition to the highest result from the previous filter.

Counting

You can count the number of results that match a certain condition using the count keyword.

2d6 count >3

Alternatively, you can use the count keyword after a filtered expression to count the number of dice that were kept.

2d6 keep >3 count

References

You can reference variables in the expression using the @ symbol. This allows you to use variables from the context in your expressions, such as attributes from a character sheet in a role-playing game.

For example, if you have a variable strength in your context, you can use it like this:

@strength + 2d6

Currently, references are very limited, and you can only reference numbers. References can also not be nested.

Problems

If you have any issues with dice-lang please feel free to report them on our issue tracker.