@yipe/dice 0.2.22 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/builder/index.cjs +392 -295
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.d.cts +9 -9
- package/dist/builder/index.d.ts +9 -9
- package/dist/builder/index.js +392 -296
- package/dist/builder/index.js.map +1 -1
- package/dist/index.cjs +356 -256
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +356 -257
- package/dist/index.js.map +1 -1
- package/dist/{pmf-BC1poIqF.d.cts → pmf-DqUCnYN9.d.cts} +89 -10
- package/dist/{pmf-BC1poIqF.d.ts → pmf-DqUCnYN9.d.ts} +89 -10
- package/package.json +11 -13
package/README.md
CHANGED
|
@@ -312,6 +312,23 @@ const query = new DiceQuery(pmf);
|
|
|
312
312
|
console.log("DPR:", query.mean());
|
|
313
313
|
```
|
|
314
314
|
|
|
315
|
+
### Error Handling
|
|
316
|
+
|
|
317
|
+
`parse()` throws a `DiceParseError` (a subclass of `Error`) for invalid input.
|
|
318
|
+
Narrow with `instanceof` and inspect the offending `expression`:
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
import { parse, DiceParseError } from "@yipe/dice";
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
parse("d6@3");
|
|
325
|
+
} catch (err) {
|
|
326
|
+
if (err instanceof DiceParseError) {
|
|
327
|
+
console.warn(`Bad dice expression: ${err.expression}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
315
332
|
### Sneak Attack (Conditional Damage)
|
|
316
333
|
|
|
317
334
|
Conditional damage ("once-per-turn damage riders") like Sneak Attack can be modeled easily:
|