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

@randsum/notation

v3.0.0

Published

Dice notation parser and types for the @randsum ecosystem

Readme

npm version bundle size Types License

Zero-dependency dice notation parser, validator, and type system for JavaScript and TypeScript.

Note: Most users should install @randsum/roller, which re-exports everything from this package along with the roll() function. Install @randsum/notation directly only if you need parsing and validation without the rolling engine.

Installation

npm install @randsum/notation
# or
bun add @randsum/notation

Usage

Parsing Notation

import { isDiceNotation, notationToOptions } from "@randsum/notation"

isDiceNotation("4d6L") // true
isDiceNotation("banana") // false

const options = notationToOptions("4d6L")
// { sides: 6, quantity: 4, modifiers: { drop: { lowest: 1 } } }

Validation

import { validateNotation } from "@randsum/notation"

const result = validateNotation("4d6L")

if (result.valid) {
  result.notation // '4d6L'
  result.options // parsed RollOptions
} else {
  result.errors // array of validation errors
}

Converting Between Formats

import { optionsToNotation, optionsToDescription } from "@randsum/notation"

const notation = optionsToNotation({
  sides: 6,
  quantity: 4,
  modifiers: { drop: { lowest: 1 } }
})
// '4d6L'

const description = optionsToDescription({
  sides: 20,
  quantity: 1,
  modifiers: { plus: 5 }
})
// '1d20 + 5'

Listing Notation Strings

import { listOfNotations } from "@randsum/notation"

const notations = listOfNotations("4d6L + 2d8")
// ['4d6L', '2d8']

API

Parsing

  • isDiceNotation(value) - Type guard for valid dice notation strings
  • notationToOptions(notation) - Parse a notation string into a RollOptions object
  • listOfNotations(input) - Extract individual notation strings from a combined expression
  • validateNotation(notation) - Validate notation and return parsed result or errors
  • suggestNotationFix(notation) - Suggest corrections for invalid notation

Transformers

  • optionsToNotation(options) - Convert a RollOptions object to a notation string
  • optionsToDescription(options) - Convert a RollOptions object to a human-readable description
  • modifiersToNotation(modifiers) - Convert modifier options to their notation suffix
  • modifiersToDescription(modifiers) - Convert modifier options to a readable description

Comparison Utilities

  • parseComparisonNotation(notation) - Parse comparison syntax like {<3,>18}
  • hasConditions(options) - Check if comparison options have any conditions
  • formatComparisonNotation(options) - Format comparison options as notation
  • formatComparisonDescription(options) - Format comparison options as text

Types

import type {
  DiceNotation,
  RollOptions,
  ModifierOptions,
  ComparisonOptions,
  DropOptions,
  KeepOptions,
  RerollOptions,
  ReplaceOptions,
  UniqueOptions,
  SuccessCountOptions,
  ValidationResult,
  NotationSchema
} from "@randsum/notation"

Modifier Schemas

All 14 modifier notation schemas are exported for use by the roller's modifier registry:

capSchema, dropSchema, keepSchema, replaceSchema, rerollSchema, explodeSchema, compoundSchema, penetrateSchema, uniqueSchema, countSuccessesSchema, multiplySchema, plusSchema, minusSchema, multiplyTotalSchema

Related Packages