@nimalkannan/calc-demo 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 +25 -0
- package/package.json +12 -0
- package/readme.md +8 -0
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Calculator Operations
|
|
3
|
+
*/
|
|
4
|
+
const calc = {
|
|
5
|
+
add: (a, b) => a + b,
|
|
6
|
+
subtract: (a, b) => a - b,
|
|
7
|
+
multiply: (a, b) => a * b,
|
|
8
|
+
divide: (a, b) => {
|
|
9
|
+
if (b === 0) throw new Error("Cannot divide by zero!");
|
|
10
|
+
return a / b;
|
|
11
|
+
},
|
|
12
|
+
// Get percentage: e.g., percentage(20, 100) = 20
|
|
13
|
+
percentage: (part, total) => (part / total) * 100
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Simple Data Validators
|
|
18
|
+
*/
|
|
19
|
+
const validate = {
|
|
20
|
+
isNumber: (val) => typeof val === 'number' && !isNaN(val),
|
|
21
|
+
isEmail: (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Export both objects for the user
|
|
25
|
+
module.exports = { calc, validate };
|
package/package.json
ADDED