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

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jul 12, 2021
1 parent af3c42e commit 337126b
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 129 deletions.
14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ function createPacResolver(
// The sandbox to use for the `vm` context.
const sandbox: Context = {
...createPacResolver.sandbox,
..._opts.sandbox
..._opts.sandbox,
};

const opts: createPacResolver.PacResolverOptions = {
filename: 'proxy.pac',
..._opts,
sandbox
sandbox,
};

// Construct the array of async function names to add `await` calls to.
const names = Object.keys(sandbox).filter(k => isAsyncFunction(sandbox[k]));
const names = Object.keys(sandbox).filter((k) =>
isAsyncFunction(sandbox[k])
);

// Compile the JS `FindProxyForURL()` function into an async function.
const resolver = compile<string, [url: string, host: string]>(
Expand Down Expand Up @@ -102,7 +104,7 @@ function createPacResolver(

Object.defineProperty(FindProxyForURL, 'toString', {
value: () => resolver.toString(),
enumerable: false
enumerable: false,
});

return FindProxyForURL;
Expand Down Expand Up @@ -199,7 +201,7 @@ namespace createPacResolver {
myIpAddress,
shExpMatch,
timeRange,
weekdayRange
weekdayRange,
});
}
export = createPacResolver;
Expand All @@ -208,7 +210,7 @@ function toCallback<T>(
promise: Promise<T>,
callback: (err: Error | null, result?: T) => void
): void {
promise.then(rtn => callback(null, rtn), callback);
promise.then((rtn) => callback(null, rtn), callback);
}

function isAsyncFunction(v: any): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/timeRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function timeRange(): boolean {

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

Expand Down
8 changes: 4 additions & 4 deletions test/dnsDomainIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
var assert = require('assert');
const { dnsDomainIs } = require('../').sandbox;

describe('dnsDomainIs(host, domain)', function() {
describe('dnsDomainIs(host, domain)', function () {
var tests = [
['www.netscape.com', '.netscape.com', true],
['www', '.netscape.com', false],
['www.mcom.com', '.netscape.com', false]
['www.mcom.com', '.netscape.com', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function() {
function () {
assert.equal(expected, dnsDomainIs(test[0], test[1]));
}
);
Expand Down
12 changes: 8 additions & 4 deletions test/dnsDomainLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
var assert = require('assert');
var { dnsDomainLevels } = require('../').sandbox;

describe('dnsDomainLevels(host)', function() {
var tests = [['www', 0], ['www.netscape', 1], ['www.netscape.com', 2]];
describe('dnsDomainLevels(host)', function () {
var tests = [
['www', 0],
['www.netscape', 1],
['www.netscape.com', 2],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function() {
function () {
assert.equal(expected, dnsDomainLevels(test[0]));
}
);
Expand Down
17 changes: 10 additions & 7 deletions test/dnsResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ var isIP = require('net').isIP;
var assert = require('assert');
var { dnsResolve } = require('../').sandbox;

describe('dnsResolve(host)', function() {
var tests = [['www.netscape.com', true], ['bogus.domain.foobar', false]];
describe('dnsResolve(host)', function () {
var tests = [
['www.netscape.com', true],
['bogus.domain.foobar', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
if (expected) {
it(
'should resolve an IPv4 address for "' +
test.join('", "') +
'"',
function(done) {
dnsResolve(test[0]).then(res => {
function (done) {
dnsResolve(test[0]).then((res) => {
assert.equal('string', typeof res);
assert.equal(4, isIP(res));
done();
Expand All @@ -29,8 +32,8 @@ describe('dnsResolve(host)', function() {
'should return null for if can\'t be resolved "' +
test.join('", "') +
'"',
function(done) {
dnsResolve(test[0]).then(res => {
function (done) {
dnsResolve(test[0]).then((res) => {
assert.equal(null, res);
done();
}, done);
Expand Down
10 changes: 5 additions & 5 deletions test/isInNet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
var assert = require('assert');
var { isInNet } = require('../').sandbox;

describe('isInNet(host, pattern, mask)', function() {
describe('isInNet(host, pattern, mask)', function () {
var tests = [
['198.95.249.79', '198.95.249.79', '255.255.255.255', true],
['198.95.249.78', '198.95.249.79', '255.255.255.255', false],
['198.95.1.1', '198.95.0.0', '255.255.0.0', true],
['198.94.1.1', '198.95.0.0', '255.255.0.0', false],
[null, '198.95.0.0', '255.255.0.0', false]
[null, '198.95.0.0', '255.255.0.0', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function(done) {
isInNet(test[0], test[1], test[2]).then(res => {
function (done) {
isInNet(test[0], test[1], test[2]).then((res) => {
assert.equal(expected, res);
done();
}, done);
Expand Down
11 changes: 7 additions & 4 deletions test/isPlainHostName.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
var assert = require('assert');
var { isPlainHostName } = require('../').sandbox;

describe('isPlainHostName(host)', function() {
var tests = [['www', true], ['www.netscape.com', false]];
describe('isPlainHostName(host)', function () {
var tests = [
['www', true],
['www.netscape.com', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function() {
function () {
assert.equal(expected, isPlainHostName(test[0]));
}
);
Expand Down
13 changes: 8 additions & 5 deletions test/isResolvable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
var assert = require('assert');
const { isResolvable } = require('../').sandbox;

describe('isResolvable(host)', function() {
var tests = [['www.netscape.com', true], ['bogus.domain.foobar', false]];
describe('isResolvable(host)', function () {
var tests = [
['www.netscape.com', true],
['bogus.domain.foobar', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function(done) {
isResolvable(test[0]).then(res => {
function (done) {
isResolvable(test[0]).then((res) => {
assert.equal(expected, res);
done();
}, done);
Expand Down
8 changes: 4 additions & 4 deletions test/localHostOrDomainIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
var assert = require('assert');
const { localHostOrDomainIs } = require('../').sandbox;

describe('localHostOrDomainIs(host, hostdom)', function() {
describe('localHostOrDomainIs(host, hostdom)', function () {
var tests = [
['www.netscape.com', 'www.netscape.com', true],
['www', 'www.netscape.com', true],
['www.mcom.com', 'www.netscape.com', false],
['home.netscape.com', 'www.netscape.com', false]
['home.netscape.com', 'www.netscape.com', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function() {
function () {
assert.equal(expected, localHostOrDomainIs(test[0], test[1]));
}
);
Expand Down
6 changes: 3 additions & 3 deletions test/myIpAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ var isIP = require('net').isIP;
var assert = require('assert');
var { myIpAddress } = require('../').sandbox;

describe('myIpAddress()', function() {
it('should return an IPv4 address', function(done) {
myIpAddress().then(ip => {
describe('myIpAddress()', function () {
it('should return an IPv4 address', function (done) {
myIpAddress().then((ip) => {
assert.equal(4, isIP(ip));
done();
}, done);
Expand Down
12 changes: 6 additions & 6 deletions test/shExpMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
var assert = require('assert');
var { shExpMatch } = require('../').sandbox;

describe('shExpMatch(str, shexp)', function() {
describe('shExpMatch(str, shexp)', function () {
var tests = [
['http://home.netscape.com/people/ari/index.html', '*/ari/*', true],
[
'http://home.netscape.com/people/montulli/index.html',
'*/ari/*',
false
false,
],
[
'http://home.example.com/people/yourpage/index.html',
'.*/mypage/.*',
false
false,
],
['www.hotmail.com', '*hotmail.com*', true],
['phishing-scam.com?email=someone@hotmail.com', '*hotmail.com*', true],
Expand All @@ -26,14 +26,14 @@ describe('shExpMatch(str, shexp)', function() {
['abcdomain.com', '*.n.com', false],
['a.com', '?.com', true],
['b.com', '?.com', true],
['ab.com', '?.com', false]
['ab.com', '?.com', false],
];

tests.forEach(function(test) {
tests.forEach(function (test) {
var expected = test.pop();
it(
'should return `' + expected + '` for "' + test.join('", "') + '"',
function() {
function () {
assert.equal(expected, shExpMatch(test[0], test[1]));
}
);
Expand Down
Loading

0 comments on commit 337126b

Please sign in to comment.