@tstdl/base 0.78.0-beta76 → 0.78.0-beta78

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.78.0-beta76",
3
+ "version": "0.78.0-beta78",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/utils/math.d.ts CHANGED
@@ -1,38 +1,44 @@
1
1
  /**
2
- * generate a random value in interval [0, 1)
2
+ * Generates a random value in interval [0, 1).
3
3
  */
4
4
  export declare type RandomNumberGenerator = () => number;
5
5
  /**
6
- * generate a random float in interval [min, max)
6
+ * Generate a random float in interval [min, max).
7
7
  * @param min minimum value
8
8
  * @param max maximum value
9
- * @param generator random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1)
9
+ * @param generator Random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1).
10
10
  * @returns random number (float)
11
11
  */
12
12
  export declare function randomFloat(min: number, max: number, generator?: RandomNumberGenerator): number;
13
13
  /**
14
- * generate a random integer in interval [min, max]
14
+ * Generate a random integer in interval [min, max].
15
15
  * @param min minimum value
16
16
  * @param max maximum value
17
- * @param generator random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1)
17
+ * @param generator random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1)
18
18
  * @returns random number (integer)
19
19
  */
20
20
  export declare function randomInt(min: number, max: number, generator?: RandomNumberGenerator): number;
21
21
  /**
22
- * calculate the average of all values
22
+ * Calculate the sum of all values.
23
+ * @param values values to sum
24
+ * @returns sum
25
+ */
26
+ export declare function sum(values: number[]): number;
27
+ /**
28
+ * Calculate the average of all values.
23
29
  * @param values values to average
24
30
  * @returns average
25
31
  */
26
32
  export declare function average(values: number[]): number;
27
33
  /**
28
- * round number to specified decimals
34
+ * Round number to specified decimals.
29
35
  * @param value value to round
30
36
  * @param decimals number of decimals to round to
31
37
  * @returns rounded number
32
38
  */
33
39
  export declare function round(value: number, decimals: number): number;
34
40
  /**
35
- * linearly interpolate the interval [fromLow, fromHigh] into [toLow, toHigh]
41
+ * Linearly interpolate the interval [fromLow, fromHigh] into [toLow, toHigh].
36
42
  * @param value value to interpolate
37
43
  * @param fromLow source lower bound
38
44
  * @param fromHigh source upper bound
@@ -42,7 +48,7 @@ export declare function round(value: number, decimals: number): number;
42
48
  */
