@dicelette/core 1.20.0 → 1.21.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 +140 -146
- package/dist/index.d.mts +108 -93
- package/dist/index.d.ts +108 -93
- package/dist/index.js +320 -235
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +317 -233
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Engine } from 'random-js';
|
|
1
|
+
import { Engine, Random } from 'random-js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -24,6 +24,41 @@ declare function roll(dice: string, engine?: Engine | null): Resultat | undefine
|
|
|
24
24
|
*/
|
|
25
25
|
declare function calculator(sign: Sign, value: number, total: number): number;
|
|
26
26
|
|
|
27
|
+
declare class DiceTypeError extends Error {
|
|
28
|
+
readonly dice: string;
|
|
29
|
+
readonly cause: string | undefined;
|
|
30
|
+
readonly method: unknown;
|
|
31
|
+
constructor(dice: string, cause?: string, method?: unknown);
|
|
32
|
+
}
|
|
33
|
+
declare class FormulaError extends Error {
|
|
34
|
+
readonly formula: string;
|
|
35
|
+
readonly cause: string | undefined;
|
|
36
|
+
readonly method: unknown;
|
|
37
|
+
constructor(formula: string, cause?: string, method?: unknown);
|
|
38
|
+
}
|
|
39
|
+
declare class MaxGreater extends Error {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly value: number;
|
|
42
|
+
readonly max: number;
|
|
43
|
+
constructor(value: number, max: number);
|
|
44
|
+
}
|
|
45
|
+
declare class EmptyObjectError extends Error {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
constructor();
|
|
48
|
+
}
|
|
49
|
+
declare class TooManyDice extends Error {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
constructor();
|
|
52
|
+
}
|
|
53
|
+
declare class TooManyStats extends Error {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
constructor();
|
|
56
|
+
}
|
|
57
|
+
declare class NoStatisticsError extends Error {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
constructor();
|
|
60
|
+
}
|
|
61
|
+
|
|
27
62
|
interface Resultat {
|
|
28
63
|
/**
|
|
29
64
|
* Original dice throw
|
|
@@ -198,6 +233,61 @@ interface CustomCritical {
|
|
|
198
233
|
affectSkill?: boolean;
|
|
199
234
|
}
|
|
200
235
|
|
|
236
|
+
declare const COMMENT_REGEX: RegExp;
|
|
237
|
+
declare const SIGN_REGEX: RegExp;
|
|
238
|
+
declare const SIGN_REGEX_SPACE: RegExp;
|
|
239
|
+
declare const SYMBOL_DICE = "&";
|
|
240
|
+
declare const DETECT_CRITICAL: RegExp;
|
|
241
|
+
|
|
242
|
+
interface StatisticalSchema extends StatisticalTemplate {
|
|
243
|
+
/**
|
|
244
|
+
* Specifies the URL for the schema definition
|
|
245
|
+
* This property is optional and should contain a valid URI.
|
|
246
|
+
*/
|
|
247
|
+
$schema?: string;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Definition of the Zod schema for template data
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
declare const templateSchema: z.ZodObject<{
|
|
255
|
+
charName: z.ZodOptional<z.ZodBoolean>;
|
|
256
|
+
statistics: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
257
|
+
max: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
|
|
258
|
+
min: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
|
|
259
|
+
combinaison: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string | undefined, string>>>;
|
|
260
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
261
|
+
}, z.core.$strip>>>;
|
|
262
|
+
total: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
|
|
263
|
+
forceDistrib: z.ZodOptional<z.ZodBoolean>;
|
|
264
|
+
diceType: z.ZodOptional<z.ZodString>;
|
|
265
|
+
critical: z.ZodOptional<z.ZodPipe<z.ZodObject<{
|
|
266
|
+
success: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
267
|
+
failure: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
268
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
269
|
+
success?: string | number | undefined;
|
|
270
|
+
failure?: string | number | undefined;
|
|
271
|
+
}, {
|
|
272
|
+
success?: string | number | undefined;
|
|
273
|
+
failure?: string | number | undefined;
|
|
274
|
+
}>>>;
|
|
275
|
+
customCritical: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
276
|
+
sign: z.ZodEnum<{
|
|
277
|
+
"<": "<";
|
|
278
|
+
">": ">";
|
|
279
|
+
">=": ">=";
|
|
280
|
+
"<=": "<=";
|
|
281
|
+
"!=": "!=";
|
|
282
|
+
"==": "==";
|
|
283
|
+
}>;
|
|
284
|
+
value: z.ZodString;
|
|
285
|
+
onNaturalDice: z.ZodOptional<z.ZodBoolean>;
|
|
286
|
+
affectSkill: z.ZodOptional<z.ZodBoolean>;
|
|
287
|
+
}, z.core.$strip>>>;
|
|
288
|
+
damage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
289
|
+
}, z.core.$strip>;
|
|
290
|
+
|
|
201
291
|
/**
|
|
202
292
|
* Escape regex string
|
|
203
293
|
* @param string {string}
|
|
@@ -236,6 +326,22 @@ declare function isNumber(value: unknown): boolean;
|
|
|
236
326
|
* @returns {string} the dice with the {exp} replaced by a random value
|
|
237
327
|
*/
|
|
238
328
|
declare function replaceExpByRandom(dice: string, engine?: Engine | null): string;
|
|
329
|
+
/**
|
|
330
|
+
* Utility function to get a random integer between min and max and using the specified engine
|
|
331
|
+
* @param min {number}
|
|
332
|
+
* @param max {number}
|
|
333
|
+
* @param engine {Engine | null} Engine to use, default to nodeCrypto
|
|
334
|
+
* @param rng {Random | undefined} Random instance to use, see https://www.npmjs.com/package/random-js#usage
|
|
335
|
+
* @returns {number} Random integer between min and max
|
|
336
|
+
*/
|
|
337
|
+
declare function randomInt(min: number, max: number, engine?: Engine | null, rng?: Random): number;
|
|
338
|
+
/**
|
|
339
|
+
* Utility function that allow to get the id of an engine
|
|
340
|
+
* @param engine {unknown} Engine to identify
|
|
341
|
+
* @returns {string} Id of the engine or "unknown"
|
|
342
|
+
* @private
|
|
343
|
+
*/
|
|
344
|
+
declare function getEngineId(engine: unknown): string;
|
|
239
345
|
/**
|
|
240
346
|
* Utility function to get the engine from its name
|
|
241
347
|
* @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
|
|
@@ -243,7 +349,6 @@ declare function replaceExpByRandom(dice: string, engine?: Engine | null): strin
|
|
|
243
349
|
* @public
|
|
244
350
|
*/
|
|
245
351
|
declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
|
|
246
|
-
declare function randomInt(min: number, max: number, engine?: Engine | null): number;
|
|
247
352
|
|
|
248
353
|
/**
|
|
249
354
|
* Verify if the provided dice work with random value
|
|
@@ -303,94 +408,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
|
|
|
303
408
|
*/
|
|
304
409
|
declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
|
|
305
410
|
|
|
306
|
-
|
|
307
|
-
readonly dice: string;
|
|
308
|
-
readonly cause: string | undefined;
|
|
309
|
-
readonly method: unknown;
|
|
310
|
-
constructor(dice: string, cause?: string, method?: unknown);
|
|
311
|
-
}
|
|
312
|
-
declare class FormulaError extends Error {
|
|
313
|
-
readonly formula: string;
|
|
314
|
-
readonly cause: string | undefined;
|
|
315
|
-
readonly method: unknown;
|
|
316
|
-
constructor(formula: string, cause?: string, method?: unknown);
|
|
317
|
-
}
|
|
318
|
-
declare class MaxGreater extends Error {
|
|
319
|
-
readonly name: string;
|
|
320
|
-
readonly value: number;
|
|
321
|
-
readonly max: number;
|
|
322
|
-
constructor(value: number, max: number);
|
|
323
|
-
}
|
|
324
|
-
declare class EmptyObjectError extends Error {
|
|
325
|
-
readonly name: string;
|
|
326
|
-
constructor();
|
|
327
|
-
}
|
|
328
|
-
declare class TooManyDice extends Error {
|
|
329
|
-
readonly name: string;
|
|
330
|
-
constructor();
|
|
331
|
-
}
|
|
332
|
-
declare class TooManyStats extends Error {
|
|
333
|
-
readonly name: string;
|
|
334
|
-
constructor();
|
|
335
|
-
}
|
|
336
|
-
declare class NoStatisticsError extends Error {
|
|
337
|
-
readonly name: string;
|
|
338
|
-
constructor();
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
declare const COMMENT_REGEX: RegExp;
|
|
342
|
-
declare const SIGN_REGEX: RegExp;
|
|
343
|
-
declare const SIGN_REGEX_SPACE: RegExp;
|
|
344
|
-
declare const SYMBOL_DICE = "&";
|
|
345
|
-
declare const DETECT_CRITICAL: RegExp;
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Definition of the Zod schema for template data
|
|
349
|
-
*/
|
|
350
|
-
|
|
351
|
-
declare const templateSchema: z.ZodObject<{
|
|
352
|
-
charName: z.ZodOptional<z.ZodBoolean>;
|
|
353
|
-
statistics: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
354
|
-
max: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
|
|
355
|
-
min: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
|
|
356
|
-
combinaison: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string | undefined, string>>>;
|
|
357
|
-
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
358
|
-
}, z.core.$strip>>>;
|
|
359
|
-
total: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
|
|
360
|
-
forceDistrib: z.ZodOptional<z.ZodBoolean>;
|
|
361
|
-
diceType: z.ZodOptional<z.ZodString>;
|
|
362
|
-
critical: z.ZodOptional<z.ZodPipe<z.ZodObject<{
|
|
363
|
-
success: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
364
|
-
failure: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
365
|
-
}, z.core.$strip>, z.ZodTransform<{
|
|
366
|
-
success?: string | number | undefined;
|
|
367
|
-
failure?: string | number | undefined;
|
|
368
|
-
}, {
|
|
369
|
-
success?: string | number | undefined;
|
|
370
|
-
failure?: string | number | undefined;
|
|
371
|
-
}>>>;
|
|
372
|
-
customCritical: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
373
|
-
sign: z.ZodEnum<{
|
|
374
|
-
">=": ">=";
|
|
375
|
-
"<=": "<=";
|
|
376
|
-
"<": "<";
|
|
377
|
-
">": ">";
|
|
378
|
-
"!=": "!=";
|
|
379
|
-
"==": "==";
|
|
380
|
-
}>;
|
|
381
|
-
value: z.ZodString;
|
|
382
|
-
onNaturalDice: z.ZodOptional<z.ZodBoolean>;
|
|
383
|
-
affectSkill: z.ZodOptional<z.ZodBoolean>;
|
|
384
|
-
}, z.core.$strip>>>;
|
|
385
|
-
damage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
386
|
-
}, z.core.$strip>;
|
|
387
|
-
|
|
388
|
-
interface StatisticalSchema extends StatisticalTemplate {
|
|
389
|
-
/**
|
|
390
|
-
* Specifies the URL for the schema definition
|
|
391
|
-
* This property is optional and should contain a valid URI.
|
|
392
|
-
*/
|
|
393
|
-
$schema?: string;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
|
411
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|