Skip to content

Commit 4643192

Browse files
authored
Merge pull request #83 from turingsecure/80-typescript-types
chore: generate typescript types automatically on build
2 parents 4aa9dc4 + 248909e commit 4643192

8 files changed

+151
-22
lines changed

README.md

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">cvss.js by <a href="https://turingpoint.eu" target="_blank">turingpoint.</a></h1>
22
<p>
3-
<img alt="Version" src="https://img.shields.io/badge/version-1.4.5-blue.svg?cacheSeconds=2592000" />
3+
<img alt="Version" src="https://img.shields.io/badge/version-1.4.6-blue.svg?cacheSeconds=2592000" />
44
<a href="#" target="_blank">
55
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
66
</a>
@@ -20,9 +20,9 @@ yarn add @turingpointde/cvss.js
2020
Import the library to use it in your code:
2121

2222
```js
23-
const CVSS = require("@turingpointde/cvss.js");
23+
const CVSS = require('@turingpointde/cvss.js');
2424
// or
25-
import CVSS from "@turingpointde/cvss.js";
25+
import CVSS from '@turingpointde/cvss.js';
2626
```
2727

2828
You can also use the library directly from the **CDN** (instead of yarn or npm):
@@ -37,28 +37,30 @@ After importing the library, the CVSS function must first be called with the vec
3737

3838
```js
3939
// Vector only with base score
40-
const vector1 = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");
40+
const vector1 = CVSS('CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L');
4141
// Vector with temporal score
42-
const vector2 = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R");
42+
const vector2 = CVSS(
43+
'CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R',
44+
);
4345
// Vector with environmental score
4446
const vector3 = CVSS(
45-
"CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N/CR:M/IR:H/AR:M/MAV:N/MAC:H/MPR:L/MUI:N/MS:C/MC:N/MI:L/MA:L"
47+
'CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N/CR:M/IR:H/AR:M/MAV:N/MAC:H/MPR:L/MUI:N/MS:C/MC:N/MI:L/MA:L',
4648
);
4749
```
4850

4951
It is possible to pass in an object as well
5052

5153
```js
5254
const vectorObject = {
53-
CVSS: "3.0",
54-
AV: "N",
55-
AC: "H",
56-
PR: "H",
57-
UI: "R",
58-
S: "U",
59-
C: "H",
60-
I: "N",
61-
A: "N"
55+
CVSS: '3.0',
56+
AV: 'N',
57+
AC: 'H',
58+
PR: 'H',
59+
UI: 'R',
60+
S: 'U',
61+
C: 'H',
62+
I: 'N',
63+
A: 'N',
6264
};
6365

6466
console.log(CVSS(vectorObject).vector); // "CVSS:3.0/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:N/A:N"
@@ -69,7 +71,7 @@ To get the scores, simply call the respective function.
6971
```js
7072
// Create a vector
7173
const vector = CVSS(
72-
"CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N/E:P/RL:O/CR:M/IR:H/AR:M/MAV:N/MAC:H/MPR:L/MUI:N/MS:C/MC:N/MI:L/MA:L"
74+
'CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N/E:P/RL:O/CR:M/IR:H/AR:M/MAV:N/MAC:H/MPR:L/MUI:N/MS:C/MC:N/MI:L/MA:L',
7375
);
7476

7577
console.log(vector.getScore()); // 3.6
@@ -80,7 +82,7 @@ console.log(vector.getEnvironmentalScore()); // 5.1
8082
Sometimes it is useful to get a qualitative rating of a score
8183

8284
```js
83-
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");
85+
const vector = CVSS('CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L');
8486

8587
console.log(vector.getRating()); // Medium
8688
console.log(vector.getTemporalRating()); // Medium
@@ -90,7 +92,7 @@ console.log(vector.getEnvironmentalRating()); // Low
9092
A few useful variables/functions to work with the vectors:
9193

9294
```js
93-
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");
95+
const vector = CVSS('CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L');
9496

9597
console.log(vector.isValid); // true
9698
console.log(vector.vector); // CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L
@@ -101,7 +103,7 @@ The following functions are suitable for displaying the vector in a human-readab
101103

