Skip to content

BCDice ported package for TypeScript and JavaScript by Opal.

License

Notifications You must be signed in to change notification settings

GenKuzumochi/bcdice-js

 
 

Repository files navigation

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

About

BCDice ported package for TypeScript and JavaScript by Opal.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 63.3%
  • TypeScript 33.8%
  • Shell 2.9%