From f05ca0e3d98717c840ac606f16b8708d2c9e4e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Gonz=C3=A1lez=20Riffo?= Date: Mon, 19 Aug 2024 17:15:29 -0400 Subject: [PATCH] fix(grades): format null grades to 0 --- .vscode/settings.json | 2 +- lib/grades/gradeFormat.ts | 3 +++ lib/grades/gradeRound.ts | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3911202d..25106104 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,6 @@ "javascript.implicitProjectConfig.checkJs": true, "javascript.validate.enable": true, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" } } diff --git a/lib/grades/gradeFormat.ts b/lib/grades/gradeFormat.ts index f0404fc7..23114b69 100644 --- a/lib/grades/gradeFormat.ts +++ b/lib/grades/gradeFormat.ts @@ -8,6 +8,9 @@ Agrega puntos, comas, caracteres antes o despues de la nota. * @example const formated = gradeFormat(scale, grade) */ export const gradeFormat = (scale: ScaleAttributes, grade: number): string => { + if (grade === null) { + grade = 0 + } let round = `${gradeRound(scale, grade)}` if (round.length === 1 && scale.append === '' && scale.base !== 'Peru') { diff --git a/lib/grades/gradeRound.ts b/lib/grades/gradeRound.ts index ccf39902..6a441122 100644 --- a/lib/grades/gradeRound.ts +++ b/lib/grades/gradeRound.ts @@ -8,6 +8,9 @@ import { ScaleAttributes } from '../types' export const gradeRound = (scale: ScaleAttributes, grade: number): number => { try { let rounded: number | string + if (grade === null) { + return Number(0) + } if (scale.decimals > 0) { if (scale.decimals === 1) { rounded = Number(