diff --git a/.eslintrc.json b/.eslintrc.json index 3def3cb..2534a29 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,38 +21,55 @@ "rules": { "no-console": "off", "linebreak-style": "off", - "camelcase": [ - "warn", - { - "properties": "never", - "ignoreImports": true - } - ], - "no-unused-vars": [ - "warn", - { - "args": "none" - } - ], - "quotes": [ - "error", - "double", - { - "allowTemplateLiterals": true - } - ], - "object-curly-spacing": [ - "error", - "always" - ], - "keyword-spacing": [ - "error", - { - "before": true - } - ], - "space-before-blocks": [ - "error" - ] + "camelcase": [ "warn", { + "properties": "never", + "ignoreImports": true + }], + "no-unused-vars": [ "warn", { + "args": "none" + }], + "quotes": [ "error", "double", { + "allowTemplateLiterals": true + }], + "array-bracket-spacing": [ "warn", "always", { + "singleValue": true, + "objectsInArrays": false, + "arraysInArrays": false + }], + "space-before-function-paren": [ "error", { + "anonymous": "always", + "named": "never", + "asyncArrow": "always" + }], + "object-curly-spacing": [ "error", "always" ], + "object-property-newline": "error", + "brace-style": "error", + "no-var": "error", + "keyword-spacing": [ "error", { + "before": true + }], + "arrow-spacing": "warn", + "no-constant-condition": [ "error", { + "checkLoops": false + }], + "space-before-blocks": [ "error" ], + "no-multiple-empty-lines": [ "warn", { + "max": 1, + "maxBOF": 0 + }], + "lines-between-class-members": [ "warn", "always", { + "exceptAfterSingleLine": true + }], + "no-unneeded-ternary": "error", + "array-bracket-newline": [ "error", "consistent" ], + "eol-last": [ "error", "always" ], + "comma-dangle": [ "warn", "only-multiline" ], + "no-empty": [ "error", { + "allowEmptyCatch": true + }], + "one-var": [ "error", "never" ], + "max-statements-per-line": [ "error", { + "max": 1 + }] } } diff --git a/src/Cloudflare.ts b/src/Cloudflare.ts index 83db731..5a6f1d9 100644 --- a/src/Cloudflare.ts +++ b/src/Cloudflare.ts @@ -4,7 +4,6 @@ import { createRequest } from "./helpers/UrllibHelper"; import { avg, convertUnits, getDistance, getQuartile, jitter, sortObject } from "./Utils"; import { SpeedUnits } from "./index"; - export class Cloudflare { private readonly options: CloudflareOptions; private readonly result: CloudflareResult = {} as CloudflareResult; @@ -14,18 +13,19 @@ export class Cloudflare { private clientLon: number; private readonly tests = { download: [ - [101000, 10], - [1001000, 8], - [10001000, 6], - [25001000, 4], - [100001000, 1] + [ 101000, 10 ], + [ 1001000, 8 ], + [ 10001000, 6 ], + [ 25001000, 4 ], + [ 100001000, 1 ] ], upload: [ - [11000, 10], - [101000, 10], - [1001000, 8] + [ 11000, 10 ], + [ 101000, 10 ], + [ 1001000, 8 ] ] } + private servers = {}; private bestServer; @@ -172,7 +172,7 @@ export class Cloudflare { times.push(total); }); } - return [Number(avg(times).toFixed(3)), Number(jitter(times).toFixed(3))]; + return [ Number(avg(times).toFixed(3)), Number(jitter(times).toFixed(3)) ]; } catch { throw new Error("An error occurred while measuring latency."); } diff --git a/src/Speedtest.ts b/src/Speedtest.ts index 6427967..43816ab 100644 --- a/src/Speedtest.ts +++ b/src/Speedtest.ts @@ -7,7 +7,6 @@ import { convertUnits, getDistance, jitter, sortObject, sum } from "./Utils"; import { HTTPUploaderData } from "./helpers/HTTPUploaderData"; import { SpeedUnits } from "./index"; - export class Speedtest { private readonly options: SpeedtestOptions; private readonly result: SpeedtestResult = {} as SpeedtestResult; @@ -15,7 +14,7 @@ export class Speedtest { private testConfig; private clientLat: number; private clientLon: number; - private readonly uploadSizes = [32768, 65536, 131072, 262144, 524288, 1048576, 7340032]; + private readonly uploadSizes = [ 32768, 65536, 131072, 262144, 524288, 1048576, 7340032 ]; private servers = {}; private fastestServer; @@ -108,8 +107,8 @@ export class Speedtest { const sizes = { "upload": this.uploadSizes.slice(uploadRatio - 1, this.uploadSizes.length), - "download": [350, 500, 750, 1000, 1500, 2000, 2500, - 3000, 3500, 4000] + "download": [ 350, 500, 750, 1000, 1500, 2000, 2500, + 3000, 3500, 4000 ] }; const uploadSizeCount = sizes["upload"].length; @@ -176,7 +175,7 @@ export class Speedtest { const distance = getDistance(this.clientLat, this.clientLon, Number(server.$.lat), Number(server.$.lon)); server.$.distance = distance; - this.servers[distance] = [server.$]; + this.servers[distance] = [ server.$ ]; }); } catch (e) { throw new Error("Error getting server list"); @@ -264,7 +263,7 @@ export class Speedtest { const requestCount = urls.length; const requests = []; urls.forEach((url, i) => { - requests.push([url, this.options.secure, i.toString(), (this.options.wait) ? this.options.timeout : this.testConfig.length.download]); + requests.push([ url, this.options.secure, i.toString(), (this.options.wait) ? this.options.timeout : this.testConfig.length.download ]); }); const maxThreads = this.testConfig.threads.download; @@ -340,7 +339,7 @@ export class Speedtest { const data = new HTTPUploaderData(size); data.preAllocate(); - requests.push([this.fastestServer.url, headers, this.options.secure, data.read(size), i.toString(), (this.options.wait) ? this.options.timeout : this.testConfig.length.upload, data.total]); + requests.push([ this.fastestServer.url, headers, this.options.secure, data.read(size), i.toString(), (this.options.wait) ? this.options.timeout : this.testConfig.length.upload, data.total ]); }); const maxThreads = this.testConfig.threads.upload; diff --git a/src/UniversalSpeedTest.ts b/src/UniversalSpeedTest.ts index bb33e09..6a751e5 100644 --- a/src/UniversalSpeedTest.ts +++ b/src/UniversalSpeedTest.ts @@ -153,7 +153,6 @@ export class UniversalSpeedtest { } } - interface UniversalSpeedTestOptions { /** Display debug messages. */ debug?: boolean, diff --git a/src/Utils.ts b/src/Utils.ts index 1ab97e8..8f99f83 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -102,4 +102,4 @@ export function sum(arr): number { export function convertUnits(actualUnit: string, newUnit: string, speed: number): number { const convert = configureMeasurements(allMeasures); return convert(speed).from(actualUnit.slice(0, -2)).to(newUnit.slice(0, -2)); -} \ No newline at end of file +} diff --git a/src/helpers/HTTPDownloader.ts b/src/helpers/HTTPDownloader.ts index 4c6741b..8667d5d 100644 --- a/src/helpers/HTTPDownloader.ts +++ b/src/helpers/HTTPDownloader.ts @@ -28,4 +28,4 @@ export class HTTPDownloader { return results; } -} \ No newline at end of file +} diff --git a/src/helpers/HTTPUploader.ts b/src/helpers/HTTPUploader.ts index 15bdd6f..6661241 100644 --- a/src/helpers/HTTPUploader.ts +++ b/src/helpers/HTTPUploader.ts @@ -22,4 +22,4 @@ export class HTTPUploader { await this.request; return sum(this.total); } -} \ No newline at end of file +} diff --git a/src/helpers/HTTPUploaderData.ts b/src/helpers/HTTPUploaderData.ts index a9fcc7d..08f3e04 100644 --- a/src/helpers/HTTPUploaderData.ts +++ b/src/helpers/HTTPUploaderData.ts @@ -10,7 +10,7 @@ export class HTTPUploaderData { constructor(length) { this.length = length; this._data = null; - this._total = [0]; + this._total = [ 0 ]; } /** @@ -43,4 +43,4 @@ export class HTTPUploaderData { this._total.push(chunk.length); return chunk; } -} \ No newline at end of file +} diff --git a/src/thread_workers/download_worker.js b/src/thread_workers/download_worker.js index 01dd345..648af4c 100644 --- a/src/thread_workers/download_worker.js +++ b/src/thread_workers/download_worker.js @@ -5,4 +5,4 @@ const { workerData } = require("worker_threads"); // eslint-disable-next-line @typescript-eslint/no-var-requires require("ts-node").register(); -require(path.resolve(__dirname, workerData.path)); \ No newline at end of file +require(path.resolve(__dirname, workerData.path)); diff --git a/src/thread_workers/download_worker.ts b/src/thread_workers/download_worker.ts index d8ad701..46b55a7 100644 --- a/src/thread_workers/download_worker.ts +++ b/src/thread_workers/download_worker.ts @@ -10,4 +10,4 @@ if (wait || (((performance.now() - startTime) / 1000) <= timeout)) { thread.run().then(result => { parentPort.postMessage(result); }); -} else parentPort.postMessage([0]); +} else parentPort.postMessage([ 0 ]); diff --git a/src/thread_workers/upload_worker.js b/src/thread_workers/upload_worker.js index 01dd345..648af4c 100644 --- a/src/thread_workers/upload_worker.js +++ b/src/thread_workers/upload_worker.js @@ -5,4 +5,4 @@ const { workerData } = require("worker_threads"); // eslint-disable-next-line @typescript-eslint/no-var-requires require("ts-node").register(); -require(path.resolve(__dirname, workerData.path)); \ No newline at end of file +require(path.resolve(__dirname, workerData.path)); diff --git a/tests/Cloudflare.test.ts b/tests/Cloudflare.test.ts index d248027..0e709df 100644 --- a/tests/Cloudflare.test.ts +++ b/tests/Cloudflare.test.ts @@ -12,4 +12,4 @@ describe("Cloudflare test", () => { expect(result.uploadSpeed).not.to.be.undefined; expect(result.downloadSpeed).to.be.above(20); }).timeout(120000); -}); \ No newline at end of file +}); diff --git a/tests/Speedtest.test.ts b/tests/Speedtest.test.ts index 71df062..2381826 100644 --- a/tests/Speedtest.test.ts +++ b/tests/Speedtest.test.ts @@ -12,4 +12,4 @@ describe("Speedtest test", () => { expect(result.uploadSpeed).to.be.undefined; expect(result.downloadSpeed).to.be.above(20); }).timeout(120000); -}); \ No newline at end of file +});