# owlbear

> A simple dice notation parser.

Latest version **0.1.0** (published 2013-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install owlbear
pnpm add owlbear
yarn add owlbear
bun add owlbear
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2013-05-07 |
| First published | 2013-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6 |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | John Mark Hawley |
| Maintainers | jmhnilbog |
| Keywords | rpg, dice, die notation |

## Links

- npm: https://www.npmjs.com/package/owlbear
- Repository: https://github.com/jmhnilbog/owlbear
- npm.io page: https://npm.io/package/owlbear

## Dependencies (4)

- [mocha](https://npm.io/package/mocha.md) ~1.9.x
- [should](https://npm.io/package/should.md) ~1.2.x
- [underscore](https://npm.io/package/underscore.md) ~1.1.x
- [escape-regexp](https://npm.io/package/escape-regexp.md) 0.0.x

## Recent versions

- 0.1.0 (latest) — 2013-05-07

## 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.

---
_Source: https://npm.io/package/owlbear · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
