UNPKG

@yipe/dice

Version:

A high-performance dice probability engine for D&D 5e DPR calculations. Powers dprcalc.com.

54 lines (50 loc) 2.35 kB
import { P as PMF } from './pmf-BC1poIqF.js'; export { B as Bin, C as CritConfig, D as DamageDistribution, i as DiceQuery, E as EPS, L as LRUCache, O as OutcomeLabelMap, j as OutcomeSnapshot, a as OutcomeType, R as Rounding, S as Snapshot, o as onAnyHit, b as onCritOnly, c as onHitOnly, e as onMissDamageOnly, d as onMissOnly, h as onPotentCantripOnly, g as onSaveFailOnly, f as onSaveHalfOnly, p as pmfCache } from './pmf-BC1poIqF.js'; /** Enable or disable the internal parse cache. */ declare function setCachingEnabled(enabled: boolean): void; /** Returns whether the internal parse cache is currently enabled. */ declare function getCachingEnabled(): boolean; /** Clears the internal parse cache. */ declare function clearParserCache(): void; /** * Parse a dice expression into a PMF. * * - Expression is case-insensitive and ignores spaces. */ declare function parse(expression: string, n?: number): PMF; /** A labeled mixture builder that preserves provenance in Bin.count. */ declare class Mixture<L extends string = string> { private readonly totals; private readonly labelMass; private readonly eps; constructor(eps?: number); /** Remove all accumulated state. */ clear(): this; /** Number of distinct outcome values currently accumulated. */ size(): number; /** Whether a label was ever added. */ hasLabel(label: L): boolean; /** * Add a labeled component with a mixture weight. * Weight can be any positive finite number. Very small contributions are pruned by eps. */ add(label: L, pmf: PMF, weight?: number): this; buildPMF(eps?: number): PMF; /** * Produce normalized *per-label* PMFs (labels independent). * These are unlabeled PMFs built from the raw mass of that label alone. */ byOutcome(): Record<L, PMF>; /** * Mixture weights per label, normalized to sum to 1 over labels that appeared. * Uses raw mass before per-outcome normalization. */ weights(): Record<L, number>; toJSON(): { totals: Array<[number, number]>; labels: Array<[number, Record<L, number>]>; eps: number; }; static mix<L extends string = string>(items: Array<[label: L, pmf: PMF, weight: number]>, eps?: number): PMF; } export { Mixture, PMF, clearParserCache, getCachingEnabled, parse, setCachingEnabled };