diff --git a/package-lock.json b/package-lock.json index 141685a1..0809ee0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.18.0", "license": "MIT", "dependencies": { - "punycode": "^2.1.1" + "punycode": "^2.1.1", + "undici": "^6.19.7" }, "devDependencies": { "mocha": "^10.1.0", @@ -864,6 +865,14 @@ "node": ">=8.0" } }, + "node_modules/undici": { + "version": "6.19.7", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz", + "integrity": "sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A==", + "engines": { + "node": ">=18.17" + } + }, "node_modules/workerpool": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz", diff --git a/package.json b/package.json index e7f412ea..9b7d82af 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "prettier": "^2.0.4" }, "dependencies": { - "punycode": "^2.1.1" + "punycode": "^2.1.1", + "undici": "^6.19.7" }, - "engines" : { - "node" : ">=15.0.0" + "engines": { + "node": ">=15.0.0" } } diff --git a/src/parsers.js b/src/parsers.js index a3f23436..348aa7dd 100644 --- a/src/parsers.js +++ b/src/parsers.js @@ -172,7 +172,7 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => { status: 'Domain Status', state: 'Domain Status', // found in .ru 'registration status': 'Domain Status', - 'eppstatus': 'Domain Status', // found in .fr + eppstatus: 'Domain Status', // found in .fr 'sponsoring registrar iana id': 'Registrar IANA ID', organisation: 'Registrar', registrar: 'Registrar', @@ -558,8 +558,8 @@ const handleJpLines = (lines) => { /** * Normalize WHOIS data for .fr ccTld, make it look more like gTLDs - * - * @param {string[]} lines + * + * @param {string[]} lines * @returns */ function handleDotFr(lines) { @@ -568,7 +568,7 @@ function handleDotFr(lines) { const finalLines = [] // split data in groups - lines.forEach(line => { + lines.forEach((line) => { if (line.startsWith('%')) { finalLines.push(line) } else if (!line.trim().length && group.length) { @@ -576,7 +576,7 @@ function handleDotFr(lines) { groups.push(group) group = [] } else if (line.trim().length && !line.startsWith('source')) { - group.push(splitStringBy(line, line.indexOf(':')).map(str => str.trim())) + group.push(splitStringBy(line, line.indexOf(':')).map((str) => str.trim())) } }) @@ -584,10 +584,10 @@ function handleDotFr(lines) { groups.push(group) } - groups.forEach(gr => { + groups.forEach((gr) => { if (gr[0][0] === 'domain') { // group with domain info - gr.forEach(line => { + gr.forEach((line) => { if (line[0] !== 'status') { finalLines.push(line.join(': ')) } @@ -603,7 +603,7 @@ function handleDotFr(lines) { }) } else if (gr[0][0] === 'nic-hdl') { let contactType = '' - const contactTypeLine = finalLines.find(line => line.includes(gr[0][1])) + const contactTypeLine = finalLines.find((line) => line.includes(gr[0][1])) if (contactTypeLine.startsWith('admin-c')) { contactType = 'admin' @@ -622,11 +622,10 @@ function handleDotFr(lines) { } }) } else { - gr.forEach(line => { + gr.forEach((line) => { finalLines.push(line.join(': ')) }) } - }) return finalLines diff --git a/src/utils.js b/src/utils.js index 04c302d9..28bc3a71 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,18 +1,16 @@ const punycode = require('punycode/') -const https = require('https') +const { request } = require('undici') + const splitStringBy = (string, by) => [string.slice(0, by), string.slice(by + 1)] -const requestGetBody = (url) => { - return new Promise((resolve, reject) => { - https - .get(url, (resp) => { - let data = '' - resp.on('data', (chunk) => (data += chunk)) - resp.on('end', () => resolve(data)) - resp.on('error', reject) - }) - .on('error', reject) - }) +const requestGetBody = async (url) => { + try { + const { body } = await request(url) + const data = await body.text() + return data + } catch (error) { + throw error + } } const isTld = (tld) => {