tiny-math-kit 1.0.0
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/index.js +32 -0
- package/package.json +13 -0
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function clamp(value, min, max) {
|
|
2
|
+
return Math.min(Math.max(value, min), max);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function percent(value, total) {
|
|
6
|
+
return (value / total) * 100;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function lerp(a, b, t) {
|
|
10
|
+
return a + (b - a) * t;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function normalize(value, min, max) {
|
|
14
|
+
return (value - min) / (max - min);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function map(value, inMin, inMax, outMin, outMax) {
|
|
18
|
+
return outMin + ((value - inMin) * (outMax - outMin)) / (inMax - inMin);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function randomRange(min, max) {
|
|
22
|
+
return Math.random() * (max - min) + min;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
clamp,
|
|
27
|
+
percent,
|
|
28
|
+
lerp,
|
|
29
|
+
normalize,
|
|
30
|
+
map,
|
|
31
|
+
randomRange
|
|
32
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tiny-math-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Basic math functions for JavaScript.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "chrjs",
|
|
9
|
+
"keywords": ["math", "calculator", "arithmetic", "numbers", "utils"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node index.js"
|
|
12
|
+
}
|
|
13
|
+
}
|