From 94dbdc09cb1e0678354844c287979b4362dda672 Mon Sep 17 00:00:00 2001 From: Felix Wotschofsky Date: Wed, 20 Dec 2023 23:07:27 +0100 Subject: [PATCH] =?UTF-8?q?Support=20TLDs=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/RelatedDomains.tsx | 13 ++++++++++--- components/SearchForm.tsx | 2 +- components/WhoisQuickInfo.tsx | 3 ++- package.json | 1 - pnpm-lock.yaml | 9 --------- utils/isValidDomain.ts | 3 +++ 6 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 utils/isValidDomain.ts diff --git a/components/RelatedDomains.tsx b/components/RelatedDomains.tsx index 8809279..272d916 100644 --- a/components/RelatedDomains.tsx +++ b/components/RelatedDomains.tsx @@ -9,19 +9,26 @@ type RelatedDomainsProps = { domain: string; }; -const RelatedDomains: FC = ({ domain: original }) => { +const getRecommendations = (original: string) => { const domains = []; const splitOriginal = original.split('.'); - for (let i = 1; i < splitOriginal.length - 1; i++) { + for (let i = 0; i < splitOriginal.length; i++) { const domain = splitOriginal.slice(i).join('.'); + if (domain === original) continue; domains.push(domain); } - if (!original.startsWith('www.')) { + if (!original.startsWith('www.') && splitOriginal.length >= 2) { domains.unshift(`www.${original}`); } + return domains; +}; + +const RelatedDomains: FC = ({ domain: original }) => { + const domains = getRecommendations(original); + return (
{domains.map((domain) => ( diff --git a/components/SearchForm.tsx b/components/SearchForm.tsx index 7a7f62e..3247510 100644 --- a/components/SearchForm.tsx +++ b/components/SearchForm.tsx @@ -1,6 +1,5 @@ 'use client'; -import isValidDomain from 'is-valid-domain'; import { Loader2 } from 'lucide-react'; import { usePathname, useRouter } from 'next/navigation'; import { toASCII } from 'punycode'; @@ -10,6 +9,7 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { cn } from '@/lib/utils'; +import isValidDomain from '@/utils/isValidDomain'; enum FormStates { Initial, diff --git a/components/WhoisQuickInfo.tsx b/components/WhoisQuickInfo.tsx index 2b70d5f..29c3a1d 100644 --- a/components/WhoisQuickInfo.tsx +++ b/components/WhoisQuickInfo.tsx @@ -1,7 +1,8 @@ -import isValidDomain from 'is-valid-domain'; import { FC } from 'react'; import whoiser, { type WhoisSearchResult } from 'whoiser'; +import isValidDomain from '@/utils/isValidDomain'; + import { Skeleton } from './ui/skeleton'; type WhoisQuickInfoProps = { diff --git a/package.json b/package.json index ba53a1e..9724a6f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "clsx": "^2.0.0", "dataloader": "^2.2.2", "dns-packet": "^5.6.1", - "is-valid-domain": "^0.1.6", "leaflet": "^1.9.4", "leaflet-defaulticon-compatibility": "^0.1.2", "lucide-react": "^0.294.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d98664..2d4188f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,9 +50,6 @@ dependencies: dns-packet: specifier: ^5.6.1 version: 5.6.1 - is-valid-domain: - specifier: ^0.1.6 - version: 0.1.6 leaflet: specifier: ^1.9.4 version: 1.9.4 @@ -4083,12 +4080,6 @@ packages: which-typed-array: 1.1.13 dev: true - /is-valid-domain@0.1.6: - resolution: {integrity: sha512-ZKtq737eFkZr71At8NxOFcP9O1K89gW3DkdrGMpp1upr/ueWjj+Weh4l9AI4rN0Gt8W2M1w7jrG2b/Yv83Ljpg==} - dependencies: - punycode: 2.3.1 - dev: false - /is-weakmap@2.0.1: resolution: {integrity: sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA==} dev: true diff --git a/utils/isValidDomain.ts b/utils/isValidDomain.ts new file mode 100644 index 0000000..af2ccf6 --- /dev/null +++ b/utils/isValidDomain.ts @@ -0,0 +1,3 @@ +const isValidDomain = (domain: string) => /^(((?!-))(xn--|_)?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*(xn--)?([a-z0-9][a-z0-9\-]{0,60}|[a-z0-9-]{1,30}\.[a-z]{2,})$/.test(domain) + +export default isValidDomain