smath 1.0.2 → 1.1.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/dist/index.js CHANGED
@@ -1,18 +1,34 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Polate"), exports);
18
- __exportStar(require("./SMath"), exports);
3
+ exports.SMath = void 0;
4
+ var SMath = (function () {
5
+ function SMath() {
6
+ }
7
+ SMath.clamp = function (n, min, max) {
8
+ if (n < min) {
9
+ return min;
10
+ }
11
+ if (n > max) {
12
+ return max;
13
+ }
14
+ return n;
15
+ };
16
+ SMath.approx = function (a, b, epsilon) {
17
+ if (epsilon === void 0) { epsilon = 1e-6; }
18
+ return a - b < epsilon && b - a < epsilon;
19
+ };
20
+ SMath.normalize = function (n, min, max) {
21
+ if (min === max) {
22
+ return 0;
23
+ }
24
+ return (n - min) / (max - min);
25
+ };
26
+ SMath.expand = function (n, min, max) {
27
+ return (max - min) * n + min;
28
+ };
29
+ SMath.translate = function (n, min1, max1, min2, max2) {
30
+ return this.expand(this.normalize(n, min1, max1), min2, max2);
31
+ };
32
+ return SMath;
33
+ }());
34
+ exports.SMath = SMath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smath",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Small math function library",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -4,5 +4,74 @@
4
4
  *
5
5
  * Exports the public-facing API for `smath`
6
6
  */
