smath 1.1.4 → 1.1.5

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/1710870424)
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.5
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
@@ -29,6 +29,16 @@ var SMath = (function () {
29
29
  SMath.translate = function (n, min1, max1, min2, max2) {
30
30
  return this.expand(this.normalize(n, min1, max1), min2, max2);
31
31
  };
32
+ SMath.linspace = function (min, max, count) {
33
+ var space = [];
34
+ for (var i = 0; i < count; i++) {
35
+ space[i] = this.translate(i, 0, count - 1, min, max);
36
+ }
37
+ return space;
38
+ };
39
+ SMath.logspace = function (min, max, count) {
40
+ return this.linspace(min, max, count).map(function (n) { return Math.pow(10, n); });
41
+ };
32
42
  return SMath;
33
43
  }());
34
44
  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.5",
4
4
  "description": "Small math function library",
5
5
  "homepage": "https://npm.nicfv.com/smath",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,9 @@
27
27
  "interpolate",
28
28
  "interpolation",
29
29
  "extrapolate",
30
- "extrapolation"
30
+ "extrapolation",
31
+ "linspace",
32
+ "logspace"
31
33
  ],
32
34
  "author": {
33
35
  "name": "Nicolas Ventura",
package/types/index.d.ts CHANGED
@@ -74,4 +74,30 @@ export declare abstract class SMath {
74
74
  * ```
75
75
  */
76
76
  static translate(n: number, min1: number, max1: number, min2: number, max2: number): number;
77
+ /**
78
+ * Generate an array of linearly spaced numbers.
79
+ * @param min The initial value of the linear space
80
+ * @param max The final value of the linear space
81
+ * @param count The number of values in the space
82
+ * @returns The linear space as an array of numbers
83
+ * @example
84
+ * ```js
85
+ * const space = SMath.linspace(1, 5, 6);
86
+ * // [ 1, 1.8, 2.6, 3.4, 4.2, 5 ]
87
+ * ```
88
+ */
89
+ static linspace(min: number, max: number, count: number): Array<number>;
90
+ /**
91
+ * Generate an array of logarithmically spaced numbers.
92
+ * @param min The initial magnitude of the space
93
+ * @param max The final magnitude of the space
94
+ * @param count The number of values in the space
95
+ * @returns The logarithmic space as an array of numbers
96
+ * @example
97
+ * ```js
98
+ * const space = SMath.logspace(0, 2, 5);
99
+ * // [ 1, 3.2, 10, 31.6, 100 ]
100
+ * ```
101
+ */
102
+ static logspace(min: number, max: number, count: number): Array<number>;
77
103
  }