@tombell/4ad 1.0.0 → 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 CHANGED
@@ -1 +1,40 @@
1
- # 4ad.js
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
@@ -1,7 +1,7 @@
1
1
  export declare function parse(notation: string): {
2
2
  count: number;
3
3
  sides: number;
4
- modSign: string;
4
+ modSign: string | undefined;
5
5
  modValue: number;
6
6
  };
7
7
  export default function roll(notation: string): {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tombell/4ad",
3
- "version": "1.0.0",
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",
@@ -17,22 +17,22 @@
17
17
  "dist/"
18
18
  ],
19
19
  "scripts": {
20
- "build": "bunx tsc -p tsconfig.build.json",
21
- "lint": "bunx eslint",
22
20
  "test": "bun test",
23
21
  "coverage": "bun test --coverage",
24
- "prepublishOnly": "rm -fr dist/ && bun run build"
22
+ "check": "bunx prettier --check .",
23
+ "lint": "bunx eslint",
24
+ "build": "bunx tsc -p tsconfig.build.json",
25
+ "prepublishOnly": "bun run build"
25
26
  },
26
27
  "devDependencies": {
27
- "@eslint/js": "^9.27.0",
28
- "@trivago/prettier-plugin-sort-imports": "^5.2.2",
29
- "@types/bun": "latest",
30
- "eslint": "^9.27.0",
31
- "eslint-config-prettier": "^10.1.5",
32
- "eslint-plugin-prettier": "^5.4.0",
33
- "jiti": "^2.4.2",
34
- "prettier": "^3.5.3",
35
- "typescript": "^5.8.3",
36
- "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"
37
37
  }
38
38
  }