Skip to content

Commit 67e7889

Browse files
committed
fix eslint issues.
1 parent 5aa630f commit 67e7889

File tree

5 files changed

+26
-3977
lines changed

5 files changed

+26
-3977
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

22
yarn.lock
3+
package-lock.json
34

45
node_modules

client/doh.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ const http2 = require('http2');
44
const Packet = require('../packet');
55

66
const protocols = {
7-
'http:': http.get,
8-
'https:': https.get,
9-
'h2:': (url, options, cb) => {
7+
'http:' : http.get,
8+
'https:' : https.get,
9+
'h2:' : (url, options, done) => {
1010
const urlObj = new URL(url);
1111
const client = http2.connect(url.replace('h2:', 'https:'));
1212
const req = client.request({
13-
':path': `${urlObj.pathname}${urlObj.search}`,
14-
':method': 'GET',
15-
...options.headers
13+
':path' : `${urlObj.pathname}${urlObj.search}`,
14+
':method' : 'GET',
15+
...options.headers,
1616
});
1717

1818
req.on('response', headers => {
1919
client.close();
20-
cb({
20+
done({
2121
headers,
22-
statusCode: headers[':status'],
23-
on: req.on.bind(req)
22+
statusCode : headers[':status'],
23+
on : req.on.bind(req),
2424
});
2525
});
2626

@@ -30,7 +30,7 @@ const protocols = {
3030
});
3131

3232
req.end();
33-
}
33+
},
3434
};
3535

3636
const makeRequest = (url, query) => new Promise((resolve, reject) => {
@@ -65,7 +65,7 @@ const buildQuery = ({ name, type = 'A', cls = Packet.CLASS.IN, clientIp, recursi
6565

6666
if (clientIp) {
6767
packet.additionals.push(Packet.Resource.EDNS([
68-
Packet.Resource.EDNS.ECS(clientIp)
68+
Packet.Resource.EDNS.ECS(clientIp),
6969
]));
7070
}
7171

@@ -74,12 +74,12 @@ const buildQuery = ({ name, type = 'A', cls = Packet.CLASS.IN, clientIp, recursi
7474
};
7575

7676
const DOHClient = ({ dns }) => {
77-
return async (name, type, cls, options = {}) => {
77+
return async(name, type, cls, options = {}) => {
7878
const query = buildQuery({ name, type, cls, ...options });
7979
const response = await makeRequest(dns, query);
8080
const data = await readStream(response);
8181
return Packet.parse(data);
8282
};
8383
};
8484

85-
module.exports = DOHClient;
85+
module.exports = DOHClient;

client/tcp.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@ const Packet = require('../packet');
55
const makeQuery = ({ name, type = 'A', cls = Packet.CLASS.IN, clientIp, recursive = true }) => {
66
const packet = new Packet();
77
packet.header.rd = recursive ? 1 : 0;
8-
8+
99
if (clientIp) {
1010
packet.additionals.push(Packet.Resource.EDNS([
11-
Packet.Resource.EDNS.ECS(clientIp)
11+
Packet.Resource.EDNS.ECS(clientIp),
1212
]));
1313
}
14-
14+
1515
packet.questions.push({ name, class: cls, type: Packet.TYPE[type] });
1616
return packet.toBuffer();
1717
};
1818

1919
const sendQuery = (client, message) => {
2020
const len = Buffer.alloc(2);
2121
len.writeUInt16BE(message.length);
22-
client.end(Buffer.concat([len, message]));
22+
client.end(Buffer.concat([ len, message ]));
2323
};
2424

2525
const protocols = {
26-
'tcp:': (host, port) => tcp.connect({ host, port }),
27-
'tls:': (host, port) => tls.connect({ host, port, servername: host })
26+
'tcp:' : (host, port) => tcp.connect({ host, port }),
27+
'tls:' : (host, port) => tls.connect({ host, port, servername: host }),
2828
};
2929

3030
const TCPClient = ({ dns, protocol = 'tcp:', port = protocol === 'tls:' ? 853 : 53 } = {}) => {
3131
if (!protocols[protocol]) {
3232
throw new Error('Protocol must be tcp: or tls:');
3333
}
3434

35-
return async (name, type, cls, options = {}) => {
35+
return async(name, type, cls, options = {}) => {
3636
const message = makeQuery({ name, type, cls, ...options });
37-
const [host] = dns.split(':');
37+
const [ host ] = dns.split(':');
3838
const client = protocols[protocol](host, port);
39-
39+
4040
sendQuery(client, message);
4141
const data = await Packet.readStream(client);
42-
42+
4343
if (!data.length) throw new Error('Empty response');
4444
return Packet.parse(data);
4545
};
4646
};
4747

48-
module.exports = TCPClient;
48+
module.exports = TCPClient;

example/client/doh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ const { DOHClient } = require('../..');
1919

2020
DOHClient({
2121
dns: 'h2://ada.openbld.net/dns-query?dns={query}',
22-
})('cdnjs.com', 'NS').then(console.log);
22+
})('cdnjs.com', 'NS').then(console.log);

0 commit comments

Comments
 (0)