@dicelette/core 1.0.0 → 1.0.2

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,2 +1,214 @@
1
- # core
2
- Core function for roll and template
1
+ # @Core
2
+
3
+ The core module for Dicelette, contains :
4
+ - The dice function (that parse the string into a Dice Parser and send the result in a good message) ;
5
+ - The verification of the template
6
+
7
+ The two are used in the bot and documentation.
8
+
9
+ # Type alias
10
+ - **Sign**: `"+" | "-" | "*" | "/" | "%" | "^" | "**";`
11
+ - **Statistic** : `{ [name: string]: { combinaison?: string; max?: number; min?: number; } }` :
12
+ - **name**: `string` : The name of the statistic
13
+ - **combinaison**: `string` : A combinaison between multiple/other statistic, formula... (ex: `constitution+2`). Can't coexist with min & max.
14
+ - **max**: `number` : The maximum value of the statistic
15
+ - **min**: `number` : The minimum value of the statistic
16
+
17
+ # Interface ([index.d.ts](core/index.d.ts))
18
+ ## Compare
19
+
20
+ - **sign**: ``"<"`` \| ``">"`` \| ``">="`` \| ``"<="`` \| ``"="`` \| ``"!="`` \| ``"=="``
21
+ - **value**: `number`
22
+
23
+ ## Critical
24
+
25
+ - `Optional` **failure**: `number`
26
+ - `Optional` **success**: `number`
27
+
28
+ ## Modifier
29
+
30
+ - **sign**: [Sign](#sign)
31
+ - **value**: `number`
32
+
33
+ ## Resultat
34
+
35
+ - `Optional` **comment**: `string`
36
+ - `Optional` **compare**: [`Compare`](#compare)
37
+ - **dice**: `string`
38
+ - `Optional` **modifier**: [`Modifier`](#modifier)
39
+ - **result**: `string`
40
+
41
+ ## Statistical Template
42
+ ### Example
43
+
44
+ ```ts
45
+ diceType: 1d20+{{$}}>=20
46
+ comparator: {
47
+ sign: ">="
48
+ value: 20
49
+ formula: +$
50
+ }
51
+ The dice throw will be 1d20 + statistique that must be >= 20
52
+ ```
53
+
54
+ ```ts
55
+ diceType: 1d20<=$
56
+ The dice throw will be 1d20 that must be <= statistique
57
+ ```
58
+
59
+ ### Properties
60
+
61
+ - `Optional` **charName**: `boolean`
62
+ Allow to force the user to choose a name for them characters
63
+
64
+ - `Optional` **critical**: [`Critical`](#critical)
65
+ How the success/echec will be done
66
+
67
+ - `Optional` **damage**: `{ [name: string]: string }`
68
+ Special dice for damage
69
+
70
+ - `Optional` **diceType**: `string`
71
+ A die type in the notation supported by the bot. [See documentation for syntaxe](https://dicelette.github.io/en/docs/model/register).
72
+
73
+ - `Optional` **statistics**: [`Statistic`](#statistic-type)
74
+
75
+ - `Optional` **total**: `number`
76
+ A total can be set, it allows to calculate the total value of a future register member
77
+ If the sum of the value > total, the bot will send a message to the user to inform him that the total is exceeded and an error will be thrown
78
+ Note: Statistic that have a formula will be ignored from the total
79
+
80
+ # Modules
81
+ ## Dice
82
+
83
+ ### Variables
84
+ - `const` **COMMENT_REGEX**: `RegExp`
85
+
86
+ ### Functions
87
+ #### **calculator**(`sign`, `value`, `total`): `number`
88
+ Evaluate a formula and replace "^" by "**" if any
89
+
90
+ | Name | Type |
91
+ | :------ | :------ |
92
+ | `sign` | [`Sign`](#sign) |
93
+ | `value` | `number` |
94
+ | `total` | `number` |
95
+
96
+ #### **roll**(`dice`): [`Resultat`](#resultat) `| undefined`
97
+ Parse the string provided and turn it as a readable dice for dice parser
98
+
99
+ | Name | Type | Description |
100
+ | :------ | :------ | :------ |
101
+ | `dice` | `string` | {string} |
102
+
103
+
104
+ ## Utils
105
+ ### **cleanedDice**(`dice`): `string`
106
+
107
+ Replace the ++ +- -- by their proper value:
108
+ - `++` = `+`
109
+ - `+-` = `-`
110
+ - `--` = `+`
111
+
112
+ | Name | Type | Description |
113
+ | :------ | :------ | :------ |
114
+ | `dice` | `string` | {string} |
115
+
116
+ ### **escapeRegex**(`string`): `string`
117
+ Escape regex string
118
+
119
+ | Name | Type | Description |
120
+ | :------ | :------ | :------ |
121
+ | `string` | `string` | {string} |
122
+
123
+ ### **generateStatsDice**(`originalDice`, `stats?`): `string`
124
+
125
+ Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`
126
+
127
+ | Name | Type | Description |
128
+ | :------ | :------ | :------ |
129
+ | `originalDice` | `string` | {dice} |
130
+ | `stats?` | `Object` | {[name: string]: number} |
131
+
132
+ ### **replaceFormulaInDice**(`dice`, `stats`): `string`
133
+
134
+ Replace the {{}} in the dice string and evaluate the interior if any
135
+
136
+ | Name | Type | Description |
137
+ | :------ | :------ | :------ |
138
+ | `dice` | `string` | {string} |
139
+
140
+
141
+ ## Verify Template
142
+ ### **diceRandomParse**(`value`, `template`): `string`
143
+
144
+ Generate a random dice and remove the formula (+ evaluate it)
145
+ Used for diceDamage only
146
+
147
+ | Name | Type | Description |
148
+ | :------ | :------ | :------ |
149
+ | `value` | `string` | {string} |
150
+ | `template` | [`StatisticalTemplate`](#statistical-template) | {StatisticalTemplate} |
151
+
152
+ ### **diceTypeRandomParse**(`dice`, `template`): `string`
153
+ | Name | Type | Description |
154
+ | :------ | :------ | :------ |
155
+ | `dice` | `string` | {string} |
156
+ | `template` | [`StatisticalTemplate`](#statistical-template) | {StatisticalTemplate} |
157
+
158
+ ### **evalCombinaison**(`combinaison`, `stats`): `Object`
159
+ Random the combinaison and evaluate it to check if everything is valid
160
+
161
+ | Name | Type | Description |
162
+ | :------ | :------ | :------ |
163
+ | `combinaison` | `Object` | {[name: string]: string} |
164
+ | `stats` | `Object` | {[name: string]: string\|number} |
165
+
166
+ ### **evalOneCombinaison**(`combinaison`, `stats`): `any`
167
+
168
+ Evaluate one selected combinaison
169
+
170
+ | Name | Type | Description |
171
+ | :------ | :------ | :------ |
172
+ | `combinaison` | `string` | {string} |
173
+ | `stats` | `Object` | {[name: string]: string\|number} |
174
+
175
+ ### **evalStatsDice**(`testDice`, `stats?`): `string`
176
+
177
+ Verify if the provided dice work with random value
178
+
179
+ | Name | Type | Description |
180
+ | :------ | :------ | :------ |
181
+ | `testDice` | `string` | {string} |
182
+ | `stats?` | `Object` | {[name: string]: number} |
183
+
184
+ ### **generateRandomStat**(`total?`, `max?`, `min?`): `number`
185
+
186
+ | Name | Type | Default value |
187
+ | :------ | :------ | :------ |
188
+ | `total` | `undefined` \| `number` | `100` |
189
+ | `max?` | `number` | `undefined` |
190
+ | `min?` | `number` | `undefined` |
191
+
192
+ ### **testCombinaison**(`template`): `void`
193
+
194
+ Test all combinaison with generated random value
195
+
196
+ | Name | Type |
197
+ | :------ | :------ |
198
+ | `template` | [`StatisticalTemplate`](#statistical-template) |
199
+
200
+ ### **testDamageRoll**(`template`): `void`
201
+
202
+ Test each damage roll from the template.damage
203
+
204
+ | Name | Type |
205
+ | :------ | :------ |
206
+ | `template` | [`StatisticalTemplate`](#statistical-template) |
207
+
208
+ ### **verifyTemplateValue**(`template`): [`StatisticalTemplate`](#statistical-template)
209
+
210
+ Parse the provided JSON and verify each field to check if everything could work when rolling
211
+
212
+ | Name | Type |
213
+ | :------ | :------ |
214
+ | `template` | `any` |
package/core/index.d.ts CHANGED
@@ -29,18 +29,10 @@ export type Statistic = {
29
29
 
30
30
  /**
31
31
  * @example
32
- * diceType: 1d20
33
- * comparator: {
34
- * sign: ">="
35
- * value: 20
36
- * formula: +$
37
- * }
32
+ * diceType: 1d20+$>=20
38
33
  * The dice throw will be 1d20 + statistique that must be >= 20
39
34
  * @example
40
- * diceType: 1d20
41
- * comparator: {
42
- * sign: "<="
43
- * }
35
+ * diceType: 1d20<=$
44
36
  * The dice throw will be 1d20 that must be <= statistique
45
37
  */
46
38
  export interface StatisticalTemplate {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dicelette/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Core library for the Dicelette Discord bot",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,6 +27,7 @@
27
27
  "remove-accents": "^0.5.0",
28
28
  "ts-dedent": "^2.2.0"
29
29
  },
30
+ "devDependencies": {},
30
31
  "scripts": {
31
32
  "test": "jest"
32
33
  }
@@ -1,5 +1,5 @@
1
1
  // FILEPATH: /c:/Users/simonettili/Documents/Github/discord-dicelette/src/utils/verify_template.test.ts
2
- import { StatisticalTemplate } from "../core/interface";
2
+ import { StatisticalTemplate } from "../core/";
3
3
  import { generateStatsDice, replaceFormulaInDice } from "../core/utils";
4
4
  import { diceRandomParse,evalCombinaison, generateRandomStat,testCombinaison, testDamageRoll, verifyTemplateValue } from "../core/verify_template";
5
5