diff --git a/.eslintrc.json b/.eslintrc.json index 11e6847..b5ba1b4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,8 @@ "extends": "eslint:recommended", "ignorePatterns": "dist/", "parserOptions": { - "ecmaVersion": 12 + "ecmaVersion": 12, + "sourceType": "module" }, "rules": { "indent": ["error", 2], diff --git a/lib/cvss.ts b/lib/cvss.ts index 6a8acc5..95f41e2 100644 --- a/lib/cvss.ts +++ b/lib/cvss.ts @@ -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 @@ -195,5 +195,3 @@ function CVSS(vector) { getExploitabilitySubScore }; } - -module.exports = CVSS; diff --git a/lib/testFile.ts b/lib/testFile.ts index 5d60fad..9a0ea9f 100644 --- a/lib/testFile.ts +++ b/lib/testFile.ts @@ -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); diff --git a/lib/types.ts b/lib/types.ts new file mode 100644 index 0000000..8c37908 --- /dev/null +++ b/lib/types.ts @@ -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[]; +}; diff --git a/lib/util.js b/lib/util.js deleted file mode 100644 index f401218..0000000 --- a/lib/util.js +++ /dev/null @@ -1,281 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var definitions = require("./cvss_3_0.json"); -/** - * Finds the vector's metric by it's abbreviation - * - * @param {string} abbr Abbreviation of the vector metric - * - * @returns {definition} Definition of the vector metric matching the abbreviation - */ -var findMetric = function (abbr) { - return definitions.definitions.find(function (def) { return def.abbr === abbr; }); -}; -/** - * Finds the vector's value for a specific metric - * - * @param {string} abbr Abbreviation of the vector metric - * @param {cvssVectorObject} vectorObject Vector object of interested - * - * @returns {metric | undefined} The metric matching to the given abbriviation or undefined if no match is found - */ -var findMetricValue = function (abbr, vectorObject) { - var definition = findMetric(abbr); - var value = definition.metrics.find(function (metric) { return metric.abbr === vectorObject[definition.abbr]; }); - return value; -}; -/** - * @param {number} num The number to round - * @param {number} precision The number of decimal places to preserve - * - * @returns {number} The rounded number - */ -function roundUpApprox(num, precision) { - precision = Math.pow(10, precision); - return Math.ceil(num * precision) / precision; -} -/** - * @param {number} num The number to round - * - * @returns {number} The rounded number - */ -function roundUpExact(num) { - var int_input = Math.round(num * 100000); - if (int_input % 10000 === 0) { - return int_input / 100000; - } - else { - return (Math.floor(int_input / 10000) + 1) / 10; - } -} -/** - * Retrieves an object of vector's metrics - * - * @param {string} vector The vector string - * - * @returns {obejct} Abbreviations & Vector Value pair - */ -function getVectorObject(vector) { - var vectorArray = vector.split("/"); - var vectorObject = {}; - definitions.definitions.forEach(function (definition) { return (vectorObject[definition["abbr"]] = "X"); }); - for (var _i = 0, vectorArray_1 = vectorArray; _i < vectorArray_1.length; _i++) { - var entry = vectorArray_1[_i]; - var values = entry.split(":"); - vectorObject[values[0]] = values[1]; - } - return vectorObject; -} -/** - * Returns a vector without undefined values - * - * @param {String} vector - * @returns {String} Vector without undefined values - */ -function getCleanVectorString(vector) { - var vectorArray = vector.split("/"); - var cleanVectorArray = []; - for (var _i = 0, vectorArray_2 = vectorArray; _i < vectorArray_2.length; _i++) { - var entry = vectorArray_2[_i]; - var values = entry.split(":"); - if (values[1] !== "X") - cleanVectorArray.push(entry); - } - return cleanVectorArray.join("/"); -} -/** - * Retrieves an object of vector's metrics - * - * @param {String} vector - * @returns {Object} Abbreviations & Vectors Detailed Values - */ -function getDetailedVectorObject(vector) { - var vectorArray = vector.split("/"); - var vectorObject = vectorArray.reduce(function (vectorObjectAccumulator, vectorItem, index) { - var _a, _b; - var values = vectorItem.split(":"); - var metrics = __assign({}, vectorObjectAccumulator.metrics); - if (index) { - var vectorDef = findMetric(values[0]); - var detailedVectorObject = { - name: vectorDef.name, - abbr: vectorDef.abbr, - fullName: vectorDef.name + " (" + vectorDef.abbr + ")", - value: vectorDef.metrics.find(function (def) { return def.abbr === values[1]; }).name, - valueAbbr: values[1] - }; - return Object.assign(vectorObjectAccumulator, { - metrics: Object.assign(metrics, (_a = {}, - _a[values[0].trim()] = detailedVectorObject, - _a)) - }); - } - else { - return Object.assign(vectorObjectAccumulator, (_b = {}, - _b[values[0].trim()] = values[1], - _b)); - } - }, { metrics: {} }); - return vectorObject; -} -/** - * Calculates the rating of the given vector - * - * @param Score calculated score from getScore() in cvss.js - * @returns {String} returns one of the five possible ratings - */ -function getRating(score) { - var rating = "None"; - if (score === 0) { - rating = "None"; - } - else if (score <= 3.9) { - rating = "Low"; - } - else if (score <= 6.9) { - rating = "Medium"; - } - else if (score <= 8.9) { - rating = "High"; - } - else { - rating = "Critical"; - } - return rating; -} -/** - * Checks whether the vector passed is valid - * - * @param {String} vector - * @returns {Boolean} result with whether the vector is valid or not - */ -var isVectorValid = function (vector) { - /** - * This function is used to scan the definitions file and join all - * abbreviations in a format that RegExp understands. - * - * Exit example: - * ((((((((((AV:[NALP]|AC:[LH])|PR:[NLH])|UI:[NR])|S:[UC])|C:[NLW])|I:[NLW])|A:[NLW])|E:[XUPFH])|RL:[XOTWU])|RC:[XURC]) - */ - var expression = definitions.definitions.reduce(function (accumulator, currentValue, index) { - var serializedAbbr = currentValue.abbr + ":[" + currentValue.metrics.reduce(function (accumulator2, currentValue2) { - return accumulator2 + currentValue2.abbr; - }, "") + "]"; - if (index !== 0) { - return "(" + accumulator + "|" + serializedAbbr + ")"; - } - else { - return serializedAbbr; - } - }, ""); - var totalExpressionVector = new RegExp("^CVSS:3.(0|1)(/" + expression + ")+$"); - //Checks if the vector is in valid format - if (!totalExpressionVector.test(vector)) { - return false; - } - /** - * Scans the definitions file and returns an array of each registered abbreviation - * with its possible values. - * - * Exit example: - * [/\/AV:[NALP]/g, /\/AC:[LH]/g, /\/PR:[NLH]/g, /\/UI:[NR]/g, /\/S:[UC]/g,] - * - * A / at the beginning serves for the algorithm not to confuse abbreviations as AC and C. - */ - var allExpressions = definitions.definitions.map(function (currentValue) { - return new RegExp("/" + currentValue.abbr + ":[" + currentValue.metrics.reduce(function (accumulator2, currentValue2) { - return accumulator2 + currentValue2.abbr; - }, "") + "]", "g"); - }); - for (var _i = 0, allExpressions_1 = allExpressions; _i < allExpressions_1.length; _i++) { - var regex = allExpressions_1[_i]; - if ((vector.match(regex) || []).length > 1) { - return false; - } - } - var mandatoryParams = [ - /\/AV:[NALP]/g, - /\/AC:[LH]/g, - /\/PR:[NLH]/g, - /\/UI:[NR]/g, - /\/S:[UC]/g, - /\/C:[NLH]/g, - /\/I:[NLH]/g, - /\/A:[NLH]/g - ]; - //Checks whether all mandatory parameters are present in the vector - for (var _a = 0, mandatoryParams_1 = mandatoryParams; _a < mandatoryParams_1.length; _a++) { - var regex = mandatoryParams_1[_a]; - if ((vector.match(regex) || []).length < 1) { - return false; - } - } - return true; -}; -/** - * This transforms an object in the format of getVectorObject() - * and parses it to a CVSS comaptible string - * - * @param {Object} obj - */ -function parseVectorObjectToString(obj) { - if (typeof obj === "string") { - return obj; - } - var vectorString = "CVSS:" + obj["CVSS"] + "/"; - for (var _i = 0, _a = definitions["definitions"]; _i < _a.length; _i++) { - var entry = _a[_i]; - var metric = entry["abbr"]; - if (Object.prototype.hasOwnProperty.call(obj, metric)) { - vectorString += metric + ":" + obj[metric] + "/"; - } - } - vectorString = vectorString.slice(0, -1); - return vectorString; -} -function updateVectorValue(vector, metric, value) { - var vectorObject = getVectorObject(vector); - vectorObject[metric] = value; - var vectorString = parseVectorObjectToString(vectorObject); - return getCleanVectorString(vectorString); -} -/** - * Retrives the version from the vector string - * - * @return {String} returns the version number - */ -function getVersion(vector) { - var version = vector.split("/"); - if (version[0] === "CVSS:3.0") { - return "3.0"; - } - else if (version[0] === "CVSS:3.1") { - return "3.1"; - } - else { - return "Error"; - } -} -module.exports = { - roundUpExact: roundUpExact, - roundUpApprox: roundUpApprox, - getVectorObject: getVectorObject, - getDetailedVectorObject: getDetailedVectorObject, - findMetric: findMetric, - findMetricValue: findMetricValue, - getRating: getRating, - updateVectorValue: updateVectorValue, - isVectorValid: isVectorValid, - parseVectorObjectToString: parseVectorObjectToString, - getVersion: getVersion, - getCleanVectorString: getCleanVectorString -}; diff --git a/lib/util.ts b/lib/util.ts index 83db55a..70ff089 100644 --- a/lib/util.ts +++ b/lib/util.ts @@ -1,51 +1,4 @@ -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; -}; - -type DetailedVectorObject = { metrics: DetailedMetric[]; CVSS: string }; - -type metric = { - name: string; - abbr: string; - numerical: number; -}; - -type Definition = { name: string; abbr: string; metrics: metric[] }; - -type CvssVersionDefinition = { - version: string; - definitions: Definition[]; -}; +import { CvssVectorObject, DetailedVectorObject, CvssVersionDefinition } from "./types"; const definitions: CvssVersionDefinition = require("./cvss_3_0.json"); @@ -72,6 +25,8 @@ const findMetricValue = function (abbr: string, vectorObject: CvssVectorObject) const definition = findMetric(abbr); const value = definition.metrics.find((metric) => metric.abbr === vectorObject[definition.abbr]); + console.log(typeof value.numerical); + return value; }; diff --git a/test/cvss.spec.js b/test/cvss.spec.js index 2ebb899..9a21812 100644 --- a/test/cvss.spec.js +++ b/test/cvss.spec.js @@ -1,4 +1,4 @@ -const CVSS = require("../lib/cvss"); +import { CVSS } from "../lib/cvss"; describe("Score Tests", () => { it("Should return the score", () => { @@ -34,7 +34,7 @@ describe("Score Tests", () => { RC: "X", RL: "X", S: "U", - UI: "N", + UI: "N" }); expect(vector5.getScore()).toBe(8.2); }); @@ -42,14 +42,10 @@ describe("Score Tests", () => { describe("Version Tests", () => { it("Should return the Version", () => { - const vector5 = 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" - ); + const vector5 = 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"); expect(vector5.getVersion()).toBe("3.0"); - const vector6 = CVSS( - "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R" - ); + const vector6 = CVSS("CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R"); expect(vector6.getVersion()).toBe("3.1"); const vector7 = () => { @@ -66,14 +62,10 @@ describe("Version Tests", () => { describe("Temporal Tests", () => { it("Should return the temporal score", () => { - const vector5 = 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" - ); + const vector5 = 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"); expect(vector5.getTemporalScore()).toBe(4.7); - const vector6 = CVSS( - "CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:F/RL:U/RC:X" - ); + const vector6 = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:F/RL:U/RC:X"); expect(vector6.getTemporalScore()).toBe(5.4); const vector7 = CVSS({ @@ -88,7 +80,7 @@ describe("Temporal Tests", () => { RC: "X", RL: "X", S: "U", - UI: "N", + UI: "N" }); expect(vector7.getTemporalScore()).toBe(8.2); }); @@ -227,7 +219,7 @@ describe("Vector Object Tests", () => { MS: "X", MC: "X", MI: "X", - MA: "X", + MA: "X" }); }); @@ -257,7 +249,7 @@ describe("Vector Object Tests", () => { MS: "X", MC: "X", MI: "X", - MA: "X", + MA: "X" }); }); }); @@ -315,19 +307,13 @@ describe("Check vector", () => { }); it("all tests must have the vectors in valid format", () => { - const vector = 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" - ); + const vector = 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"); expect(vector.isValid).toBe(true); - const vector2 = CVSS( - "CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R" - ); + const vector2 = CVSS("CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/E:U/RL:T/RC:R"); expect(vector2.isValid).toBe(true); - const vector3 = CVSS( - "CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:H/A:L/E:U/RL:T/RC:R" - ); + const vector3 = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:H/A:L/E:U/RL:T/RC:R"); expect(vector3.isValid).toBe(true); }); }); @@ -344,58 +330,58 @@ describe("Detailed Vector Object Tests", () => { abbr: "AV", fullName: "Attack Vector (AV)", value: "Network", - valueAbbr: "N", + valueAbbr: "N" }, AC: { name: "Attack Complexity", abbr: "AC", fullName: "Attack Complexity (AC)", value: "Low", - valueAbbr: "L", + valueAbbr: "L" }, PR: { name: "Privileges Required", abbr: "PR", fullName: "Privileges Required (PR)", value: "None", - valueAbbr: "N", + valueAbbr: "N" }, UI: { name: "User Interaction", abbr: "UI", fullName: "User Interaction (UI)", value: "None", - valueAbbr: "N", + valueAbbr: "N" }, S: { name: "Scope", abbr: "S", fullName: "Scope (S)", value: "Unchanged", - valueAbbr: "U", + valueAbbr: "U" }, C: { name: "Confidentiality", abbr: "C", fullName: "Confidentiality (C)", value: "High", - valueAbbr: "H", + valueAbbr: "H" }, I: { name: "Integrity", abbr: "I", fullName: "Integrity (I)", value: "High", - valueAbbr: "H", + valueAbbr: "H" }, A: { name: "Availability", abbr: "A", fullName: "Availability (A)", value: "High", - valueAbbr: "H", - }, - }, + valueAbbr: "H" + } + } }); }); @@ -410,58 +396,58 @@ describe("Detailed Vector Object Tests", () => { abbr: "AV", fullName: "Attack Vector (AV)", value: "Network", - valueAbbr: "N", + valueAbbr: "N" }, AC: { name: "Attack Complexity", abbr: "AC", fullName: "Attack Complexity (AC)", value: "High", - valueAbbr: "H", + valueAbbr: "H" }, PR: { name: "Privileges Required", abbr: "PR", fullName: "Privileges Required (PR)", value: "High", - valueAbbr: "H", + valueAbbr: "H" }, UI: { name: "User Interaction", abbr: "UI", fullName: "User Interaction (UI)", value: "Required", - valueAbbr: "R", + valueAbbr: "R" }, S: { name: "Scope", abbr: "S", fullName: "Scope (S)", value: "Unchanged", - valueAbbr: "U", + valueAbbr: "U" }, C: { name: "Confidentiality", abbr: "C", fullName: "Confidentiality (C)", value: "High", - valueAbbr: "H", + valueAbbr: "H" }, I: { name: "Integrity", abbr: "I", fullName: "Integrity (I)", value: "None", - valueAbbr: "N", + valueAbbr: "N" }, A: { name: "Availability", abbr: "A", fullName: "Availability (A)", value: "None", - valueAbbr: "N", - }, - }, + valueAbbr: "N" + } + } }); }); }); @@ -477,12 +463,10 @@ describe("Create vector from object", () => { S: "U", C: "H", I: "N", - A: "N", + A: "N" }; - expect(CVSS(vectorObject).vector).toBe( - "CVSS:3.0/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:N/A:N" - ); + expect(CVSS(vectorObject).vector).toBe("CVSS:3.0/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:N/A:N"); const vectorObject1 = { A: "N", @@ -496,7 +480,7 @@ describe("Create vector from object", () => { RC: "X", RL: "X", S: "U", - UI: "N", + UI: "N" }; expect(CVSS(vectorObject1).vector).toBe( @@ -526,7 +510,7 @@ describe("Create vector from object", () => { MS: "C", MC: "H", MI: "H", - MA: "H", + MA: "H" }; expect(CVSS(vectorObject).getScore()).toBe(7.1); @@ -541,14 +525,10 @@ describe("Clean Vector String Test", () => { CVSS( "CVSS:3.0/AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:H/A:N/E:P/RL:W/RC:X/CR:X/IR:X/AR:M/MAV:A/MAC:X/MPR:X/MUI:N/MS:X/MC:X/MI:X/MA:X" ).getCleanVectorString() - ).toBe( - "CVSS:3.0/AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:H/A:N/E:P/RL:W/AR:M/MAV:A/MUI:N" - ); + ).toBe("CVSS:3.0/AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:H/A:N/E:P/RL:W/AR:M/MAV:A/MUI:N"); expect( - CVSS( - "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" - ).getCleanVectorString() + CVSS("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").getCleanVectorString() ).toBe("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N"); expect( @@ -562,9 +542,7 @@ describe("Clean Vector String Test", () => { describe("Update Vector Value Test", () => { it("Should return the updated vector as string", () => { expect( - CVSS( - "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N/RL:X/RC:X" - ).updateVectorValue("AV", "L") + CVSS("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N/RL:X/RC:X").updateVectorValue("AV", "L") ).toBe("CVSS:3.0/AV:L/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N"); }); }); diff --git a/test/util.spec.js b/test/util.spec.js index ffb2c91..15948c1 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -1,13 +1,13 @@ -const util = require("../lib/util"); +import { util } from "../lib/util"; describe("roundUpExact Tests", () => { it("Should return the Number", () => { - expect(util.roundUpExact(0.1+0.2)).toBe(0.3); + expect(util.roundUpExact(0.1 + 0.2)).toBe(0.3); - expect(util.roundUpExact(0.6+0.2)).toBe(0.8); + expect(util.roundUpExact(0.6 + 0.2)).toBe(0.8); - expect(util.roundUpExact(0.4+0.2)).toBe(0.6); + expect(util.roundUpExact(0.4 + 0.2)).toBe(0.6); - expect(util.roundUpExact(0.8+0.2)).toBe(1); + expect(util.roundUpExact(0.8 + 0.2)).toBe(1); }); -}); \ No newline at end of file +}); diff --git a/tsconfig.json b/tsconfig.json index ae816bb..8a1d926 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "allowJs": true, "declaration": true, "emitDeclarationOnly": true, - "outDir": "dist" + "outDir": "dist", + "resolveJsonModule": true } }