0.0.6 • Published 3 years ago

dice-roll-check v0.0.6

Weekly downloads
288
License
MIT
Repository
-
Last release
3 years ago

dice-roll-check

Rolls dice and checks the result from a single text string.

installation

npm install dice-roll-check

basics

You can break down a text string to a dice rolled result object. +(plus), -(minus), *(multiple), /(devide) are usable to calculate.
Only single sign which of the following is valid in the string. =(equal), <(less), >(greater), <=(lessor or equal), >=(greater or equal)
Any message may be added after a space.

const { roll } = require('dice-roll-check')

roll('1d100<=60 Some additional Message.')


/* This results like below.
{
  resultText: '1d100[47]<=60 => 47<=60 => Success! Some additional,
  resultTextSimple: '1d100[47]<=60 => Success! Some additional Message.',
  processed: true,
  info: {
    input: '1d100<=60 Some additional Message.',
    firstPart: '1d100<=60',
    secondPart: ' Some additional Message.',
    sign: '<=',
    rollLeftSidePart: { sum: 47, str: '1d100[47]', dice: [ { type: 100, result: [ 47 ] } ] },
    rollRightSidePart: { sum: 60, str: '60', dice: [] },
    rollResult: '1d100[47]<=60',
    rollResultText: '1d100[47]<=60 => 47<=60 => Success!',
    rollResultTextSimple: '1d100[47]<=60 => Success!',
    rollSucceed: true
  },
  error: null
} 
*/

options

roll('3d6', { sortRollResults: false })
option propertytypedefaultdescription
defaultDiceMinnumber1Dice minimum number. example: set this value to 0 results that 1d6 takes range between 0 and 5.
defaultDiceMaxnumber6Dice maximum number when dice type is ommited. example: set this value to 100 results that 2d means to roll 1d100 twice.
sortRollResultsbooleantrueResult sort flag. Whether to sort dice roll results or not.
rollSucceedTextstringSuccess!Succeed to check text.
rollFailedTextstringFail...Failed to check text.
rollResultArrowstring=>Arrow text.
customRandomMethodfunctiondefaultGetRandomInt()A function to get the random value. Default function example is below.
function defaultGetRandomInt (min, max) {
  const limit = max - min
  return min + Math.floor(Math.random() * limit)
}
0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago