studywise-toolkit 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Studywise Toolkit contributors
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 CHANGED
@@ -1,3 +1,108 @@
1
- # Temporary Holding Version
1
+ # Studywise Toolkit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Studywise is a small, dependency-free JavaScript toolkit for common student tasks: weighted grades, GPA, deadline status, task prioritization, and Pomodoro schedules. It works as an ES module or a command-line program and requires Node.js 18 or newer.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install studywise-toolkit
9
+ ```
10
+
11
+ ## Use as a library
12
+
13
+ ```js
14
+ import {
15
+ calculateGrade,
16
+ calculateGpa,
17
+ getDeadlineStatus,
18
+ prioritizeTasks,
19
+ createPomodoroPlan
20
+ } from "studywise-toolkit";
21
+
22
+ calculateGrade([
23
+ { name: "Midterm", score: 82, maxScore: 100, weight: 40 },
24
+ { name: "Final", score: 91, maxScore: 100, weight: 60 }
25
+ ]);
26
+ // { percentage: 87.4, totalWeight: 100 }
27
+
28
+ calculateGpa([
29
+ { course: "Programming", gradePoints: 3.7, credits: 4 },
30
+ { course: "Math", gradePoints: 3.3, credits: 3 }
31
+ ]);
32
+ // { gpa: 3.53, totalCredits: 7, scale: 4 }
33
+
34
+ getDeadlineStatus("2026-12-01");
35
+ // { dueDate: "...", daysRemaining: ..., status: "upcoming" }
36
+
37
+ prioritizeTasks([
38
+ { title: "Submit project", dueDate: "2026-12-01", priority: 5 },
39
+ { title: "Read chapter", dueDate: "2026-12-05", priority: 2 }
40
+ ]);
41
+ // Tasks sorted by score, with rank, daysRemaining, and score fields.
42
+
43
+ createPomodoroPlan({ rounds: 4 });
44
+ // Four focus blocks, three short breaks, and 115 minutes total.
45
+ ```
46
+
47
+ All functions validate their input and throw a `TypeError` or `RangeError` with a useful message when values are invalid. `priority` uses a 1–5 scale and defaults to 3. GPA `gradePoints` must be within the selected scale, which defaults to 4. For `YYYY-MM-DD` deadlines, calculations compare local calendar days; pass `{ now: new Date("2026-11-24T12:00:00") }` when you need a reproducible result. Pomodoro plans put breaks between focus rounds, with a long break after every fourth round when another round follows.
48
+
49
+ ## Use the CLI
50
+
51
+ After installing, the `studywise` command is available:
52
+
53
+ ```sh
54
+ studywise deadline --date 2026-12-01
55
+ studywise pomodoro --rounds 4
56
+ studywise grade --input grades.json
57
+ studywise gpa --input courses.json
58
+ studywise prioritize --input tasks.json
59
+ ```
60
+
61
+ Example `grades.json`:
62
+
63
+ ```json
64
+ [
65
+ { "name": "Midterm", "score": 82, "maxScore": 100, "weight": 40 },
66
+ { "name": "Final", "score": 91, "maxScore": 100, "weight": 60 }
67
+ ]
68
+ ```
69
+
70
+ Example `courses.json`:
71
+
72
+ ```json
73
+ [
74
+ { "course": "Programming", "gradePoints": 3.7, "credits": 4 },
75
+ { "course": "Math", "gradePoints": 3.3, "credits": 3 }
76
+ ]
77
+ ```
78
+
79
+ Example `tasks.json`:
80
+
81
+ ```json
82
+ [
83
+ { "title": "Submit project", "dueDate": "2026-12-01", "priority": 5 },
84
+ { "title": "Read chapter", "dueDate": "2026-12-05", "priority": 2 }
85
+ ]
86
+ ```
87
+
88
+ ## API
89
+
90
+ - `calculateGrade(items)` — returns normalized weighted percentage and total weight.
91
+ - `calculateGpa(courses, { scale })` — returns credit-weighted GPA (4-point scale by default).
92
+ - `getDeadlineStatus(dueDate, { now })` — returns ISO due date, days remaining, and `upcoming`, `due-today`, or `overdue` status.
93
+ - `prioritizeTasks(tasks, { now })` — sorts by urgency adjusted by priority (1–5).
94
+ - `createPomodoroPlan(options)` — returns a minute-by-minute focus and break schedule.
95
+
96
+ ## Package contents
97
+
98
+ The package has no runtime dependencies. Source and CLI are plain JavaScript. Released under the MIT License.
99
+
100
+ ## Publish
101
+
102
+ 1. Choose a unique npm package name; if `studywise-toolkit` is already taken, update `name` in `package.json` and the install/import examples here.
103
+ 2. Add your name to `package.json`. If you create a public Git repository, add its URL and related links to `package.json`.
104
+ 3. Sign in or create an account at [npmjs.com](https://www.npmjs.com/), and verify the email address.
105
+ 4. From this folder, run `npm login`, `npm test`, and `npm publish`.
106
+ 5. Check the package page on npmjs.com and install it in a fresh folder to confirm it is public and installable.
107
+
108
+ Publishing requires your own npm account credentials. Do not share your password or one-time codes.
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from "node:fs/promises";
3
+ import { calculateGrade, calculateGpa, createPomodoroPlan, getDeadlineStatus, prioritizeTasks } from "../src/index.js";
4
+
5
+ const help = `Studywise — practical study planning utilities
6
+
7
+ Usage:
8
+ studywise <command> [options]
9
+
10
+ Commands:
11
+ grade --input grades.json Calculate a weighted grade
12
+ gpa --input courses.json Calculate a credit-weighted GPA
13
+ prioritize --input tasks.json Rank tasks by deadline and priority
14
+ deadline --date 2026-12-01 Check a deadline
15
+ pomodoro [--rounds 4] Print a focus/break plan
16
+ help Show this help
17
+
18
+ Input files contain JSON arrays. See README.md for example formats.
19
+ `;
20
+
21
+ function option(args, name) {
22
+ const index = args.indexOf(`--${name}`);
23
+ return index === -1 ? undefined : args[index + 1];
24
+ }
25
+
26
+ async function main() {
27
+ const [command = "help", ...args] = process.argv.slice(2);
28
+ if (command === "help" || command === "--help" || command === "-h") return console.log(help);
29
+ let result;
30
+ if (command === "deadline") {
31
+ const date = option(args, "date");
32
+ if (!date) throw new Error("Provide a date with --date YYYY-MM-DD.");
33
+ result = getDeadlineStatus(date);
34
+ } else if (command === "pomodoro") {
35
+ const rounds = option(args, "rounds");
36
+ result = createPomodoroPlan(rounds === undefined ? {} : { rounds: Number(rounds) });
37
+ } else {
38
+ const input = option(args, "input");
39
+ if (!input) throw new Error(`Provide a JSON file with --input.\n\n${help}`);
40
+ const data = JSON.parse(await readFile(input, "utf8"));
41
+ if (command === "grade") result = calculateGrade(data);
42
+ else if (command === "gpa") result = calculateGpa(data);
43
+ else if (command === "prioritize") result = prioritizeTasks(data);
44
+ else throw new Error(`Unknown command: ${command}\n\n${help}`);
45
+ }
46
+ console.log(JSON.stringify(result, null, 2));
47
+ }
48
+
49
+ main().catch((error) => {
50
+ console.error(`studywise: ${error.message}`);
51
+ process.exitCode = 1;
52
+ });
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "studywise-toolkit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "A dependency-free toolkit and CLI for grades, deadlines, and study planning.",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "module": "./src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js"
10
+ },
11
+ "scripts": {
12
+ "test": "node --test"
13
+ },
14
+ "bin": {
15
+ "studywise": "./bin/studywise.js"
16
+ },
17
+ "files": ["src", "bin", "README.md", "LICENSE"],
18
+ "engines": { "node": ">=18" },
19
+ "keywords": ["study", "student", "gpa", "grades", "deadline", "planner", "education"],
20
+ "license": "MIT"
21
+ }
package/src/index.js ADDED
@@ -0,0 +1,110 @@
1
+ const assertNumber = (value, label, { min = -Infinity, max = Infinity } = {}) => {
2
+ if (typeof value !== "number" || !Number.isFinite(value)) {
3
+ throw new TypeError(`${label} must be a finite number between ${min} and ${max}.`);
4
+ }
5
+ if (value < min || value > max) throw new RangeError(`${label} must be between ${min} and ${max}.`);
6
+ };
7
+
8
+ const round = (value, places = 2) => Number(value.toFixed(places));
9
+
10
+ function daysUntil(date, reference) {
11
+ // Treat YYYY-MM-DD as a calendar date, so its status does not change at midnight UTC.
12
+ const dateOnly = typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date);
13
+ if (dateOnly) {
14
+ const [year, month, day] = date.split("-").map(Number);
15
+ const dueDay = new Date(year, month - 1, day);
16
+ if (dueDay.getFullYear() !== year || dueDay.getMonth() !== month - 1 || dueDay.getDate() !== day) {
17
+ throw new TypeError("Date must be a real calendar date.");
18
+ }
19
+ const today = new Date(reference.getFullYear(), reference.getMonth(), reference.getDate());
20
+ return Math.round((dueDay - today) / 86_400_000);
21
+ }
22
+ return Math.ceil((new Date(date) - reference) / 86_400_000);
23
+ }
24
+
25
+ /** Calculate a weighted percentage from [{ name, score, maxScore, weight }]. */
26
+ export function calculateGrade(items) {
27
+ if (!Array.isArray(items) || items.length === 0) throw new TypeError("items must be a non-empty array.");
28
+ let totalWeight = 0;
29
+ let weightedScore = 0;
30
+ for (const [index, item] of items.entries()) {
31
+ if (!item || typeof item !== "object") throw new TypeError(`Item ${index + 1} must be an object.`);
32
+ assertNumber(item.score, `Item ${index + 1} score`, { min: 0 });
33
+ assertNumber(item.maxScore, `Item ${index + 1} maxScore`, { min: Number.EPSILON });
34
+ assertNumber(item.weight, `Item ${index + 1} weight`, { min: 0 });
35
+ if (item.score > item.maxScore) throw new RangeError(`Item ${index + 1} score cannot exceed maxScore.`);
36
+ totalWeight += item.weight;
37
+ weightedScore += (item.score / item.maxScore) * item.weight;
38
+ }
39
+ if (totalWeight <= 0) throw new RangeError("The sum of weights must be greater than zero.");
40
+ return { percentage: round((weightedScore / totalWeight) * 100), totalWeight: round(totalWeight) };
41
+ }
42
+
43
+ /** Calculate a weighted GPA from [{ gradePoints, credits }]. */
44
+ export function calculateGpa(courses, { scale = 4 } = {}) {
45
+ if (!Array.isArray(courses) || courses.length === 0) throw new TypeError("courses must be a non-empty array.");
46
+ assertNumber(scale, "scale", { min: Number.EPSILON });
47
+ let credits = 0;
48
+ let points = 0;
49
+ for (const [index, course] of courses.entries()) {
50
+ if (!course || typeof course !== "object") throw new TypeError(`Course ${index + 1} must be an object.`);
51
+ assertNumber(course.gradePoints, `Course ${index + 1} gradePoints`, { min: 0, max: scale });
52
+ assertNumber(course.credits, `Course ${index + 1} credits`, { min: Number.EPSILON });
53
+ credits += course.credits;
54
+ points += course.gradePoints * course.credits;
55
+ }
56
+ return { gpa: round(points / credits), totalCredits: round(credits), scale };
57
+ }
58
+
59
+ /** Rank tasks by urgency and user-set priority. Earlier due dates rank first. */
60
+ export function prioritizeTasks(tasks, { now = new Date() } = {}) {
61
+ if (!Array.isArray(tasks)) throw new TypeError("tasks must be an array.");
62
+ const reference = new Date(now);
63
+ if (Number.isNaN(reference.getTime())) throw new TypeError("now must be a valid date.");
64
+ const ranked = tasks.map((task, index) => {
65
+ if (!task || typeof task !== "object") throw new TypeError(`Task ${index + 1} must be an object.`);
66
+ if (typeof task.title !== "string" || !task.title.trim()) throw new TypeError(`Task ${index + 1} needs a title.`);
67
+ const due = new Date(task.dueDate);
68
+ if (Number.isNaN(due.getTime())) throw new TypeError(`Task ${index + 1} dueDate must be a valid date.`);
69
+ const priority = task.priority ?? 3;
70
+ assertNumber(priority, `Task ${index + 1} priority`, { min: 1, max: 5 });
71
+ const daysRemaining = daysUntil(task.dueDate, reference);
72
+ const urgency = daysRemaining < 0 ? 100 + Math.abs(daysRemaining) : 100 / (daysRemaining + 1);
73
+ return { ...task, priority, daysRemaining, score: round(urgency * (priority / 3)), _index: index };
74
+ });
75
+ return ranked.sort((a, b) => b.score - a.score || a._index - b._index)
76
+ .map(({ _index, ...task }, rank) => ({ ...task, rank: rank + 1 }));
77
+ }
78
+
79
+ /** Describe how close a deadline is. Accepts any value understood by Date. */
80
+ export function getDeadlineStatus(dueDate, { now = new Date() } = {}) {
81
+ const due = new Date(dueDate);
82
+ const reference = new Date(now);
83
+ if (Number.isNaN(due.getTime())) throw new TypeError("dueDate must be a valid date.");
84
+ if (Number.isNaN(reference.getTime())) throw new TypeError("now must be a valid date.");
85
+ const daysRemaining = daysUntil(dueDate, reference);
86
+ const status = daysRemaining < 0 ? "overdue" : daysRemaining === 0 ? "due-today" : "upcoming";
87
+ return { dueDate: due.toISOString(), daysRemaining, status };
88
+ }
89
+
90
+ /** Build a simple focus/break timeline in minutes. */
91
+ export function createPomodoroPlan({ rounds = 4, focusMinutes = 25, shortBreakMinutes = 5, longBreakMinutes = 15 } = {}) {
92
+ assertNumber(rounds, "rounds", { min: 1, max: 20 });
93
+ assertNumber(focusMinutes, "focusMinutes", { min: 1 });
94
+ assertNumber(shortBreakMinutes, "shortBreakMinutes", { min: 1 });
95
+ assertNumber(longBreakMinutes, "longBreakMinutes", { min: 1 });
96
+ if (!Number.isInteger(rounds)) throw new TypeError("rounds must be an integer.");
97
+ const sessions = [];
98
+ let startMinute = 0;
99
+ for (let roundNumber = 1; roundNumber <= rounds; roundNumber++) {
100
+ sessions.push({ type: "focus", round: roundNumber, startMinute, durationMinutes: focusMinutes });
101
+ startMinute += focusMinutes;
102
+ if (roundNumber < rounds) {
103
+ const isLongBreak = roundNumber % 4 === 0;
104
+ const durationMinutes = isLongBreak ? longBreakMinutes : shortBreakMinutes;
105
+ sessions.push({ type: isLongBreak ? "long-break" : "short-break", afterRound: roundNumber, startMinute, durationMinutes });
106
+ startMinute += durationMinutes;
107
+ }
108
+ }
109
+ return { sessions, totalMinutes: startMinute };
110
+ }