Skip to content

Latest commit

 

History

History
93 lines (76 loc) · 2.34 KB

README.md

File metadata and controls

93 lines (76 loc) · 2.34 KB

BCDice

npm Snyk Vulnerabilities for npm package Travis (.org) GitHub issues GitHub forks GitHub stars GitHub license

BCDice ported package for JavaScript by Opal.

Install

$ npm install --save bcdice

Usage

import BCDice, { Info } from 'bcdice';
import 'bcdice/lib/diceBot/Cthulhu';

/* or CommonJS
const BCDice = require('bcdice').default; // Do not forget ".default"

require('bcdice/lib/diceBot/Cthulhu');
*/

function getInfo(gameType: string): Info | undefined {
  return BCDice.infoList.find(info => info.gameType === gameType);
}

interface RollResult {
  result: string;
  rands: number[][] | null;
}

function roll(command: string, gameType: string): RollResult {
  const bcdice = new BCDice();
  const [result, rands] = bcdice.roll(command, gameType);
  return {
    result,
    rands,
  };
}

console.log(getInfo('Cthulhu'))
console.log(roll('CC', 'Cthulhu'));

Dynamic Importing

import BCDice, { Info } from 'bcdice';

function getInfo(gameType: string): Info | undefined {
  return BCDice.infoList.find(info => info.gameType === gameType);
}

interface RollResult {
  result: string;
  rands: number[][] | null;
}

function roll(command: string, gameType: string): Promise<RollResult? {
  const bcdice = new BCDice();
  return import(`bcdice/lib/diceBot/${gameType}`).then(() => {
    const [result, rands] = bcdice.roll(command, gameType);
    return {
      result,
      rands,
    };
  });
}

console.log(getInfo('Cthulhu'));
roll('CC', 'Cthulhu').then(result => console.log(result));

Development

Install

$ bundle install
$ npm install

Build

$ npm run build

Test

$ npm test