From 39952bd602246bc4164712e562c1990add92f94b Mon Sep 17 00:00:00 2001 From: Nic <24358775+nicfv@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:30:35 -0800 Subject: [PATCH 1/2] Smath updates (#11) * Remove module * Update class docs * Rename file * Add small math function library * Export smath --- smath/src/{Interpolator.ts => Polate.ts} | 4 +-- smath/src/SMath.ts | 39 ++++++++++++++++++++++++ smath/src/index.ts | 3 +- smath/tsconfig.json | 1 - 4 files changed, 43 insertions(+), 4 deletions(-) rename smath/src/{Interpolator.ts => Polate.ts} (94%) create mode 100644 smath/src/SMath.ts diff --git a/smath/src/Interpolator.ts b/smath/src/Polate.ts similarity index 94% rename from smath/src/Interpolator.ts rename to smath/src/Polate.ts index 2c0ec174..c3ec14ac 100644 --- a/smath/src/Interpolator.ts +++ b/smath/src/Polate.ts @@ -1,7 +1,7 @@ /** - * Contains useful interpolation functions. + * Contains useful interpolation and extrapolation functions. */ -export class Interpolator { +export class Polate { /** * Normalize the number `n` from the range `min, max` to the range `0, 1` * @param n The number to normalize diff --git a/smath/src/SMath.ts b/smath/src/SMath.ts new file mode 100644 index 00000000..b2cc1130 --- /dev/null +++ b/smath/src/SMath.ts @@ -0,0 +1,39 @@ +/** + * Small Math function library + */ +export class SMath { + /** + * Determine if a value is numeric. + * @param n Any value to check + * @returns True if `n` is a number + */ + public static isNumber(n: any): boolean { + return typeof n === 'number'; + } + /** + * Clamp a number within a range. + * @param n The number to clamp + * @param min The minimum value of the range + * @param max The maximum value of the range + * @returns A clamped number + */ + public static clamp(n: number, min: number, max: number): number { + if (n < min) { + return min; + } + if (n > max) { + return max; + } + return n; + } + /** + * Check if two numbers are approximately equal with a maximum abolute error. + * @param a Any number + * @param b Any number + * @param epsilon Maximum absolute error + * @returns True if `a` is approximately `b` + */ + public static approx(a: number, b: number, epsilon: number = 1e-6): boolean { + return a - b < epsilon && b - a < epsilon; + } +} \ No newline at end of file diff --git a/smath/src/index.ts b/smath/src/index.ts index 7707758c..1b5022d7 100644 --- a/smath/src/index.ts +++ b/smath/src/index.ts @@ -1 +1,2 @@ -export * from './Interpolator'; +export * from './Polate'; +export * from './SMath'; diff --git a/smath/tsconfig.json b/smath/tsconfig.json index 61694b57..b1c6651a 100644 --- a/smath/tsconfig.json +++ b/smath/tsconfig.json @@ -1,7 +1,6 @@ { "compilerOptions": { "strict": true, - "module": "CommonJS", "rootDir": "src", "outDir": "dist", } From ac1cd6da570a6ca0cdd6ee0dfe609871a688a8ba Mon Sep 17 00:00:00 2001 From: Nic <24358775+nicfv@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:44:38 -0800 Subject: [PATCH 2/2] Publish v0.0.4 (#12) --- smath/CHANGELOG.md | 9 +++++++++ smath/README.md | 5 ++++- smath/package.json | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/smath/CHANGELOG.md b/smath/CHANGELOG.md index 139e9bb9..cb8b40a6 100644 --- a/smath/CHANGELOG.md +++ b/smath/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.0.4 + +- Rename interpolator class +- Add and export `SMath` library +- Minor simplification in `tsconfig.json` +- Add badges in README +- Add keywords in `package.json` +- Add funding in `package.json` + ## 0.0.3 - Fix bugs in scripts diff --git a/smath/README.md b/smath/README.md index c3b13f4a..5bfce748 100644 --- a/smath/README.md +++ b/smath/README.md @@ -1,2 +1,5 @@ # smath -Small math function library \ No newline at end of file +Small math function library + +![NPM Version](https://img.shields.io/npm/v/smath) +![NPM Downloads](https://img.shields.io/npm/dt/smath) diff --git a/smath/package.json b/smath/package.json index dc8320e5..d18c9915 100644 --- a/smath/package.json +++ b/smath/package.json @@ -1,6 +1,6 @@ { "name": "smath", - "version": "0.0.3", + "version": "0.0.4", "description": "Small math function library", "main": "dist/index.js", "types": "types/index.d.ts", @@ -17,12 +17,27 @@ "docs": "rm -rf docs && typedoc src", "prepublishOnly": "npm run build && npm run types" }, - "keywords": [], + "keywords": [ + "small", + "math", + "function", + "library", + "simple", + "number", + "interpolate", + "interpolation", + "extrapolate", + "extrapolation" + ], "author": { "name": "Nicolas Ventura", "email": "smath@nicolasventura.com", "url": "https://nicolasventura.com/" }, + "funding": { + "type": "paypal", + "url": "https://www.paypal.com/donate/?business=UM6EEKPW8GXA2&no_recurring=0&item_name=Open+source+development¤cy_code=USD" + }, "repository": { "type": "git", "url": "https://github.com/nicfv/npm",