student-utils 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ranjith Raja B
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Student Utils
2
+
3
+ A simple Node.js package for student-related calculations.
4
+
5
+ ## Features
6
+
7
+ - Calculate CGPA
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install student-utils
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ const calculateCGPA = require("./utils/cgpa");
2
+ const calculatePercentage = require("./utils/percentage");
3
+ const calculateGrade = require("./utils/grade");
4
+ const attendancePercentage = require("./utils/attendance");
5
+
6
+ module.exports = {
7
+ calculateCGPA,
8
+ calculatePercentage,
9
+ calculateGrade,
10
+ attendancePercentage
11
+ };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "student-utils",
3
+ "version": "1.1.0",
4
+ "description": "A simple student utility package for calculating CGPA and other academic values.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test.js"
8
+ },
9
+ "keywords": [
10
+ "cgpa",
11
+ "gpa",
12
+ "student",
13
+ "calculator",
14
+ "academic"
15
+ ],
16
+ "author": "RRkhv",
17
+ "license": "MIT"
18
+ }
package/test.js ADDED
@@ -0,0 +1,23 @@
1
+ const {
2
+ calculateCGPA,
3
+ calculatePercentage,
4
+ calculateGrade,
5
+ attendancePercentage
6
+ } = require("./index");
7
+
8
+ console.log("CGPA:", calculateCGPA([9, 8.5, 7.5, 8]));
9
+
10
+ console.log(
11
+ "Percentage:",
12
+ calculatePercentage(450,500)
13
+ );
14
+
15
+ console.log(
16
+ "Grade:",
17
+ calculateGrade(87)
18
+ );
19
+
20
+ console.log(
21
+ "Attendance:",
22
+ attendancePercentage(72,90)
23
+ );
@@ -0,0 +1,13 @@
1
+ function attendancePercentage(attended, total)
2
+ {
3
+ if(total <= 0)
4
+ {
5
+ throw new Error("Total classes must be greater than 0");
6
+ }
7
+
8
+ return Number(
9
+ ((attended / total) * 100).toFixed(2)
10
+ );
11
+ }
12
+
13
+ module.exports = attendancePercentage;
package/utils/cgpa.js ADDED
@@ -0,0 +1,23 @@
1
+ function calculateCGPA(grades)
2
+ {
3
+ if(!Array.isArray(grades))
4
+ {
5
+ throw new Error("Input must be an array");
6
+ }
7
+
8
+ if(grades.length === 0)
9
+ {
10
+ throw new Error("Grades array cannot be empty");
11
+ }
12
+
13
+ const total = grades.reduce(
14
+ (sum, grade) => sum + grade,
15
+ 0
16
+ );
17
+
18
+ return Number(
19
+ (total / grades.length).toFixed(2)
20
+ );
21
+ }
22
+
23
+ module.exports = calculateCGPA;
package/utils/grade.js ADDED
@@ -0,0 +1,12 @@
1
+ function calculateGrade(mark)
2
+ {
3
+ if(mark >= 90) return "O";
4
+ if(mark >= 80) return "A+";
5
+ if(mark >= 70) return "A";
6
+ if(mark >= 60) return "B+";
7
+ if(mark >= 50) return "B";
8
+
9
+ return "RA";
10
+ }
11
+
12
+ module.exports = calculateGrade;
@@ -0,0 +1,13 @@
1
+ function calculatePercentage(obtained, total)
2
+ {
3
+ if(total <= 0)
4
+ {
5
+ throw new Error("Total marks must be greater than 0");
6
+ }
7
+
8
+ return Number(
9
+ ((obtained / total) * 100).toFixed(2)
10
+ );
11
+ }
12
+
13
+ module.exports = calculatePercentage;