-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseverityRating.js
41 lines (35 loc) · 1.36 KB
/
severityRating.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/** ****************************************************************************************************
* File: severityRating.js
* Project: cvsscalculator
* @author Nick Soggin <iSkore@users.noreply.github.com> on 18-Feb-2019
*******************************************************************************************************/
'use strict';
const { severityRatings } = require( './variables' );
/**
* severityRating
*
* Given a CVSS score, returns the name of the severity rating as defined in the CVSS standard.
* The input needs to be a number between 0.0 to 10.0, to one decimal place of precision.
*
* The following error values may be returned instead of a severity rating name:
* NaN (JavaScript "Not a Number") - if the input is not a number.
* undefined - if the input is a number that is not within the range of any defined severity rating.
*
* @param {number} score - assessed score
* @returns {*} - severity rating or undefined
*/
function severityRating( score ) {
const
severityRatingLength = severityRatings.length,
validatedScore = +score;
if( isNaN( validatedScore ) ) {
return validatedScore;
}
for( let i = 0; i < severityRatingLength; i++ ) {
if( score >= severityRatings[ i ].bottom && score <= severityRatings[ i ].top ) {
return severityRatings[ i ].name;
}
}
return undefined;
}
module.exports = severityRating;