Skip to content

Full Toolkit for Next-Level Domain Analysis

Always return getBaseDomain in lowercase 🔡 (#147)

Felix Wotschofsky2ad763154ef7
diff --git a/lib/for-sale.ts b/lib/for-sale.ts
index 2e7a0d9..1a8bdfb 100644
--- a/lib/for-sale.ts
+++ b/lib/for-sale.ts
@@ -192,7 +192,7 @@ export const lookupForSale = async (
): Promise<ForSaleSummary> => {
if (!isValidDomain(domain)) throw new Error('Invalid domain');
- const baseDomain = getBaseDomain(domain).toLowerCase();
+ const baseDomain = getBaseDomain(domain);
if (baseDomain === 'arpa' || baseDomain.endsWith('.arpa'))
return { domain: baseDomain, listing: null };
diff --git a/lib/utils.test.ts b/lib/utils.test.ts
index d4d7179..9394031 100644
--- a/lib/utils.test.ts
+++ b/lib/utils.test.ts
@@ -159,6 +159,13 @@ describe('getBaseDomain', () => {
expect(getBaseDomain('xn--fiqs8s')).toBe('xn--fiqs8s');
expect(getBaseDomain('com')).toBe('com');
});
+
+ it('always returns lowercase, including when no base domain is found', () => {
+ expect(getBaseDomain('WWW.Example.COM')).toBe('example.com');
+ expect(getBaseDomain('*.Example.COM.')).toBe('example.com');
+ expect(getBaseDomain('COM')).toBe('com');
+ expect(getBaseDomain('ARPA')).toBe('arpa');
+ });
});
describe('isWildcardDomain', () => {
diff --git a/lib/utils.ts b/lib/utils.ts
index 7ac09e0..dc5e67d 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -97,9 +97,11 @@ export const isValidDomain = (domain: string) => {
export const getBaseDomain = (domain: string) => {
// Remove wildcard prefix to avoid base domain not being extracted correctly
// Remove trailing dot
- const cleanedDomain = domain.replace(/^\*\./, '').replace(/\.$/, '');
- const baseDomain = getDomain(cleanedDomain) || cleanedDomain;
- return baseDomain;
+ const cleanedDomain = domain
+ .replace(/^\*\./, '')
+ .replace(/\.$/, '')
+ .toLowerCase();
+ return getDomain(cleanedDomain) || cleanedDomain;
};
export const isWildcardDomain = (domain: string) =>