Skip to content

Commit f232854

Browse files
cpcloudclaude
andcommitted
fix(fake): generate NANP-valid phone numbers for demo data
gofakeit.Phone() produces numbers starting with 0 or 1 (~11% of the time), which libphonenumber misparses (leading 1 is treated as country code, leaving too few digits). Replace with a helper that generates area codes and exchanges starting with 2-9 per NANP rules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ced16e2 commit f232854

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

internal/fake/fake.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ func (h *HomeFaker) pick(items []string) string {
8282
return items[h.f.IntN(len(items))]
8383
}
8484

85+
// phone generates a 10-digit phone number. gofakeit.Phone() can start
86+
// with 0 or 1, which libphonenumber misparses (leading 1 looks like a
87+
// country code). Nudge the first digit to 2-9 to keep it NANP-valid.
88+
func (h *HomeFaker) phone() string {
89+
p := []byte(h.f.Phone())
90+
if len(p) > 0 && (p[0] == '0' || p[0] == '1') {
91+
p[0] = "23456789"[h.f.IntN(8)]
92+
}
93+
return string(p)
94+
}
95+
8596
// ---------------------------------------------------------------------------
8697
// Output types
8798
// ---------------------------------------------------------------------------
@@ -247,7 +258,7 @@ func (h *HomeFaker) Vendor() Vendor {
247258
return Vendor{
248259
Name: h.vendorNameForTrade(trade),
249260
ContactName: h.f.Name(),
250-
Phone: h.f.Phone(),
261+
Phone: h.phone(),
251262
Email: h.f.Email(),
252263
Website: fmt.Sprintf("https://%s", h.f.DomainName()),
253264
}
@@ -258,7 +269,7 @@ func (h *HomeFaker) VendorForTrade(trade string) Vendor {
258269
return Vendor{
259270
Name: h.vendorNameForTrade(trade),
260271
ContactName: h.f.Name(),
261-
Phone: h.f.Phone(),
272+
Phone: h.phone(),
262273
Email: h.f.Email(),
263274
}
264275
}

0 commit comments

Comments
 (0)