smath 1.8.5 → 1.8.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 +0 -104
- package/dist/index.js +1 -3
- package/package.json +6 -8
- package/types/index.d.ts +1 -3
package/README.md
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
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
|
-

|
|
4
|
-

|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-

|
|
9
|
-
[](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!
|
|
26
1
|
## Getting Started
|
|
27
2
|
|
|
28
3
|
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!
|
|
@@ -46,82 +21,3 @@ This example command returns the value 0.4.
|
|
|
46
21
|
```shell
|
|
47
22
|
npx smath normalize 4 0 10
|
|
48
23
|
```
|
|
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/dist/index.js
CHANGED
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SMath = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @packageDocumentation
|
|
6
|
-
* Small math function library
|
|
7
|
-
*
|
|
8
|
-
* Exports the public-facing API for `smath`
|
|
6
|
+
*  Small math function library
|
|
9
7
|
*/
|
|
10
8
|
/**
|
|
11
9
|
* Contains a small math function library including
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smath",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.6",
|
|
4
4
|
"description": "Small math function library",
|
|
5
|
-
"homepage": "https://npm.nicfv.com/
|
|
5
|
+
"homepage": "https://npm.nicfv.com/",
|
|
6
6
|
"bin": "dist/bin.js",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "types/index.d.ts",
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
"types"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "npm run postpack &&
|
|
15
|
-
"test": "tsc
|
|
16
|
-
"clean": "rm -rf node_modules package-lock.json && npm run postpack",
|
|
14
|
+
"build": "npm run postpack && tsc && node dist/test.js && rm dist/test.js types/test.d.ts",
|
|
15
|
+
"test": "tsc --noEmit",
|
|
17
16
|
"prepack": "npm run build",
|
|
18
|
-
"postpack": "rm -rf dist types
|
|
17
|
+
"postpack": "rm -rf dist types"
|
|
19
18
|
},
|
|
20
19
|
"keywords": [
|
|
21
20
|
"small",
|
|
@@ -57,7 +56,6 @@
|
|
|
57
56
|
"license": "MIT",
|
|
58
57
|
"devDependencies": {
|
|
59
58
|
"@types/node": "20.12.7",
|
|
60
|
-
"
|
|
61
|
-
"typedoc": "0.25.13"
|
|
59
|
+
"t6": "1.1.4"
|
|
62
60
|
}
|
|
63
61
|
}
|
package/types/index.d.ts
CHANGED