Get Started
Install
NPM:
npm install @dice-roller/rpg-dice-roller
Yarn:
yarn add @dice-roller/rpg-dice-roller
<script src="https://cdn.jsdelivr.net/npm/@dice-roller/rpg-dice-roller@VERSION/lib/umd/bundle.min.js"></script>
Replace
VERSION
with the version you want to use.
Setup
ES modules
You can import the dice roller and use it in your application, using ES standard modules like so:
import * as rpgDiceRoller from '@dice-roller/rpg-dice-roller';
If you only want to import specific components, you can do so like:
import { DiceRoller } from '@dice-roller/rpg-dice-roller';
CommonJS
Node.js
We only support Node.js 12+. Please check the browser support.
TIP
If you're using Node.js, with ES modules (import
) instead of CommonJS (require
) follow the ES modules examples above.
You can also load the library using CommonJS, AMD, etc. with the UMD build:
const rpgDiceRoller = require('@dice-roller/rpg-dice-roller');
If you only want to import specific components, you can do so like:
const { DiceRoller } = require('@dice-roller/rpg-dice-roller');
Browsers
Browser support
We don't guarantee that the library works with all older browsers. We advise you to check the browser support.
Dependencies
First, you'll need to include some third party dependencies:
<script src="https://unpkg.com/mathjs@9.3.2/lib/browser/math.js"></script>
<script src="https://cdn.jsdelivr.net/npm/random-js@2.1.0/dist/random-js.umd.min.js"></script>
Dice Roller
You can either download the file locally, or use the CDN (Note umd
in the path, instead of esm
):
<!-- local file -->
<script src="./path/to/lib/umd/bundle.min.js"></script>
<!-- or CDN -->
<script src="https://cdn.jsdelivr.net/npm/@dice-roller/rpg-dice-roller@VERSION/lib/umd/bundle.min.js"></script>
The UMD bundle provides the global variable, rpgDiceRoller
, that is used to access the library.
<script>
// create a new instance of the DiceRoller
var diceRoller = new rpgDiceRoller.DiceRoller();
</script>