@elara-services/packages 6.0.5 → 6.0.7

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/packages",
3
- "version": "6.0.5",
3
+ "version": "6.0.7",
4
4
  "description": "",
5
5
  "main": "./dist/src/index.js",
6
6
  "author": "SUPERCHIEFYT (Elara-Discord-Bots, Elara-Services)",
@@ -38,7 +38,7 @@
38
38
  "node-schedule": "2.1.1"
39
39
  },
40
40
  "dependencies": {
41
- "@elara-services/utils": "1.2.14",
41
+ "@elara-services/utils": "^1.2.31",
42
42
  "discord-api-types": "0.37.48"
43
43
  }
44
44
  }
@@ -116,7 +116,7 @@ exports.Interactions = {
116
116
  }
117
117
  return data;
118
118
  },
119
- textInput: (options = {}, row = false) => {
119
+ textInput: (options = {}, row = true) => {
120
120
  const data = {
121
121
  type: 4,
122
122
  custom_id: undefined,
@@ -14,3 +14,9 @@ export interface RandomWord {
14
14
  join: string;
15
15
  }
16
16
  export declare function randomWords(options: RandomWord): string | string[];
17
+ export interface RandomNumberOptions {
18
+ min?: number;
19
+ max?: number;
20
+ integer?: boolean;
21
+ }
22
+ export declare function randomNumber(options?: RandomNumberOptions): number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomWords = exports.randomWeight = void 0;
3
+ exports.randomNumber = exports.randomWords = exports.randomWeight = void 0;
4
4
  const utils_1 = require("@elara-services/utils");
5
5
  function randomWeight(objects) {
6
6
  const randomNumber = Math.random() * objects.reduce((agg, object) => agg + object.weight, 0);
@@ -2033,3 +2033,30 @@ function randomWords(options) {
2033
2033
  return results;
2034
2034
  }
2035
2035
  exports.randomWords = randomWords;
2036
+ function randomNumber(options) {
2037
+ const { min, max, integer } = getDefaultsForRandomNumber(options);
2038
+ if (max === min) {
2039
+ return min;
2040
+ }
2041
+ const r = Math.random() * (max - min + Number(!!integer)) + min;
2042
+ return integer ? Math.floor(r) : r;
2043
+ }
2044
+ exports.randomNumber = randomNumber;
2045
+ function getDefaultsForRandomNumber(options) {
2046
+ if (!utils_1.is.object(options)) {
2047
+ options = {};
2048
+ }
2049
+ let min = options.min || 0;
2050
+ let max = options.max || 1;
2051
+ const integer = options.integer || false;
2052
+ if (!utils_1.is.number(min, false)) {
2053
+ min = max - 1;
2054
+ }
2055
+ else if (!utils_1.is.number(max, false)) {
2056
+ max = min + 1;
2057
+ }
2058
+ if (max < min) {
2059
+ throw new Error("invalid options, max must be >= min");
2060
+ }
2061
+ return { min, max, integer };
2062
+ }