@wabot-dev/framework 0.1.0-beta.52 → 0.1.0-beta.53

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.
@@ -4,6 +4,24 @@ const DIGITS = '0123456789';
4
4
  const ALPHA_NUMERIC_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
5
5
  const ALPHA_NUMERIC_LOWER_CASE_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
6
6
  class Random {
7
+ static integer(options) {
8
+ const { min, max } = options;
9
+ if (min > max) {
10
+ throw new RangeError('min must be less than or equal to max');
11
+ }
12
+ const range = max - min + 1;
13
+ if (range <= 0) {
14
+ throw new RangeError('Range must be a positive number');
15
+ }
16
+ const byteSize = 6; // gives us up to 2^48
17
+ const maxGeneratedValue = Math.pow(2, byteSize * 8) - 1;
18
+ const maxAcceptable = maxGeneratedValue - (maxGeneratedValue % range);
19
+ let randomNumber;
20
+ do {
21
+ randomNumber = parseInt(randomBytes(byteSize).toString('hex'), 16);
22
+ } while (randomNumber >= maxAcceptable);
23
+ return min + (randomNumber % range);
24
+ }
7
25
  static slug(name, options) {
8
26
  const base = name
9
27
  .toLowerCase()
@@ -146,6 +146,10 @@ declare class Password {
146
146
  }
147
147
 
148
148
  declare class Random {
149
+ static integer(options: {
150
+ min: number;
151
+ max: number;
152
+ }): number;
149
153
  static slug(name: string, options: {
150
154
  randomLength: number;
151
155
  }): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.52",
3
+ "version": "0.1.0-beta.53",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",