Skip to content

Full Toolkit for Next-Level Domain Analysis

Use ISO date formatting in WHOIS summary 📆

Felix Wotschofsky653a72cda545
diff --git a/lib/whois.test.ts b/lib/whois.test.ts
new file mode 100644
index 0000000..835eef1
--- /dev/null
+++ b/lib/whois.test.ts
@@ -0,0 +1,10 @@
+import { describe, expect, it } from 'vitest';
+
+import { formatDate } from './whois';
+
+describe('formatDate', () => {
+ it('formats a date as an ISO string without the time', () => {
+ const date = new Date('2021-01-01T12:34:56Z');
+ expect(formatDate(date)).toBe('2021-01-01');
+ });
+});
diff --git a/lib/whois.ts b/lib/whois.ts
index a1ee48e..4661246 100644
--- a/lib/whois.ts
+++ b/lib/whois.ts
@@ -2,6 +2,8 @@ import whoiser, { type WhoisSearchResult } from 'whoiser';
import { getBaseDomain, isValidDomain } from './utils';
+export const formatDate = (date: Date) => date.toISOString().split('T')[0];
+
export const lookupWhois = async (domain: string) => {
const result = await whoiser(domain, {
raw: true,
@@ -85,9 +87,7 @@ export const getWhoisSummary = async (
registrar: firstResult['Registrar']?.toString(),
createdAt:
firstResult && 'Created Date' in firstResult
- ? new Date(firstResult['Created Date'].toString()).toLocaleDateString(
- 'en-US'
- )
+ ? formatDate(new Date(firstResult['Created Date'].toString()))
: null,
dnssec: firstResult['DNSSEC']?.toString(),
};