JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 169
  • Score
    100M100P100Q78205F
  • License MIT

A very tiny dice util. You can roll a dice with any amount of sides.

Package Exports

  • roll-anything

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (roll-anything) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Roll anything 🎲

npm i roll-anything

A very tiny dice util. You can roll a dice with any amount of sides.

Meet the family

Usage

import dice from 'roll-anything'

const dice = dice()
// will return
// {
//   sides: 6,
//   roll: function
// }

// Rolling 🎲👋
dice().roll() // will return 1 ~ 6
dice(2).roll() // will return 1 ~ 2
dice(10).roll() // will return 1 ~ 10

// Roll and evaluate
dice(6).roll(6)
// will roll 1 ~ 6 and return true if it rolled 6 immidiately
dice(2).roll(1)
// 50-50 chance

Source code

The source code is litterally just this, but written in TypeScript:

export default function dice (sides = 6) {
  return {
    sides,
    roll (target) {
      const randomNumber = Math.floor(Math.random() * this.sides) + 1
      if (target === undefined) return randomNumber
      return target === randomNumber
    }
  }
}