Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dicelette/core

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dicelette/core

Core library for the Dicelette Discord bot

  • 1.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
480
increased by1746.15%
Maintainers
0
Weekly downloads
 
Created
Source

@Core

The core module for Dicelette, contains :

  • The dice function (that parse the string into a Dice Parser and send the result in a good message) ;
  • The verification of the template

The two are used in the bot and documentation.

Type alias

  • Sign: "+" | "-" | "*" | "/" | "%" | "^" | "**";
  • Statistic : { [name: string]: { combinaison?: string; max?: number; min?: number; } } :
    • name: string : The name of the statistic
    • combinaison: string : A combinaison between multiple/other statistic, formula... (ex: constitution+2). Can't coexist with min & max.
    • max: number : The maximum value of the statistic
    • min: number : The minimum value of the statistic

Interface (index.d.ts)

Compare

  • sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "=="
  • value: number

Critical

  • Optional failure: number
  • Optional success: number

Modifier

  • sign: Sign
  • value: number

Resultat

  • Optional comment: string
  • Optional compare: Compare
  • dice: string
  • Optional modifier: Modifier
  • result: string

Statistical Template

Example

diceType: "1d20+{{$}}>=20"

The dice throw will be 1d20 + statistique that must be less than 20

diceType: "1d20<=$"

The dice throw will be 1d20 that must be less than the statistic

Properties

  • Optional charName: boolean Allow to force the user to choose a name for them characters

  • Optional critical: Critical How the success/echec will be done

  • Optional damage: { [name: string]: string } Special dice for damage

  • Optional diceType: string A die type in the notation supported by the bot. See documentation for syntaxe.

  • Optional statistics: Statistic

  • Optional total: number A total can be set, it allows to calculate the total value of a future register member If the sum of the value > total, the bot will send a message to the user to inform him that the total is exceeded and an error will be thrown Note: Statistic that have a formula will be ignored from the total

Modules

Dice

Variables

  • const COMMENT_REGEX: RegExp

Functions

calculator(sign, value, total): number

Evaluate a formula and replace "^" by "**" if any

NameType
signSign
valuenumber
totalnumber
roll(dice): Resultat | undefined

Parse the string provided and turn it as a readable dice for dice parser

NameTypeDescription
dicestring{string}

Utils

cleanedDice(dice): string

Replace the ++ +- -- by their proper value:

  • ++ = +
  • +- = -
  • -- = +
NameTypeDescription
dicestring{string}

escapeRegex(string): string

Escape regex string

NameTypeDescription
stringstring{string}

generateStatsDice(originalDice, stats?): string

Replace the stat name by their value using stat and after evaluate any formula using replaceFormulaInDice

NameTypeDescription
originalDicestring{dice}
stats?Object{[name: string]: number}

replaceFormulaInDice(dice, stats): string

Replace the {{}} in the dice string and evaluate the interior if any

NameTypeDescription
dicestring{string}

Verify Template

diceRandomParse(value, template): string

Generate a random dice and remove the formula (+ evaluate it) Used for diceDamage only

NameTypeDescription
valuestring{string}
templateStatisticalTemplate{StatisticalTemplate}

diceTypeRandomParse(dice, template): string

NameTypeDescription
dicestring{string}
templateStatisticalTemplate{StatisticalTemplate}

evalCombinaison(combinaison, stats): Object

Random the combinaison and evaluate it to check if everything is valid

NameTypeDescription
combinaisonObject{[name: string]: string}
statsObject{[name: string]: string|number}

evalOneCombinaison(combinaison, stats): any

Evaluate one selected combinaison

NameTypeDescription
combinaisonstring{string}
statsObject{[name: string]: string|number}

evalStatsDice(testDice, stats?): string

Verify if the provided dice work with random value

NameTypeDescription
testDicestring{string}
stats?Object{[name: string]: number}

generateRandomStat(total?, max?, min?): number

NameTypeDefault value
totalundefined | number100
max?numberundefined
min?numberundefined

testCombinaison(template): void

Test all combinaison with generated random value

NameType
templateStatisticalTemplate

testDamageRoll(template): void

Test each damage roll from the template.damage

NameType
templateStatisticalTemplate

verifyTemplateValue(template): StatisticalTemplate

Parse the provided JSON and verify each field to check if everything could work when rolling

NameType
templateany

Keywords

FAQs

Package last updated on 01 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc