ects-oleksi-pavliuk 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/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # ects-oleksii-pavliuk
2
+
3
+ A small npm package that converts scores from the 100-point grading system to the ECTS format.
4
+
5
+ ## Installation
6
+
7
+ npm install ects-oleksii-pavliuk
8
+
9
+ ## Usage
10
+
11
+ const ECTS = require('ects-oleksii-pavliuk');
12
+ const grade = new ECTS(87).ectsFromScore(); // 'B'
13
+
14
+ ## Tests
15
+
16
+ Run tests locally:
17
+
18
+ npm test
19
+
20
+ ## Publish
21
+
22
+ 1. Ensure `package.json` `name` is `ects-oleksii-pavliuk`.
23
+ 2. `npm login` (or `npm adduser`).
24
+ 3. `npm publish` (use `--access public` if needed).
25
+
26
+ Make sure `name.txt` in the task repo contains the published package name exactly: `ects-oleksii-pavliuk`.
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ class ECTS {
2
+ constructor(score) {
3
+ this.score = Number(score);
4
+ }
5
+
6
+ ectsFromScore() {
7
+ const s = this.score;
8
+ if (Number.isNaN(s) || s < 0 || s > 100) {
9
+ throw new Error('Score must be a number between 0 and 100');
10
+ }
11
+
12
+ if (s >= 90 && s <= 100) return 'A';
13
+ if (s >= 82 && s <= 89) return 'B';
14
+ if (s >= 74 && s <= 81) return 'C';
15
+ if (s >= 65 && s <= 73) return 'D';
16
+ if (s >= 60 && s <= 64) return 'E';
17
+ return 'F';
18
+ }
19
+ }
20
+
21
+ module.exports = ECTS;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "ects-oleksi-pavliuk",
3
+ "version": "1.0.0",
4
+ "description": "Convert scores from the 100-point grading system to ECTS format",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test/test.js"
8
+ },
9
+ "keywords": [
10
+ "ects",
11
+ "grading",
12
+ "score"
13
+ ],
14
+ "author": "Oleksii Pavliuk",
15
+ "license": "MIT",
16
+ "directories": {
17
+ "test": "test"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/OleksiiPavliuk2002/ECTS.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/OleksiiPavliuk2002/ECTS/issues"
25
+ },
26
+ "homepage": "https://github.com/OleksiiPavliuk2002/ECTS#readme"
27
+ }
package/test/test.js ADDED
@@ -0,0 +1,31 @@
1
+ const assert = require('assert');
2
+ const ECTS = require('../index');
3
+
4
+ const cases = [
5
+ [91, 'A'],
6
+ [90, 'A'],
7
+ [89.9, 'B'],
8
+ [80, 'B'],
9
+ [79.9, 'C'],
10
+ [70, 'C'],
11
+ [60, 'D'],
12
+ [45, 'E'],
13
+ [44.9, 'F'],
14
+ [0, 'F'],
15
+ ];
16
+
17
+ cases.forEach(([score, expected]) => {
18
+ const e = new ECTS(score);
19
+ assert.strictEqual(e.ectsFromScore(), expected, `Score ${score} should be ${expected}`);
20
+ });
21
+
22
+ // Validate error on invalid input
23
+ let threw = false;
24
+ try {
25
+ new ECTS('abc').ectsFromScore();
26
+ } catch (err) {
27
+ threw = true;
28
+ }
29
+ assert.strictEqual(threw, true, 'Should throw on invalid score');
30
+
31
+ console.log('All tests passed');