Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit c0850a9

Browse files
Tom WolfeTom Wolfe
authored andcommitted
Fix dice parsing to include any existing modifier. Prevent throwing an error on parsing bad roll. Export some more types.
1 parent 930ca41 commit c0850a9

File tree

98 files changed

+5627
-5523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+5627
-5523
lines changed

.vscode/launch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "chrome",
9+
"request": "launch",
10+
"name": "Karma Tests",
11+
"sourceMaps": true,
12+
"webRoot": "${workspaceRoot}",
13+
"url": "http://localhost:9876/debug.html",
14+
// "runtimeArgs": [
15+
// "--headless"
16+
// ],
17+
"pathMapping": {
18+
"/": "${workspaceRoot}",
19+
"/base/": "${workspaceRoot}/"
20+
},
21+
"sourceMapPathOverrides": {
22+
"webpack:///./*": "${webRoot}/*",
23+
"webpack:///src/*": "${webRoot}/*",
24+
"webpack:///*": "*",
25+
"webpack:///./~/*": "${webRoot}/node_modules/*",
26+
"meteor://💻app/*": "${webRoot}/*"
27+
}
28+
}
29+
]
30+
}

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm install dice-typescript
2121
At its simplest, the dice roller is very simple to use. Take the following example:
2222

2323
```typescript
24-
import * as Dice from "dice-typescript";
24+
import { Dice } from "dice-typescript";
2525

2626
const dice = new Dice();
2727
const result = dice.roll("1d20").total;
@@ -57,7 +57,7 @@ In addition to the ```abs```, ```ceil```, ```floor```, ```round``` and ```sqrt``
5757
```typescript
5858
const customFunctions = new FunctionDefinitionList();
5959
customFunctions["floor"] = (interpreter: DiceInterpreter, functionNode: ExpressionNode, errors: ErrorMessage[]): number => {
60-
return Math.floor(interpreter.evaluate(functionNode.getChild(0), errors));
60+
return Math.floor(interpreter.evaluate(functionNode.getChild(0), errors));
6161
}
6262

6363
const dice = new Dice(customFunctions);
@@ -71,10 +71,10 @@ By default, the Dice library uses [random-js](https://www.npmjs.com/package/rand
7171

7272
```typescript
7373
export class CustomRandom implements RandomProvider {
74-
numberBetween(min: number, max: number) {
75-
return 4; // chosen by fair dice roll.
76-
// guaranteed to be random.
77-
}
74+
numberBetween(min: number, max: number) {
75+
return 4; // chosen by fair dice roll.
76+
// guaranteed to be random.
77+
}
7878
}
7979

8080
const dice = new Dice(null, new CustomRandom());
@@ -89,7 +89,7 @@ The dice rolling syntax is based on the system used by Roll20, a detailed explan
8989
In addition to the above syntax rules, some slightly more complicated variations are available. For example, you can roll a variable number of dice using an expression similar to the following:
9090

9191
```dice
92-
(4d4)d20
92+
(4d4)d20
9393
```
9494

9595
##### Conditional Operators
@@ -101,7 +101,7 @@ As per the Roll20 syntax, you can use conditional operators, such as in ```4d20>
101101
Sometimes it is necessary to roll complex groups of dice that aren't supported by the basic syntax. For example, rolling a saving throw at disadvantage for 10 creatures. For this, you can use the group repeater modifier, which works like this:
102102

103103
```dice
104-
{2d20kl...10}>=14
104+
{2d20kl...10}>=14
105105
```
106106

107107
The above will roll 10 disadvantaged saving throws, reporting successes for those that break DC14.
@@ -111,7 +111,7 @@ The above will roll 10 disadvantaged saving throws, reporting successes for thos
111111
Using the allowed syntax, it is possible to request a fractional number of dice to be rolled. Take the following example:
112112

113113
```dice
114-
(2 / 5)d6
114+
(2 / 5)d6
115115
```
116116

117117
In this instance, the number of dice to be rolled will be rounded to the nearest integer (2.5 gets rounded up to 3).

karma.conf.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,52 @@ const watching = process.env.npm_lifecycle_script.indexOf("--single-run") === -1
44
console.log("Watching: " + watching);
55

66
module.exports = function (config) {
7-
config.set({
8-
browserNoActivityTimeout: 20000,
9-
frameworks: ["jasmine", "karma-typescript"],
10-
files: [
11-
{ pattern: "spec/**/*.ts" },
12-
{ pattern: "src/**/*.ts" },
13-
],
14-
preprocessors: {
15-
"**/*.ts": ["karma-typescript"],
16-
},
17-
reporters: ["progress", "karma-typescript"],
18-
browsers: ["Chrome"],
19-
plugins: [
20-
"karma-chrome-launcher",
21-
"karma-jasmine",
22-
"karma-typescript"
23-
],
24-
customLaunchers: {
25-
chromeTravisCi: {
26-
base: "Chrome",
27-
flags: ["--no-sandbox"]
28-
}
29-
},
30-
karmaTypescriptConfig: {
31-
coverageOptions: {
32-
instrumentation: true
33-
},
34-
reports: {
35-
lcovonly: {
36-
directory: "coverage",
37-
filename: "lcov.info",
38-
subdirectory: "lcov"
39-
}
40-
}
7+
config.set({
8+
browserNoActivityTimeout: 20000,
9+
frameworks: ["jasmine", "karma-typescript"],
10+
files: [
11+
{ pattern: "spec/**/*.ts" },
12+
{ pattern: "src/**/*.ts" },
13+
],
14+
preprocessors: {
15+
"**/*.ts": ["karma-typescript"],
16+
},
17+
reporters: ["progress", "karma-typescript"],
18+
browsers: ["chromeDebugging"],
19+
plugins: [
20+
"karma-chrome-launcher",
21+
"karma-jasmine",
22+
"karma-typescript"
23+
],
24+
customLaunchers: {
25+
chromeDebugging: {
26+
base: 'Chrome',
27+
flags: [ '--remote-debugging-port=9333' ]
28+
},
29+
chromeTravisCi: {
30+
base: "Chrome",
31+
flags: ["--no-sandbox"]
32+
}
33+
},
34+
karmaTypescriptConfig: {
35+
coverageOptions: {
36+
instrumentation: true
37+
},
38+
reports: {
39+
lcovonly: {
40+
directory: "coverage",
41+
filename: "lcov.info",
42+
subdirectory: "lcov"
4143
}
42-
});
43-
44-
if (watching) {
45-
config.karmaTypescriptConfig.coverageOptions.instrumentation = false;
44+
}
4645
}
46+
});
4747

48-
if (process.env.TRAVIS) {
49-
config.browsers = ["chromeTravisCi"];
50-
}
48+
if (watching) {
49+
config.karmaTypescriptConfig.coverageOptions.instrumentation = false;
50+
}
51+
52+
if (process.env.TRAVIS) {
53+
config.browsers = ["chromeTravisCi"];
54+
}
5155
};

0 commit comments

Comments
 (0)