102104
```js
103105
const vector = CVSS(
104-
"CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R/MAC:X/MUI:X/MA:X/MI:X"
106+
'CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R/MAC:X/MUI:X/MA:X/MI:X',
105107
);
106108

107109
console.log(vector.getVectorObject()); // { CVSS: "3.0", AV: "N", AC: "H", PR: "L", UI: "R", S: "C", C: "L", I: "L", A: "L", E: "U", RL: "T", RC: "R", CR: "X", IR: "X", AR: "X", MAV: "X", MAC: "X", MPR: "X", MUI: "X", MS: "X" , MC: "X", MI: "X", MA: "X" }

dist/cvss.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export = CVSS;
2+
/**
3+
* Creates a new CVSS object
4+
*
5+
* @param {String} vector
6+
*/
7+
declare function CVSS(vector: string): {
8+
vector: string;
9+
getScore: () => number;
10+
getTemporalScore: () => number;
11+
getEnvironmentalScore: () => number;
12+
getRating: () => string;
13+
getTemporalRating: () => string;
14+
getEnvironmentalRating: () => string;
15+
getVectorObject: () => any;
16+
getDetailedVectorObject: () => any;
17+
getVersion: () => string;
18+
getCleanVectorString: () => string;
19+
isValid: true;
20+
};

dist/production.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/score.d.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Parses the vector to a number score
3+
*
4+
* @returns {Number} Calculated Score
5+
*/
6+
export function getScore(vector: any): number;
7+
/**
8+
* Parses the vector to the temporal score
9+
*
10+
* @returns {Number} Temporal Score
11+
*/
12+
export function getTemporalScore(vector: any): number;
13+
/**
14+
* Parses the vector to the environmental score
15+
*
16+
* @returns {Number} Environmental Score
17+
*/
18+
export function getEnvironmentalScore(vector: any): number;

dist/util.d.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @param {Number} num The number to round
3+
*
4+
* @returns The rounded number
5+
*/
6+
export function roundUpExact(num: number): number;
7+
/**
8+
* @param {Number} num The number to round
9+
* @param {Number} precision The number of decimal places to preserve
10+
*
11+
* @returns The rounded number
12+
*/
13+
export function roundUpApprox(num: number, precision: number): number;
14+
/**
15+
* Retrieves an object of vector's metrics
16+
*
17+
* @param {String} vector
18+
* @returns {Object} Abbreviations & Vector Value pair
19+
*/
20+
export function getVectorObject(vector: string): any;
21+
/**
22+
* Retrieves an object of vector's metrics
23+
*
24+
* @param {String} vector
25+
* @returns {Object} Abbreviations & Vectors Detailed Values
26+
*/
27+
export function getDetailedVectorObject(vector: string): any;
28+
/**
29+
* Finds the vector's metric by it's abbreviation
30+
*
31+
* @param {String} abbr
32+
*/
33+
export function findMetric(abbr: string): any;
34+
/**
35+
* Finds the vector's value for a specific metric
36+
*
37+
* @param {String} abbr
38+
* @param {Object} vectorObject
39+
*/
40+
export function findMetricValue(abbr: string, vectorObject: any): any;
41+
/**
42+
* Calculates the rating of the given vector
43+
*
44+
* @param Score calculated score from getScore() in cvss.js
45+
* @returns {String} returns one of the five possible ratings
46+
*/
47+
export function getRating(score: any): string;
48+
/**
49+
* Checks whether the vector passed is valid
50+
*
51+
* @param {String} vector
52+
* @returns {Boolean} result with whether the vector is valid or not
53+
*/
54+
export function isVectorValid(vector: string): boolean;
55+
/**
56+
* This transforms an object in the format of getVectorObject()
57+
* and parses it to a CVSS comaptible string
58+
*
59+
* @param {Object} obj
60+
*/
61+
export function parseVectorObjectToString(obj: any): string;
62+
/**
63+
* Retrives the version from the vector string
64+
*
65+
* @return {String} returns the version number
66+
*/
67+
export function getVersion(vector: any): string;
68+
/**
69+
* Returns a vector without undefined values
70+
*
71+
* @param {String} vector
72+
* @returns {String} Vector without undefined values
73+
*/
74+
export function getCleanVectorString(vector: string): string;

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@turingpointde/cvss.js",
3-
"version": "1.4.5",
3+
"version": "1.4.6",
44
"description": "A tiny library to work with cvss vectors",
55
"scripts": {
6-
"build": "webpack",
6+
"build": "webpack && tsc",
77
"start": "node index.js",
88
"lint": "npx eslint ./",
99
"test": "jest --detectOpenHandles --forceExit"
@@ -14,6 +14,7 @@
1414
"devDependencies": {
1515
"eslint": "^7.30.0",
1616
"jest": "^27.0.6",
17+
"typescript": "^4.3.5",
1718
"webpack": "^5.44.0",
1819
"webpack-cli": "^4.7.2"
1920
},

tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"include": ["lib/**/*"],
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"declaration": true,
6+
"emitDeclarationOnly": true,
7+
"outDir": "dist"
8+
}
9+
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,11 @@ typedarray-to-buffer@^3.1.5:
33833383
dependencies:
33843384
is-typedarray "^1.0.0"
33853385

3386+
typescript@^4.3.5:
3387+
version "4.3.5"
3388+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
3389+
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
3390+
33863391
universalify@^0.1.2:
33873392
version "0.1.2"
33883393
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"

0 commit comments

Comments
 (0)