@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.
Files changed (3) hide show
  1. package/index.js +25 -0
  2. package/package.json +12 -0
  3. 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
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@nimalkannan/calc-demo",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC"
12
+ }
package/readme.md ADDED
@@ -0,0 +1,8 @@
1
+ # Calc Utils 🧮
2
+
3
+ A lightweight JavaScript utility for basic mathematical operations and data validation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @nimalkannan/calc-demo