@kilan080/grade-calculator
v0.2.0
Published
A configurable grade calculator with support for custom grading schemes
Maintainers
Readme
@kilan080/grade-calculator
A lightweight, configurable grade calculator for converting scores into letter grades — with support for custom grading schemes.
Install
```bash npm install @kilan080/grade-calculator ```
Usage
```ts import { calculateGrade } from '@kilan080/grade-calculator';
const result = calculateGrade(75, 100); console.log(result); // { percentage: 75, grade: 'A' } ```
Custom grading scheme
```ts import { calculateGrade, GradeBand } from '@kilan080/grade-calculator';
const customScheme: GradeBand[] = [ { min: 90, grade: 'A' }, { min: 80, grade: 'B' }, { min: 70, grade: 'C' }, { min: 0, grade: 'F' }, ];
const result = calculateGrade(85, 100, customScheme); console.log(result); // { percentage: 85, grade: 'B' } ```
Default grading scheme
| Percentage | Grade | | ------------- | ----- | | 70% and above | A | | 60% – 69% | B | | 50% – 59% | C | | 45% – 49% | D | | 40% – 44% | E | | Below 40% | F |
API
`calculateGrade(score, total, scheme?)`
- `score` (number) — the score achieved
- `total` (number) — the total possible score
- `scheme` (GradeBand[], optional) — custom grading bands. Defaults to the standard scheme above.
Returns `{ percentage: number, grade: string }`.
Throws if:
- `total` is 0 or less
- `score` is negative
- `score` is greater than `total`
License
MIT
