smath 0.0.3 → 0.0.4

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 CHANGED
@@ -1,2 +1,5 @@
1
1
  # smath
2
- Small math function library
2
+ Small math function library
3
+
4
+ ![NPM Version](https://img.shields.io/npm/v/smath)
5
+ ![NPM Downloads](https://img.shields.io/npm/dt/smath)
package/dist/Polate.js ADDED
@@ -0,0 +1,21 @@
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 min;
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 ADDED
@@ -0,0 +1,25 @@
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';
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
+ return SMath;
24
+ }());
25
+ exports.SMath = SMath;
package/dist/index.js CHANGED
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Interpolator"), exports);
17
+ __exportStar(require("./Polate"), exports);
18
+ __exportStar(require("./SMath"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smath",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Small math function library",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -17,12 +17,27 @@
17
17
  "docs": "rm -rf docs && typedoc src",
18
18
  "prepublishOnly": "npm run build && npm run types"
19
19
  },
20
- "keywords": [],
20
+ "keywords": [
21
+ "small",
22
+ "math",
23
+ "function",
24
+ "library",
25
+ "simple",
26
+ "number",
27
+ "interpolate",
28
+ "interpolation",
29
+ "extrapolate",
30
+ "extrapolation"
31
+ ],
21
32
  "author": {
22
33
  "name": "Nicolas Ventura",
23
34
  "email": "smath@nicolasventura.com",
24
35
  "url": "https://nicolasventura.com/"
25
36
  },
37
+ "funding": {
38
+ "type": "paypal",
39
+ "url": "https://www.paypal.com/donate/?business=UM6EEKPW8GXA2&no_recurring=0&item_name=Open+source+development&currency_code=USD"
40
+ },
26
41
  "repository": {
27
42
  "type": "git",
28
43
  "url": "https://github.com/nicfv/npm",
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Contains useful interpolation functions.
2
+ * Contains useful interpolation and extrapolation functions.
3
3
  */
4
- export declare class Interpolator {
4
+ export declare class Polate {
5
5
  /**
6
6
  * Normalize the number `n` from the range `min, max` to the range `0, 1`
7
7
  * @param n The number to normalize
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Small Math function library
3
+ */
4
+ export declare 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
+ */
10
+ static isNumber(n: any): boolean;
11
+ /**
12
+ * Clamp a number within a range.
13
+ * @param n The number to clamp
14
+ * @param min The minimum value of the range
15
+ * @param max The maximum value of the range
16
+ * @returns A clamped number
17
+ */
18
+ static clamp(n: number, min: number, max: number): number;
19
+ /**
20
+ * Check if two numbers are approximately equal with a maximum abolute error.
21
+ * @param a Any number
22
+ * @param b Any number
23
+ * @param epsilon Maximum absolute error
24
+ * @returns True if `a` is approximately `b`
25
+ */
26
+ static approx(a: number, b: number, epsilon?: number): boolean;
27
+ }
package/types/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export * from './Interpolator';
1
+ export * from './Polate';
2
+ export * from './SMath';
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Interpolator = void 0;
4
- var Interpolator = (function () {
5
- function Interpolator() {
6
- }
7
- Interpolator.normalize = function (n, min, max) {
8
- if (min === max) {
9
- return min;
10
- }
11
- return (n - min) / (max - min);
12
- };
13
- Interpolator.expand = function (n, min, max) {
14
- return (max - min) * n + min;
15
- };
16
- Interpolator.translate = function (n, min1, max1, min2, max2) {
17
- return this.expand(this.normalize(n, min1, max1), min2, max2);
18
- };
19
- return Interpolator;
20
- }());
21
- exports.Interpolator = Interpolator;