smath 1.8.4 → 1.8.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.
Files changed (2) hide show
  1. package/README.md +104 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
+ [Home](https://npm.nicfv.com/) | [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) | [YouTube](https://www.youtube.com/@n1cfv) | Small math function library
2
+
3
+ ![NPM Downloads](https://img.shields.io/npm/dt/smath)
4
+ ![NPM Version](https://img.shields.io/npm/v/smath)
5
+ ![Relative date](https://img.shields.io/date/1713369829)
6
+ ![GitHub watchers](https://img.shields.io/github/watchers/nicfv/npm)
7
+ ![GitHub forks](https://img.shields.io/github/forks/nicfv/npm)
8
+ ![GitHub Repo stars](https://img.shields.io/github/stars/nicfv/npm)
9
+ [![Static Badge](https://img.shields.io/badge/donate-PayPal-blue)](https://paypal.me/nicfv)
10
+
11
+ ## Installation
12
+
13
+ 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.
14
+
15
+ ```shell
16
+ npm i smath@1.8.5
17
+ ```
18
+
19
+ ## Bugs and Requests
20
+
21
+ 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@nicfv.com>.
22
+
23
+ ## Contribute
24
+
25
+ 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
26
  ## Getting Started
2
27
 
3
28
  Small math? Simple math? Or supplemental math? Canonically, "SMath" is pronounced "smath" and stands for "small math (library.)" 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!
@@ -21,3 +46,82 @@ This example command returns the value 0.4.
21
46
  ```shell
22
47
  npx smath normalize 4 0 10
23
48
  ```
49
+ ## Examples
50
+ Here are a few quickstart examples written in JavaScript that showcase some out-of-box features of the `smath` package.
51
+ ### JavaScript Math Oddities
52
+ Sometimes, JavaScript does weird math! Try adding `0.1 + 0.2` in your NodeJS terminal. What did you get?
53
+
54
+ > Hint: It's not 0.3!
55
+
56
+ The function `SMath.approx()` is an attempt to mitigate some of the issues that arise when doing arithmetic with non-whole numbers.
57
+ #### Instructions
58
+ 1. Copy the source code
59
+ 1. Paste into a new file
60
+ 1. Save as `JavaScript-Math-Oddities.mjs`
61
+ 1. Run this command in your terminal
62
+ ```shell
63
+ node JavaScript-Math-Oddities.mjs
64
+ ```
65
+ #### Source
66
+ ```js
67
+ import { SMath } from 'smath';
68
+
69
+ // Determine the value of 0.1 + 0.2 using vanilla JavaScript and SMath
70
+ console.log('0.1 + 0.2 == 0.3 is ' + (0.1 + 0.2 == 0.3));
71
+ console.log('SMath.approx(0.1 + 0.2, 0.3) is ' + SMath.approx(0.1 + 0.2, 0.3));
72
+ ```
73
+ #### Output
74
+ ```text
75
+ 0.1 + 0.2 == 0.3 is false
76
+ SMath.approx(0.1 + 0.2, 0.3) is true
77
+ ```
78
+ ### Temperature Conversion
79
+ This example demonstrates a simple temperature converter from Celsius to Fahrenheit, using `SMath.translate()` to linearly interpolate between unit systems. The translation uses freezing and boiling points to fix the bounds of the linear interpolation.
80
+ #### Instructions
81
+ 1. Copy the source code
82
+ 1. Paste into a new file
83
+ 1. Save as `Temperature-Conversion.mjs`
84
+ 1. Run this command in your terminal
85
+ ```shell
86
+ node Temperature-Conversion.mjs
87
+ ```
88
+ #### Source
89
+ ```js
90
+ import { SMath } from 'smath';
91
+
92
+ // Water always freezes at the
93
+ // same temperature, but the
94
+ // units might be different.
95
+ // Define some constants to
96
+ // create two number ranges.
97
+ const C_Freeze = 0,
98
+ C_Boil = 100,
99
+ F_Freeze = 32,
100
+ F_Boil = 212;
101
+
102
+ // Use the `SMath` class to
103
+ // generate an array of five
104
+ // linearly spaced temperature
105
+ // values from 0 to 20.
106
+ const C = SMath.linspace(0, 20, 5);
107
+
108
+ // Use the `SMath` class to linearly
109
+ // interpolate the temperature in the
110
+ // C number range to a temperature
111
+ // in the F number range.
112
+ const F = C.map(c => SMath.translate(c, C_Freeze, C_Boil, F_Freeze, F_Boil));
113
+
114
+ // Print out each temperature
115
+ // in both units of C and F.
116
+ for (let i = 0; i < C.length; i++) {
117
+ console.log(C[i].toFixed() + 'C is ' + F[i].toFixed() + 'F')
118
+ }
119
+ ```
120
+ #### Output
121
+ ```text
122
+ 0C is 32F
123
+ 5C is 41F
124
+ 10C is 50F
125
+ 15C is 59F
126
+ 20C is 68F
127
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smath",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "Small math function library",
5
5
  "homepage": "https://npm.nicfv.com/smath",
6
6
  "bin": "dist/bin.js",