From fc99308c588f094025818abfd36e3b75889ef613 Mon Sep 17 00:00:00 2001 From: Pulseline-Tech <166222062+Pulseline-Tech@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:01:37 +0000 Subject: [PATCH 1/2] feat: use undici --- package-lock.json | 11 ++++++- package.json | 7 +++-- src/utils.js | 78 +++++++++++++++++++++++------------------------ 3 files changed, 52 insertions(+), 44 deletions(-) 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/utils.js b/src/utils.js index 04c302d9..f6af0bd7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,45 +1,43 @@ -const punycode = require('punycode/') -const https = require('https') -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 punycode = require('punycode/'); +const { request } = require('undici'); + +const splitStringBy = (string, by) => [string.slice(0, by), string.slice(by + 1)]; + +const requestGetBody = async (url) => { + try { + const { body } = await request(url); + const data = await body.text(); + return data; + } catch (error) { + throw error; + } +}; const isTld = (tld) => { - if (tld.startsWith('.')) { - tld = tld.substring(1) - } + if (tld.startsWith('.')) { + tld = tld.substring(1); + } - return /^([a-z]{2,64}|xn[a-z0-9-]{5,})$/i.test(punycode.toASCII(tld)) -} + return /^([a-z]{2,64}|xn[a-z0-9-]{5,})$/i.test(punycode.toASCII(tld)); +}; const isDomain = (domain) => { - if (domain.endsWith('.')) { - domain = domain.substring(0, domain.length - 1) - } - - const labels = punycode.toASCII(domain).split('.').reverse() - const labelTest = /^([a-z0-9-]{1,64}|xn[a-z0-9-]{5,})$/i - - return ( - labels.length > 1 && - labels.every((label, index) => { - return index ? labelTest.test(label) && !label.startsWith('-') && !label.endsWith('-') : isTld(label) - }) - ) -} - -module.exports.splitStringBy = splitStringBy -module.exports.requestGetBody = requestGetBody -module.exports.isTld = isTld -module.exports.isDomain = isDomain + if (domain.endsWith('.')) { + domain = domain.substring(0, domain.length - 1); + } + + const labels = punycode.toASCII(domain).split('.').reverse(); + const labelTest = /^([a-z0-9-]{1,64}|xn[a-z0-9-]{5,})$/i; + + return ( + labels.length > 1 && + labels.every((label, index) => { + return index ? labelTest.test(label) && !label.startsWith('-') && !label.endsWith('-') : isTld(label); + }) + ); +}; + +module.exports.splitStringBy = splitStringBy; +module.exports.requestGetBody = requestGetBody; +module.exports.isTld = isTld; +module.exports.isDomain = isDomain; \ No newline at end of file From 43d1ed99f74816f908a4bc7d28e2a3529e77bb5f Mon Sep 17 00:00:00 2001 From: Pulseline-Tech <166222062+Pulseline-Tech@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:05:02 +0000 Subject: [PATCH 2/2] prettier --- src/parsers.js | 19 +++++++------- src/utils.js | 70 +++++++++++++++++++++++++------------------------- 2 files changed, 44 insertions(+), 45 deletions(-) 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 f6af0bd7..28bc3a71 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,43 +1,43 @@ -const punycode = require('punycode/'); -const { request } = require('undici'); +const punycode = require('punycode/') +const { request } = require('undici') -const splitStringBy = (string, by) => [string.slice(0, by), string.slice(by + 1)]; +const splitStringBy = (string, by) => [string.slice(0, by), string.slice(by + 1)] const requestGetBody = async (url) => { - try { - const { body } = await request(url); - const data = await body.text(); - return data; - } catch (error) { - throw error; - } -}; + try { + const { body } = await request(url) + const data = await body.text() + return data + } catch (error) { + throw error + } +} const isTld = (tld) => { - if (tld.startsWith('.')) { - tld = tld.substring(1); - } + if (tld.startsWith('.')) { + tld = tld.substring(1) + } - return /^([a-z]{2,64}|xn[a-z0-9-]{5,})$/i.test(punycode.toASCII(tld)); -}; + return /^([a-z]{2,64}|xn[a-z0-9-]{5,})$/i.test(punycode.toASCII(tld)) +} const isDomain = (domain) => { - if (domain.endsWith('.')) { - domain = domain.substring(0, domain.length - 1); - } - - const labels = punycode.toASCII(domain).split('.').reverse(); - const labelTest = /^([a-z0-9-]{1,64}|xn[a-z0-9-]{5,})$/i; - - return ( - labels.length > 1 && - labels.every((label, index) => { - return index ? labelTest.test(label) && !label.startsWith('-') && !label.endsWith('-') : isTld(label); - }) - ); -}; - -module.exports.splitStringBy = splitStringBy; -module.exports.requestGetBody = requestGetBody; -module.exports.isTld = isTld; -module.exports.isDomain = isDomain; \ No newline at end of file + if (domain.endsWith('.')) { + domain = domain.substring(0, domain.length - 1) + } + + const labels = punycode.toASCII(domain).split('.').reverse() + const labelTest = /^([a-z0-9-]{1,64}|xn[a-z0-9-]{5,})$/i + + return ( + labels.length > 1 && + labels.every((label, index) => { + return index ? labelTest.test(label) && !label.startsWith('-') && !label.endsWith('-') : isTld(label) + }) + ) +} + +module.exports.splitStringBy = splitStringBy +module.exports.requestGetBody = requestGetBody +module.exports.isTld = isTld +module.exports.isDomain = isDomain