7
- export * from './Polate';
8
- export * from './SMath';
7
+ /**
8
+ * Contains a small math function library including
9
+ * useful interpolation and extrapolation functions.
10
+ */
11
+ export declare abstract class SMath {
12
+ /**
13
+ * Clamp a number within a range.
14
+ * @param n The number to clamp
15
+ * @param min The minimum value of the range
16
+ * @param max The maximum value of the range
17
+ * @returns A clamped number
18
+ * @example
19
+ * ```js
20
+ * const n1 = SMath.clamp(5, 0, 10), // 5
21
+ * n2 = SMath.clamp(-2, 0, 10); // 0
22
+ * ```
23
+ */
24
+ static clamp(n: number, min: number, max: number): number;
25
+ /**
26
+ * Check if two numbers are approximately equal with a maximum abolute error.
27
+ * @param a Any number
28
+ * @param b Any number
29
+ * @param epsilon Maximum absolute error
30
+ * @returns True if `a` is approximately `b`
31
+ * @example
32
+ * ```js
33
+ * const b1 = SMath.approx(1 / 3, 0.33, 1e-6), // false
34
+ * b2 = SMath.approx(1 / 3, 0.33, 1e-2); // true
35
+ * ```
36
+ */
37
+ static approx(a: number, b: number, epsilon?: number): boolean;
38
+ /**
39
+ * Normalize the number `n` from the range `min, max` to the range `0, 1`
40
+ * @param n The number to normalize
41
+ * @param min The minimum value in the range
42
+ * @param max The maximum value in the range
43
+ * @returns A normalized value
44
+ * @example
45
+ * ```js
46
+ * const y = SMath.normalize(18, 9, 99); // 0.1
47
+ * ```
48
+ */
49
+ static normalize(n: number, min: number, max: number): number;
50
+ /**
51
+ * Expand a normalized number `n` to the range `min, max`
52
+ * @param n A normalized number
53
+ * @param min The minimum value in the range
54
+ * @param max The maximum value in the range
55
+ * @returns A value within the number range
56
+ * @example
57
+ * ```js
58
+ * const y = SMath.expand(0.25, 4, 6); // 4.5
59
+ * ```
60
+ */
61
+ static expand(n: number, min: number, max: number): number;
62
+ /**
63
+ * Translate a number `n` from the range `min1, max1` to the range `min2, max2`
64
+ * @param n The number to translate
65
+ * @param min1 The minimum value from the initial range
66
+ * @param max1 The maximum value from the initial range
67
+ * @param min2 The minimum value for the final range
68
+ * @param max2 The maximum value for the final range
69
+ * @returns A translated number in the final range
70
+ * @example
71
+ * ```js
72
+ * const C = 20,
73
+ * F = SMath.translate(C, 0, 100, 32, 212); // 68
74
+ * ```
75
+ */
76
+ static translate(n: number, min1: number, max1: number, min2: number, max2: number): number;
77
+ }
package/dist/Polate.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Polate = void 0;
4
- var Polate = (function () {
5
- function Polate() {
6
- }
7
- Polate.normalize = function (n, min, max) {
8
- if (min === max) {
9
- return 0;
10
- }
11
- return (n - min) / (max - min);
12
- };
13
- Polate.expand = function (n, min, max) {
14
- return (max - min) * n + min;
15
- };
16
- Polate.translate = function (n, min1, max1, min2, max2) {
17
- return this.expand(this.normalize(n, min1, max1), min2, max2);
18
- };
19
- return Polate;
20
- }());
21
- exports.Polate = Polate;
package/dist/SMath.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SMath = void 0;
4
- var SMath = (function () {
5
- function SMath() {
6
- }
7
- SMath.isNumber = function (n) {
8
- return typeof n === 'number' && n !== Infinity && n !== -Infinity;
9
- };
10
- SMath.clamp = function (n, min, max) {
11
- if (n < min) {
12
- return min;
13
- }
14
- if (n > max) {
15
- return max;
16
- }
17
- return n;
18
- };
19
- SMath.approx = function (a, b, epsilon) {
20
- if (epsilon === void 0) { epsilon = 1e-6; }
21
- return a - b < epsilon && b - a < epsilon;
22
- };
23
- SMath.round = function (n, d) {
24
- return Math.round(n * Math.pow(10, d)) / (Math.pow(10, d));
25
- };
26
- return SMath;
27
- }());
28
- exports.SMath = SMath;
package/types/Polate.d.ts DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * Contains useful interpolation and extrapolation functions.
3
- */
4
- export declare abstract class Polate {
5
- /**
6
- * Normalize the number `n` from the range `min, max` to the range `0, 1`
7
- * @param n The number to normalize
8
- * @param min The minimum value in the range
9
- * @param max The maximum value in the range
10
- * @returns A normalized value
11
- * @example
12
- * ```js
13
- * const y = Polate.normalize(18, 9, 99); // 0.1
14
- * ```
15
- */
16
- static normalize(n: number, min: number, max: number): number;
17
- /**
18
- * Expand a normalized number `n` to the range `min, max`
19
- * @param n A normalized number
20
- * @param min The minimum value in the range
21
- * @param max The maximum value in the range
22
- * @returns A value within the number range
23
- * @example
24
- * ```js
25
- * const y = Polate.expand(0.25, 4, 6); // 4.5
26
- * ```
27
- */
28
- static expand(n: number, min: number, max: number): number;
29
- /**
30
- * Translate a number `n` from the range `min1, max1` to the range `min2, max2`
31
- * @param n The number to translate
32
- * @param min1 The minimum value from the initial range
33
- * @param max1 The maximum value from the initial range
34
- * @param min2 The minimum value for the final range
35
- * @param max2 The maximum value for the final range
36
- * @returns A translated number in the final range
37
- * @example
38
- * ```js
39
- * const C = 20,
40
- * F = Polate.translate(C, 0, 100, 32, 212); // 68
41
- * ```
42
- */
43
- static translate(n: number, min1: number, max1: number, min2: number, max2: number): number;
44
- }
package/types/SMath.d.ts DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * Contains a small math function library.
3
- */
4
- export declare abstract class SMath {
5
- /**
6
- * Determine if a value is numeric.
7
- * @param n Any value to check
8
- * @returns True if `n` is a number
9
- * @example
10
- * ```js
11
- * const b1 = SMath.isNumber(2), // true
12
- * b2 = SMath.isNumber('2'); // false
13
- * ```
14
- */
15
- static isNumber(n: any): boolean;
16
- /**
17
- * Clamp a number within a range.
18
- * @param n The number to clamp
19
- * @param min The minimum value of the range
20
- * @param max The maximum value of the range
21
- * @returns A clamped number
22
- * @example
23
- * ```js
24
- * const n1 = SMath.clamp(5, 0, 10), // 5
25
- * n2 = SMath.clamp(-2, 0, 10); // 0
26
- * ```
27
- */
28
- static clamp(n: number, min: number, max: number): number;
29
- /**
30
- * Check if two numbers are approximately equal with a maximum abolute error.
31
- * @param a Any number
32
- * @param b Any number
33
- * @param epsilon Maximum absolute error
34
- * @returns True if `a` is approximately `b`
35
- * @example
36
- * ```js
37
- * const b1 = SMath.approx(1 / 3, 0.33, 1e-6), // false
38
- * b2 = SMath.approx(1 / 3, 0.33, 1e-2); // true
39
- * ```
40
- */
41
- static approx(a: number, b: number, epsilon?: number): boolean;
42
- /**
43
- * Round a number to any number of decimal places.
44
- * @param n The number to round
45
- * @param d The number of places on the right side of the decimal
46
- * @returns The rounded number
47
- * @example
48
- * ```js
49
- * const pi = SMath.round(3.1416, 2); // 3.14
50
- * ```
51
- */
52
- static round(n: number, d: number): number;
53
- }