smath 1.1.4 → 1.1.6

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,6 +1,36 @@
1
+ <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
2
+
3
+ [Docs](https://npm.nicfv.com/smath/) | [GitHub](https://github.com/nicfv/npm/tree/main/smath/) | [npm](https://www.npmjs.com/package/smath) | [Changelog](https://github.com/nicfv/npm/blob/main/smath//CHANGELOG.md) | Small math function library
4
+
5
+ ![NPM Downloads](https://img.shields.io/npm/dt/smath)
6
+ ![NPM Version](https://img.shields.io/npm/v/smath)
7
+ ![Relative date](https://img.shields.io/date/1710877538)
8
+ ![GitHub watchers](https://img.shields.io/github/watchers/nicfv/npm)
9
+ ![GitHub forks](https://img.shields.io/github/forks/nicfv/npm)
10
+ ![GitHub Repo stars](https://img.shields.io/github/stars/nicfv/npm)
11
+
12
+ ## Installation
13
+
14
+ smath can be installed from the official [npm package repository](https://www.npmjs.com/package/smath). It is highly recommended to install the latest version, which is installed by default with the following command.
15
+
16
+ ```shell
17
+ npm i smath@1.1.6
18
+ ```
19
+
20
+ ## Bugs and Requests
21
+
22
+ Is there a way we can make smath better? Please report all bugs, issues, and new feature requests to the [issues](https://github.com/nicfv/npm/issues) page in the [official repository](https://github.com/nicfv/npm). For critical security issues, please send an email to <smath@nicolasventura.com>.
23
+
24
+ ## Contribute
25
+
26
+ Thank you for your interest in contributing to smath! smath is an open source software package maintained by Nicolas Ventura ([@nicfv](https://github.com/nicfv)) and built by users like you! You are allowed to fork the repository as permitted by the [MIT License](https://raw.githubusercontent.com/nicfv/npm/main/LICENSE) terms. Contributions are welcome by submitting a [pull request](https://github.com/nicfv/npm/pulls). Please follow the existing code styling if submitting a pull request. Thank you for your consideration!
1
27
  ## Getting Started
2
28
 
3
- **Example:** A temperature conversion tool using [`SMath.translate`](https://npm.nicfv.com/smath/classes/SMath.html#translate) to convert units and [`SMath.approx`](https://npm.nicfv.com/smath/classes/SMath.html#approx) to validate the result. The translation uses freezing and boiling points for 2 unit systems to linearly interpolate between them.
29
+ Similar to JavaScript's builtin [`Math`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) object, `SMath` exports one global object with several math-related helper functions. There is no need to instantiate the class, just call functions directly. See the examples below to get started using SMath!
30
+
31
+ ## Example
32
+
33
+ A temperature conversion tool using [`SMath.translate`](https://npm.nicfv.com/smath/classes/SMath.html#translate) to convert units and [`SMath.approx`](https://npm.nicfv.com/smath/classes/SMath.html#approx) to validate the result. The translation uses freezing and boiling points for 2 unit systems to linearly interpolate between them.
4
34
 
5
35
  ```js
6
36
  import { SMath } from 'smath';
package/dist/index.js CHANGED
@@ -4,6 +4,13 @@ exports.SMath = void 0;
4
4
  var SMath = (function () {
5
5
  function SMath() {
6
6
  }
7
+ SMath.avg = function () {
8
+ var n = [];
9
+ for (var _i = 0; _i < arguments.length; _i++) {
10
+ n[_i] = arguments[_i];
11
+ }
12
+ return n.reduce(function (prev, curr) { return prev + curr; }) / n.length;
13
+ };
7
14
  SMath.clamp = function (n, min, max) {
8
15
  if (n < min) {
9
16
  return min;
@@ -29,6 +36,16 @@ var SMath = (function () {
29
36
  SMath.translate = function (n, min1, max1, min2, max2) {
30
37
  return this.expand(this.normalize(n, min1, max1), min2, max2);
31
38
  };
39
+ SMath.linspace = function (min, max, count) {
40
+ var space = [];
41
+ for (var i = 0; i < count; i++) {
42
+ space[i] = this.translate(i, 0, count - 1, min, max);
43
+ }
44
+ return space;
45
+ };
46
+ SMath.logspace = function (min, max, count) {
47
+ return this.linspace(min, max, count).map(function (n) { return Math.pow(10, n); });
48
+ };
32
49
  return SMath;
33
50
  }());
34
51
  exports.SMath = SMath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smath",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Small math function library",
5
5
  "homepage": "https://npm.nicfv.com/smath",
6
6
  "main": "dist/index.js",
@@ -24,10 +24,15 @@
24
24
  "library",
25
25
  "simple",
26
26
  "number",
27
+ "avg",
28
+ "average",
29
+ "mean",
27
30
  "interpolate",
28
31
  "interpolation",
29
32
  "extrapolate",
30
- "extrapolation"
33
+ "extrapolation",
34
+ "linspace",
35
+ "logspace"
31
36
  ],
32
37
  "author": {
33
38
  "name": "Nicolas Ventura",
package/types/index.d.ts CHANGED
@@ -9,6 +9,16 @@
9
9
  * useful interpolation and extrapolation functions.
10
10
  */
11
11
  export declare abstract class SMath {
12
+ /**
13
+ * Compute the average, or mean, of a set of numbers.
14
+ * @param n Any amount of numeric inputs
15
+ * @returns The average, or mean
16
+ * @example
17
+ * ```js
18
+ * const mean = SMath.avg(1, 2, 3, 4); // 2.5
19
+ * ```
20
+ */
21
+ static avg(...n: Array<number>): number;
12
22
  /**
13
23
  * Clamp a number within a range.
14
24
  * @param n The number to clamp
@@ -74,4 +84,30 @@ export declare abstract class SMath {
74
84
  * ```
75
85
  */
76
86
  static translate(n: number, min1: number, max1: number, min2: number, max2: number): number;
87
+ /**
88
+ * Generate an array of linearly spaced numbers.
89
+ * @param min The initial value of the linear space
90
+ * @param max The final value of the linear space
91
+ * @param count The number of values in the space
92
+ * @returns The linear space as an array of numbers
93
+ * @example
94
+ * ```js
95
+ * const space = SMath.linspace(1, 5, 6);
96
+ * // [ 1, 1.8, 2.6, 3.4, 4.2, 5 ]
97
+ * ```
98
+ */
99
+ static linspace(min: number, max: number, count: number): Array<number>;
100
+ /**
101
+ * Generate an array of logarithmically spaced numbers.
102
+ * @param min The initial magnitude of the space
103
+ * @param max The final magnitude of the space
104
+ * @param count The number of values in the space
105
+ * @returns The logarithmic space as an array of numbers
106
+ * @example
107
+ * ```js
108
+ * const space = SMath.logspace(0, 2, 5);
109
+ * // [ 1, 3.2, 10, 31.6, 100 ]
110
+ * ```
111
+ */
112
+ static logspace(min: number, max: number, count: number): Array<number>;
77
113
  }