math-utils-simple 1.0.0 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-utils-simple",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A simple math utility library for npm",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -10,7 +10,12 @@
10
10
  "scripts": {
11
11
  "test": "node --test"
12
12
  },
13
- "keywords": ["math", "utils", "npm", "library"],
13
+ "keywords": [
14
+ "math",
15
+ "utils",
16
+ "npm",
17
+ "library"
18
+ ],
14
19
  "author": "Umar Farooq",
15
20
  "license": "MIT"
16
- }
21
+ }
@@ -0,0 +1,3 @@
1
+ export default function abs(n) {
2
+ return Math.abs(n);
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function cube(n) {
2
+ return n * n * n;
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function cubeRoot(n) {
2
+ return Math.cbrt(n);
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function decrement(n) {
2
+ return n - 1;
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function increment(n) {
2
+ return n + 1;
3
+ }
@@ -0,0 +1,4 @@
1
+ export default function mod(a, b) {
2
+ if (b === 0) throw new Error("Modulo by zero.");
3
+ return a % b;
4
+ }
@@ -0,0 +1,3 @@
1
+ export default function negate(n) {
2
+ return -n;
3
+ }
@@ -0,0 +1,4 @@
1
+ export default function nthRoot(number, n) {
2
+ if (n === 0) throw new Error("Root degree cannot be zero.");
3
+ return Math.pow(number, 1 / n);
4
+ }
@@ -0,0 +1,4 @@
1
+ export default function reciprocal(n) {
2
+ if (n === 0) throw new Error("Cannot calculate reciprocal of zero.");
3
+ return 1 / n;
4
+ }
@@ -0,0 +1,3 @@
1
+ export default function square(n) {
2
+ return n * n;
3
+ }
package/src/index.js CHANGED
@@ -1,10 +1,16 @@
1
- export { default as add } from "./add.js";
2
- export { default as subtract } from "./subtract.js";
3
- export { default as multiply } from "./multiply.js";
4
- export { default as divide } from "./divide.js";
5
- export { default as power } from "./power.js";
6
- export { default as sqrt } from "./sqrt.js";
7
- export { default as factorial } from "./factorial.js";
8
- export { default as gcd } from "./gcd.js";
9
- export { default as lcm } from "./lcm.js";
10
- export { default as average } from "./average.js";
1
+ export { default as add } from "./arithmetic/add.js";
2
+ export { default as subtract } from "./arithmetic/subtract.js";
3
+ export { default as multiply } from "./arithmetic/multiply.js";
4
+ export { default as divide } from "./arithmetic/divide.js";
5
+ export { default as mod } from "./arithmetic/mod.js";
6
+ export { default as power } from "./arithmetic/power.js";
7
+ export { default as sqrt } from "./arithmetic/sqrt.js";
8
+ export { default as cubeRoot } from "./arithmetic/cubeRoot.js";
9
+ export { default as nthRoot } from "./arithmetic/nthRoot.js";
10
+ export { default as abs } from "./arithmetic/abs.js";
11
+ export { default as negate } from "./arithmetic/negate.js";
12
+ export { default as increment } from "./arithmetic/increment.js";
13
+ export { default as decrement } from "./arithmetic/decrement.js";
14
+ export { default as square } from "./arithmetic/square.js";
15
+ export { default as cube } from "./arithmetic/cube.js";
16
+ export { default as reciprocal } from "./arithmetic/reciprocal.js";
@@ -0,0 +1,5 @@
1
+ function validateNumber(value, name = "value") {
2
+ if (typeof value !== "number" || Number.isNaN(value)) {
3
+ throw new TypeError(`${name} must be a valid number.`);
4
+ }
5
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes