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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@3d-dice/dice-parser-interface

v0.2.1

Published

a parser interface that parses roll20 format strings using @3d-dice/dice-roller-parser for @3d-dice/dice-box

Downloads

860

Readme

Dice Parser Interface

This module simply provides an interface between @3d-dice/dice-roller-parser and @3d-dice/dice-box. Since dice-roller-parser is a fork of another person's module, I did not want to include this interface in that package.

FDP (Fantastic Dice Parcer) has been renamed to Dice Parser Interface for symantics. The @3d-dice/fdp npm module has been depricated

What it does

This module allows for more advanced rolls with dice-box. All the rolls supported are documented at Roll20 Dice Specification

How to use it

Install the library using:

npm install @3d-dice/dice-parser-interface

Then create a new instace of dice-parser-interface

import DiceParser from '@3d-dice/dice-parser-interface'

const DP = new DiceParser()

The DP class now has methods to parse raw notations, process re-rolls and compute the final results from dice-box

<form id="dice-to-roll">
  <input id="input--notation" class="input" placeholder="2d20" autocomplete="off" />
</form>
const form = document.getElementById("dice-to-roll")
const notationInput = document.getElementById("input--notation")

const submitForm = (e) => {
  e.preventDefault();
    const notation = DP.parseNotation(notationInput.value)
}

form.addEventListener("submit", submitForm)

Methods

parseNotation(string, default: '')

Accepts a dice string input, parses it and returns a JSON representation of the parsed input.

Example: DP.parseNotation('4d6')

[
  {
    "qty": 4,
    "sides": 6,
    "mods": [],
    "rolls": [
      {
        "sides": 6,
        "groupId": 0,
        "rollId": 0,
        "id": 0,
        "theme": "sunset",
        "result": 1
      },
      {
        "sides": 6,
        "groupId": 0,
        "rollId": 1,
        "id": 1,
        "theme": "sunset",
        "result": 3
      },
      {
        "sides": 6,
        "groupId": 0,
        "rollId": 2,
        "id": 2,
        "theme": "sunset",
        "result": 6
      },
      {
        "sides": 6,
        "groupId": 0,
        "rollId": 3,
        "id": 3,
        "theme": "sunset",
        "result": 6
      }
    ],
    "value": 16
  }
]

See also: Just parse the value

handleRerolls(array, default:[])

This method accepts an array of dice rolls (generated by parseNotation, updated by dice-box) and returns a new array of dice objects that need to be re-rolled. Examples of rolls that could generate rerolls include, exploding, penetrating, and compounding rolls (e.g.: 6d6!). Reroll and reroll-once notation is also supported (e.g.: 2d12r1).

Dice Object:

| Property | Type | Description | |-|-|-| |groupId|int|The group the reroll target belongs to| |rollId|int or string|The roll id of the die being rerolled. This will be incremented by .1 for every reroll made| |side|int|The number of sides the reroll die has| |qty|int|The number of dice to be rolled. This will always be 1 on rerolls but is needed by dice-box|

Example:

[
  {
    "groupId": 0,
    "rollId": "2.1",
    "sides": 6,
    "qty": 1
  },
  {
    "groupId": 0,
    "rollId": "3.1",
    "sides": 6,
    "qty": 1
  }
]

parseFinalResults(array, default: [])

After all rolls and rerolls have completed, you can pass the results object to parseFinalResults to get the final results of the dice roll. This typically happens inside dice-box's onRollComplete callback method.

Example:

const results = DP.parseFinalResults(results)

Putting it all together

Example HTML

Example JavaScript

Caveats

One thing this modules does not do is provide the interface for providing an input for the roll notation string or displaying the final results. It is expected that the developer will create their own inputs and outputs or use modules from @3d-dice/dice-ui