Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Updated all dependencies and fixed linting errors, removed unused pac…
Browse files Browse the repository at this point in the history
…kages (#29)
  • Loading branch information
Havunen authored May 25, 2022
1 parent 0439ff2 commit 0beb8e5
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 54 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
'import/no-extraneous-dependencies': 0,
'import/prefer-default-export': 0,
'lines-between-class-members': 0,
'import/extensions': 0,
'no-await-in-loop': 0,
'no-bitwise': 0,
'no-console': 0,
Expand All @@ -57,17 +58,16 @@ module.exports = {
// '@typescript-eslint/indent': ['error', 2] // this might conflict with a lot ongoing changes
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/interface-name-prefix': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/naming-convention': 'error',
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-parameter-properties': 'error',
'@typescript-eslint/no-triple-slash-reference': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/type-annotation-spacing': 'error'
'@typescript-eslint/type-annotation-spacing': 'error',
// '@typescript-eslint/array-type': 'error',
// '@typescript-eslint/ban-types': 'error',
// '@typescript-eslint/explicit-function-return-type': 'warn',
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/node_modules
/?.?s
/*.pac
.idea
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,25 @@
"dist"
],
"dependencies": {
"degenerator": "^3.0.1",
"degenerator": "^3.0.2",
"ip": "^1.1.5",
"netmask": "^2.0.1"
"netmask": "^2.0.2"
},
"devDependencies": {
"@types/debug": "4",
"@types/ip": "^1.1.0",
"@types/netmask": "^1.0.30",
"@types/node": "^12.12.11",
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.1.0",
"eslint": "5.16.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "4.1.0",
"eslint-import-resolver-typescript": "1.1.1",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"mocha": "^6.2.2",
"rimraf": "^3.0.0",
"typescript": "^4.3.5"
"@types/node": "^17.0.19",
"@typescript-eslint/eslint-plugin": "5.12.0",
"@typescript-eslint/parser": "5.12.0",
"eslint": "^8.9.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "8.4.0",
"eslint-import-resolver-typescript": "2.5.0",
"eslint-plugin-import": "2.25.4",
"mocha": "^9.2.1",
"rimraf": "^3.0.2",
"typescript": "^4.5.5"
},
"scripts": {
"prebuild": "rimraf dist",
Expand Down
4 changes: 2 additions & 2 deletions src/dnsDomainLevels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* @return {Number} number of domain levels
*/
export default function dnsDomainLevels(host: string): number {
var match = String(host).match(/\./g);
var levels = 0;
const match = String(host).match(/\./g);
let levels = 0;
if (match) {
levels = match.length;
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function createPacResolver(
opts
);

/* eslint-disable @typescript-eslint/naming-convention, no-redeclare */
function FindProxyForURL(url: string, host?: string): Promise<string>;
function FindProxyForURL(
url: string,
Expand Down Expand Up @@ -110,6 +111,7 @@ function createPacResolver(
return FindProxyForURL;
}

// eslint-disable-next-line @typescript-eslint/no-namespace
namespace createPacResolver {
export type GMT = 'GMT';
export type Hour =
Expand Down Expand Up @@ -189,7 +191,7 @@ namespace createPacResolver {
}
export type FindProxyForURL = ReturnType<typeof createPacResolver>;
export const sandbox: Readonly<Context> = Object.freeze({
alert: (message: string = '') => console.log('%s', message),
alert: (message = '') => console.log('%s', message),
dateRange,
dnsDomainIs,
dnsDomainLevels,
Expand Down
8 changes: 4 additions & 4 deletions src/myIpAddress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ip from 'ip';
import net from 'net';
import net, {AddressInfo} from 'net';

/**
* Returns the IP address of the host that the Navigator is running on, as
Expand All @@ -20,7 +20,7 @@ export default async function myIpAddress(): Promise<string> {
// 8.8.8.8:53 is "Google Public DNS":
// https://developers.google.com/speed/public-dns/
const socket = net.connect({ host: '8.8.8.8', port: 53 });
const onError = (err: Error) => {
const onError = () => {
// if we fail to access Google DNS (as in firewall blocks access),
// fallback to querying IP locally
resolve(ip.address());
Expand All @@ -32,8 +32,8 @@ export default async function myIpAddress(): Promise<string> {
socket.destroy();
if (typeof addr === 'string') {
resolve(addr);
} else if (addr.address) {
resolve(addr.address);
} else if ((addr as AddressInfo).address) {
resolve((addr as AddressInfo).address);
} else {
reject(new Error('Expected a `string`'));
}
Expand Down
4 changes: 2 additions & 2 deletions src/shExpMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

export default function shExpMatch(str: string, shexp: string): boolean {
var re = toRegExp(shexp);
const re = toRegExp(shexp);
return re.test(str);
}

Expand All @@ -36,5 +36,5 @@ function toRegExp(str: string): RegExp {
.replace(/\./g, '\\.')
.replace(/\?/g, '.')
.replace(/\*/g, '.*');
return new RegExp('^' + str + '$');
return new RegExp(`^${str}$`);
}
29 changes: 14 additions & 15 deletions src/timeRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,31 @@
*/

export default function timeRange(): boolean {
var args = Array.prototype.slice.call(arguments),
lastArg = args.pop(),
useGMTzone = lastArg == 'GMT',
currentDate = new Date();
// eslint-disable-next-line prefer-rest-params
const args = Array.prototype.slice.call(arguments);
const lastArg = args.pop();
const useGMTzone = lastArg === 'GMT';
const currentDate = new Date();

if (!useGMTzone) {
args.push(lastArg);
}

var noOfArgs = args.length,
result = false,
numericArgs = args.map(function (n) {
return parseInt(n);
});
const noOfArgs = args.length;
let result = false;
let numericArgs = args.map((n) => parseInt(n, 10));

// timeRange(hour)
if (noOfArgs == 1) {
result = getCurrentHour(useGMTzone, currentDate) == numericArgs[0];
if (noOfArgs === 1) {
result = getCurrentHour(useGMTzone, currentDate) === numericArgs[0];

// timeRange(hour1, hour2)
} else if (noOfArgs == 2) {
var currentHour = getCurrentHour(useGMTzone, currentDate);
} else if (noOfArgs === 2) {
const currentHour = getCurrentHour(useGMTzone, currentDate);
result = numericArgs[0] <= currentHour && currentHour < numericArgs[1];

// timeRange(hour1, min1, hour2, min2)
} else if (noOfArgs == 4) {
} else if (noOfArgs === 4) {
result = valueInRange(
secondsElapsedToday(numericArgs[0], numericArgs[1], 0),
secondsElapsedToday(
Expand All @@ -78,7 +77,7 @@ export default function timeRange(): boolean {
);

// timeRange(hour1, min1, sec1, hour2, min2, sec2)
} else if (noOfArgs == 6) {
} else if (noOfArgs === 6) {
result = valueInRange(
secondsElapsedToday(numericArgs[0], numericArgs[1], numericArgs[2]),
secondsElapsedToday(
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GMT } from './index';
import { LookupAddress, LookupOptions, lookup } from 'dns';
import { GMT } from './index';

export function dnsLookup(
host: string,
Expand Down
17 changes: 8 additions & 9 deletions src/weekdayRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,18 @@ export default function weekdayRange(
}

let todaysDay = getTodaysDay(useGMTzone);
let result = false;
let result: boolean;

if (wd2Index < 0) {
result = todaysDay == wd1Index;
result = todaysDay === wd1Index;
} else if (wd1Index <= wd2Index) {
result = valueInRange(wd1Index, todaysDay, wd2Index);
} else {
if (wd1Index <= wd2Index) {
result = valueInRange(wd1Index, todaysDay, wd2Index);
} else {
result =
valueInRange(wd1Index, todaysDay, 6) ||
valueInRange(0, todaysDay, wd2Index);
}
result =
valueInRange(wd1Index, todaysDay, 6) ||
valueInRange(0, todaysDay, wd2Index);
}

return result;
}

Expand Down

0 comments on commit 0beb8e5

Please sign in to comment.