Skip to content

Commit

Permalink
typescript refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
miko37x committed Apr 16, 2024
1 parent 7432a11 commit 1f9c6ac
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 402 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"extends": "eslint:recommended",
"ignorePatterns": "dist/",
"parserOptions": {
"ecmaVersion": 12
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"indent": ["error", 2],
Expand Down
4 changes: 1 addition & 3 deletions lib/cvss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { score } from "./score";
*
* @param {String} vector
*/
function CVSS(vector) {
export function CVSS(vector) {
/**
* Retrieves an object of vector's metrics
* Calls a function from util.js
Expand Down Expand Up @@ -195,5 +195,3 @@ function CVSS(vector) {
getExploitabilitySubScore
};
}

module.exports = CVSS;
28 changes: 27 additions & 1 deletion lib/testFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,30 @@ const vectorObject = util.getDetailedVectorObject(
"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N/E:X/RL:X/RC:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MPR:X/MUI:X/MS:X/MC:X/MI:X/MA:X"
);

console.log(vectorObject);
const test = util.findMetricValue("AV", {
AV: "N",
AC: "L",
PR: "N",
UI: "N",
S: "U",
C: "L",
I: "H",
A: "N",
E: "X",
RL: "X",
RC: "X",
CR: "X",
IR: "X",
AR: "X",
MAV: "X",
MAC: "X",
MPR: "X",
MUI: "X",
MS: "X",
MC: "X",
MI: "X",
MA: "X",
CVSS: "3.0"
});

console.log(test);
56 changes: 56 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export type CvssVectorObject = {
AV: "N" | "A" | "L" | "P";
AC: "L" | "H";
PR: "N" | "L" | "H";
UI: "N" | "R";
S: "U" | "C";
C: "N" | "L" | "H";
I: "N" | "L" | "H";
A: "N" | "L" | "H";
E: "X" | "H" | "F" | "P" | "U";
RL: "X" | "U" | "W" | "T" | "O";
RC: "X" | "C" | "R" | "U";
CR: "X" | "H" | "M" | "L";
IR: "X" | "H" | "M" | "L";
AR: "X" | "H" | "M" | "L";
MAV: "X" | "N" | "A" | "L" | "P";
MAC: "X" | "L" | "H";
MPR: "X" | "N" | "L" | "H";
MUI: "X" | "N" | "R";
MS: "X" | "U" | "C";
MC: "X" | "N" | "L" | "H";
MI: "X" | "N" | "L" | "H";
MA: "X" | "N" | "L" | "H";
CVSS: string;
};

type DetailedMetric = {
name: string;
abbr: string;
fullName: string;
value: string;
valueAbbr: string;
};

export type DetailedVectorObject = { metrics: DetailedMetric[]; CVSS: string };

type Metric = {
name: string;
abbr: string;
numerical: number;
};

type MetricTest = {
name: string;
abbr: string;
numerical: { changed: number; unchanged: number }; // del
};

type Definition = { name: string; abbr: string; metrics: Metric[] };

type DefinitionTest = { name: string; abbr: "PR" | "MPR"; metrics: MetricTest[] }; // del

export type CvssVersionDefinition = {
version: string;
definitions: DefinitionTest[] | Definition[];
};
281 changes: 0 additions & 281 deletions lib/util.js

This file was deleted.

Loading

0 comments on commit 1f9c6ac

Please sign in to comment.