npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dicelette/core

v1.2.1

Published

Core library for the Dicelette Discord bot

Downloads

26

Readme

@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

| Name | Type | | :------ | :------ | | sign | Sign | | value | number | | total | number |

roll(dice): Resultat | undefined

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

| Name | Type | Description | | :------ | :------ | :------ | | dice | string | {string} |

Utils

cleanedDice(dice): string

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

  • ++ = +
  • +- = -
  • -- = +

| Name | Type | Description | | :------ | :------ | :------ | | dice | string | {string} |

escapeRegex(string): string

Escape regex string

| Name | Type | Description | | :------ | :------ | :------ | | string | string | {string} |

generateStatsDice(originalDice, stats?): string

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

| Name | Type | Description | | :------ | :------ | :------ | | originalDice | string | {dice} | | stats? | Object | {[name: string]: number} |

replaceFormulaInDice(dice, stats): string

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

| Name | Type | Description | | :------ | :------ | :------ | | dice | string | {string} |

Verify Template

diceRandomParse(value, template): string

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

| Name | Type | Description | | :------ | :------ | :------ | | value | string | {string} | | template | StatisticalTemplate | {StatisticalTemplate} |

diceTypeRandomParse(dice, template): string

| Name | Type | Description | | :------ | :------ | :------ | | dice | string | {string} | | template | StatisticalTemplate | {StatisticalTemplate} |

evalCombinaison(combinaison, stats): Object

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

| Name | Type | Description | | :------ | :------ | :------ | | combinaison | Object | {[name: string]: string} | | stats | Object | {[name: string]: string|number} |

evalOneCombinaison(combinaison, stats): any

Evaluate one selected combinaison

| Name | Type | Description | | :------ | :------ | :------ | | combinaison | string | {string} | | stats | Object | {[name: string]: string|number} |

evalStatsDice(testDice, stats?): string

Verify if the provided dice work with random value

| Name | Type | Description | | :------ | :------ | :------ | | testDice | string | {string} | | stats? | Object | {[name: string]: number} |

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

| Name | Type | Default value | | :------ | :------ | :------ | | total | undefined | number | 100 | | max? | number | undefined | | min? | number | undefined |

testCombinaison(template): void

Test all combinaison with generated random value

| Name | Type | | :------ | :------ | | template | StatisticalTemplate |

testDamageRoll(template): void

Test each damage roll from the template.damage

| Name | Type | | :------ | :------ | | template | StatisticalTemplate |

verifyTemplateValue(template): StatisticalTemplate

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

| Name | Type | | :------ | :------ | | template | any |