Skip to content

Commit

Permalink
Support TLDs 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
wotschofsky committed Dec 20, 2023
1 parent beb6b7a commit 94dbdc0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
13 changes: 10 additions & 3 deletions components/RelatedDomains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ type RelatedDomainsProps = {
domain: string;
};

const RelatedDomains: FC<RelatedDomainsProps> = ({ 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<RelatedDomainsProps> = ({ domain: original }) => {
const domains = getRecommendations(original);

return (
<div className="my-4 flex flex-wrap gap-4">
{domains.map((domain) => (
Expand Down
2 changes: 1 addition & 1 deletion components/SearchForm.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion components/WhoisQuickInfo.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions utils/isValidDomain.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 94dbdc0

Please sign in to comment.