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

owlbear

v0.1.0

Published

A simple dice notation parser.

Downloads

23

Readme

Owlbear

Parses and composes dice notation, with support for exploding dice, rerolls, discarding lowest rolls, moving along a dice chain and simple arithmetic. Doesn't actually roll anything.

Example

var Owlbear = require('owlbear');

myOwlbear = new Owlbear();

myOwlbear.parse('4d6k3'); // k: keep n of x in xdykn
/* 
returns: 
[
  {
    count: 4,
    chain: 0,
    keep: 3,
    die: {
      sides: 6,
      reroll: [],
      explode: []
    }
  }
]
*/

myOwlbear.parse('1d4R! + 5'); // R: reroll lowest (1), !: explode highest (4)
/*
returns:
[
  {
    count: 1,
    chain: 0,
    keep: 1,
    die: {
      sides: 4,
      reroll: [1],
      explode: [4]
    }
  },
  {
    operator: '+'
  },
  {
    constant: 5
  }
]
*/

// or just get super goofy. 
// >: shift up dice chain, <: shift down.
// r: reroll listed, x: explode listed.
myOwlbear.parse(Math.PI + 'd10.5r6.2,6.3x10!>>>><');
/*
returns:
[
  {
    count: Math.PI,
    chain: 3,
    keep: Math.PI,
    die: {
      sides: 10.5,
      reroll: [6.2, 6.3],
      explode: [10.5, 10]
    }
  }
]
*/

// we can go backwards as well.
myOwlbear.compose([
  {
    constant: 10
  },
  {
    operator: '*'
  },
  {
    count: 1,
    chain: -1,
    keep: 1,
    die: {
      sides: 4,
      reroll: [1],
      explode: []
    }
  }
]) == '10*1d4R<';

Owlbear objects

new Owlbear(options);

Creates a new owlbear.

Supported options:

  • operators - Supported operators. Defaults to [ '*', '/', '+', '-' ].

parse() method

owlbear.parse(notation);

Dice notation may include any of the supported operators (as above) between die specifications. Each specification may be either a numeric constant or a die. Dice are in the format:

(number of dice)d(sides on a die)R!r(comma-separated numbers)x(comma-separated numbers)k(number of dice to keep)><

  • (number of dice) defaults to 1 if not present. May be floating point, must be non-negative.
  • (sides on a die) May be floating point, must be non-negative.
  • R indicates the lowest possible roll should be rerolled on this die.
  • ! indicates the highest possible roll should 'explode' -- be rerolled and added in.
  • r indicates the numbers afterward should be rerolled.
  • x indicates the numbers afterward should 'explode'.
  • k(number of dice to keep) indicates that only the highest n dice count.
  • < and > indicate shifts along a dice chain.

parse() returns an array of objects as shown in the above examples.

compose() method

owlbear.compose(Object[])

Returns a string of dice notation that will parse as the object provided.