@tombell/4ad 0.0.4 → 1.0.1
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 +40 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
-
# 4ad
|
|
1
|
+
# @tombell/4ad
|
|
2
|
+
|
|
3
|
+
A library for parsing simple dice rolling syntax, with basic modifier support.
|
|
4
|
+
|
|
5
|
+
For example `d6`, `2d20`, and `2d20+2`.
|
|
6
|
+
|
|
7
|
+
Currently only very basic syntax is supported: `{count}d{sides}{modifier}`. Where the following:
|
|
8
|
+
|
|
9
|
+
- `count` is optional
|
|
10
|
+
- `sides` is required
|
|
11
|
+
- `modifier` is an optional positive or negative number (e.g. `+2`, or `-10`)
|
|
12
|
+
|
|
13
|
+
# Usage
|
|
14
|
+
|
|
15
|
+
You can import the `roll` function if you would like to get the result of a specific dice syntax.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import roll from "@tombell/4ad";
|
|
19
|
+
|
|
20
|
+
const { total, rolls, modifier } = roll("2d6+2");
|
|
21
|
+
|
|
22
|
+
// total will the the total of all the rolls +2
|
|
23
|
+
// rolls will be an array of each individual roll
|
|
24
|
+
// modifier will be the positive or negative modifier that will be added
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The `parse` function is also exported if you would like to handle the "rolling" yourself.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { parse } from "@tombell/4ad";
|
|
31
|
+
|
|
32
|
+
count { count, sides, modSign, modValue } = parse("2d6+2");
|
|
33
|
+
|
|
34
|
+
// count will be 2
|
|
35
|
+
// sides will be 6
|
|
36
|
+
// modSign will be "+"
|
|
37
|
+
// modValue will be 2
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The `modSign` will be `undefined` if no modifier is specified, and `modValue` will be 0.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export function parse(notation) {
|
|
|
6
6
|
}
|
|
7
7
|
const count = parseInt(match[1], 10) || 1;
|
|
8
8
|
const sides = parseInt(match[2], 10);
|
|
9
|
-
const modSign = match[3];
|
|
9
|
+
const modSign = match[3] || undefined;
|
|
10
10
|
const modValue = match[4] ? parseInt(match[4], 10) : 0;
|
|
11
11
|
return { count, sides, modSign, modValue };
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tombell/4ad",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A simple library to parse dice syntax for Four Against Darkness games.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dice",
|
|
7
|
+
"die",
|
|
7
8
|
"4ad",
|
|
8
9
|
"four against darkness"
|
|
9
10
|
],
|
|
@@ -16,22 +17,22 @@
|
|
|
16
17
|
"dist/"
|
|
17
18
|
],
|
|
18
19
|
"scripts": {
|
|
19
|
-
"build": "bunx tsc -p tsconfig.build.json",
|
|
20
|
-
"lint": "bunx eslint",
|
|
21
20
|
"test": "bun test",
|
|
22
21
|
"coverage": "bun test --coverage",
|
|
23
|
-
"
|
|
22
|
+
"check": "bunx prettier --check .",
|
|
23
|
+
"lint": "bunx eslint",
|
|
24
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
25
|
+
"prepublishOnly": "bun run build"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@eslint/js": "^9.
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"eslint": "^
|
|
30
|
-
"eslint-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"typescript": "^
|
|
35
|
-
"typescript-eslint": "^8.33.0"
|
|
28
|
+
"@eslint/js": "^9.37.0",
|
|
29
|
+
"@types/bun": "1.2.23",
|
|
30
|
+
"eslint": "^9.37.0",
|
|
31
|
+
"eslint-config-prettier": "^10.1.8",
|
|
32
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
33
|
+
"jiti": "^2.6.1",
|
|
34
|
+
"prettier": "^3.6.2",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"typescript-eslint": "^8.45.0"
|
|
36
37
|
}
|
|
37
38
|
}
|