43
49
  export declare function linearInterpolate(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number;
44
50
  /**
45
- * linearly interpolate [0, 1] into an interval
51
+ * Linearly interpolate [0, 1] into an interval.
46
52
  * @param value value to interpolate in interval [0, 1]
47
53
  * @param low lower bound
48
54
  * @param high upper bound
@@ -50,10 +56,19 @@ export declare function linearInterpolate(value: number, fromLow: number, fromHi
50
56
  */
51
57
  export declare function linearInterpolateFloat(value: number, low: number, high: number): number;
52
58
  /**
53
- * clamps a number between two numbers
59
+ * Clamps a number between two numbers.
54
60
  * @param value value to clamp
55
61
  * @param minimum lower bound
56
62
  * @param maximum upper bound
57
63
  * @returns clamped value
58
64
  */
59
65
  export declare function clamp(value: number, minimum: number, maximum: number): number;
66
+ /**
67
+ * Calculates the nth-root of a number.
68
+ *
69
+ * Warning: negative values are handled as if they were positive but returned with an negative sign.
70
+ * @param base base
71
+ * @param root root
72
+ * @returns nth-root of base
73
+ */
74
+ export declare function nthRoot(base: number, root: number): number;
package/utils/math.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clamp = exports.linearInterpolateFloat = exports.linearInterpolate = exports.round = exports.average = exports.randomInt = exports.randomFloat = void 0;
3
+ exports.nthRoot = exports.clamp = exports.linearInterpolateFloat = exports.linearInterpolate = exports.round = exports.average = exports.sum = exports.randomInt = exports.randomFloat = void 0;
4
4
  const defaultRandomNumberGenerator = () => Math.random();
5
5
  /**
6
- * generate a random float in interval [min, max)
6
+ * Generate a random float in interval [min, max).
7
7
  * @param min minimum value
8
8
  * @param max maximum value
9
- * @param generator random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1)
9
+ * @param generator Random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1).
10
10
  * @returns random number (float)
11
11
  */
12
12
  function randomFloat(min, max, generator = defaultRandomNumberGenerator) {
@@ -14,10 +14,10 @@ function randomFloat(min, max, generator = defaultRandomNumberGenerator) {
14
14
  }
15
15
  exports.randomFloat = randomFloat;
16
16
  /**
17
- * generate a random integer in interval [min, max]
17
+ * Generate a random integer in interval [min, max].
18
18
  * @param min minimum value
19
19
  * @param max maximum value
20
- * @param generator random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1)
20
+ * @param generator random number generator to use, defaults to `Math.random`. Must return a number in interval [0, 1)
21
21
  * @returns random number (integer)
22
22
  */
23
23
  function randomInt(min, max, generator = defaultRandomNumberGenerator) {
@@ -25,17 +25,25 @@ function randomInt(min, max, generator = defaultRandomNumberGenerator) {
25
25
  }
26
26
  exports.randomInt = randomInt;
27
27
  /**
28
- * calculate the average of all values
28
+ * Calculate the sum of all values.
29
+ * @param values values to sum
30
+ * @returns sum
31
+ */
32
+ function sum(values) {
33
+ return values.reduce((previous, current) => previous + current, 0);
34
+ }
35
+ exports.sum = sum;
36
+ /**
37
+ * Calculate the average of all values.
29
38
  * @param values values to average
30
39
  * @returns average
31
40
  */
32
41
  function average(values) {
33
- const total = values.reduce((previous, current) => previous + current, 0);
34
- return total / values.length;
42
+ return sum(values) / values.length;
35
43
  }
36
44
  exports.average = average;
37
45
  /**
38
- * round number to specified decimals
46
+ * Round number to specified decimals.
39
47
  * @param value value to round
40
48
  * @param decimals number of decimals to round to
41
49
  * @returns rounded number
@@ -46,7 +54,7 @@ function round(value, decimals) {
46
54
  }
47
55
  exports.round = round;
48
56
  /**
49
- * linearly interpolate the interval [fromLow, fromHigh] into [toLow, toHigh]
57
+ * Linearly interpolate the interval [fromLow, fromHigh] into [toLow, toHigh].
50
58
  * @param value value to interpolate
51
59
  * @param fromLow source lower bound
52
60
  * @param fromHigh source upper bound
@@ -59,7 +67,7 @@ function linearInterpolate(value, fromLow, fromHigh, toLow, toHigh) {
59
67
  }
60
68
  exports.linearInterpolate = linearInterpolate;
61
69
  /**
62
- * linearly interpolate [0, 1] into an interval
70
+ * Linearly interpolate [0, 1] into an interval.
63
71
  * @param value value to interpolate in interval [0, 1]
64
72
  * @param low lower bound
65
73
  * @param high upper bound
@@ -70,7 +78,7 @@ function linearInterpolateFloat(value, low, high) {
70
78
  }
71
79
  exports.linearInterpolateFloat = linearInterpolateFloat;
72
80
  /**
73
- * clamps a number between two numbers
81
+ * Clamps a number between two numbers.
74
82
  * @param value value to clamp
75
83
  * @param minimum lower bound
76
84
  * @param maximum upper bound
@@ -80,4 +88,16 @@ function clamp(value, minimum, maximum) {
80
88
  return Math.min(maximum, Math.max(minimum, value));
81
89
  }
82
90
  exports.clamp = clamp;
91
+ /**
92
+ * Calculates the nth-root of a number.
93
+ *
94
+ * Warning: negative values are handled as if they were positive but returned with an negative sign.
95
+ * @param base base
96
+ * @param root root
97
+ * @returns nth-root of base
98
+ */
99
+ function nthRoot(base, root) {
100
+ return (base < 0) ? -((-base) ** (1 / root)) : (base ** (1 / root));
101
+ }
102
+ exports.nthRoot = nthRoot;
83
103
  //# sourceMappingURL=math.js.map
package/utils/math.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.js","sourceRoot":"","sources":["../../source/utils/math.ts"],"names":[],"mappings":";;;AAKA,MAAM,4BAA4B,GAA0B,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;AAEhF;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,GAAW,EAAE,GAAW,EAAE,YAAmC,4BAA4B;IACnH,OAAO,sBAAsB,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACvD,CAAC;AAFD,kCAEC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,C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