Skip to content

Derive phone region from extracted location (locale-aware parsing) #69

Description

@s-annam

Problem

After Issue A, phone parsing uses a fixed US default region. But the résumé already tells us the candidate's region — extractContact extracts location in the same scan (src/lib/heuristics/extract-fields.ts:268, via US_LOCATION_RE / INTL_LOCATION_RE) — and we ignore it. A London or Bangalore résumé with a national-format number gets parsed as if US.

Use the extracted location as the region hint so national/local-format numbers parse and reformat correctly for the candidate's actual locale.

Approach

  1. Add a small regionFromLocation(location: string): string | undefined helper (likely in phone.ts or a sibling): map US_LOCATION_RE matches → US; map the country tail of INTL_LOCATION_RE → ISO 3166-1 alpha-2 (e.g. United KingdomGB, IndiaIN, CanadaCA). Keep the country→ISO table small and explicit; unmatched → undefined.
  2. Thread the derived region into the findPhoneNumbersInText / normalizePhone call from Issue A as defaultCountry.
  3. Fallback to US when no location is extracted or the country is unmapped (matches the Issue A default — confirmed decision).

Depends on

Blocked by Issue A (the normalizer + findPhoneNumbersInText wiring must land first).

Affected files

  • src/lib/heuristics/phone.ts (or sibling) — add regionFromLocation + country→ISO table.
  • src/lib/heuristics/extract-fields.ts — pass derived region instead of hardcoded US.
  • Tests — regionFromLocation unit tests (US + 2–3 intl); a fixture demonstrating an intl national-format number reformatting correctly.

Acceptance criteria

  • regionFromLocation maps US + a small explicit set of intl countries to ISO codes; unmatched → undefined.
  • Phone parsing uses the location-derived region; falls back to US when absent/unmapped.
  • An international-locale fixture (national-format number) reformats to the correct national/international form.
  • npm run test + npm run typecheck green.

Notes

Part of the phone-handling epic. Builds on Issue A.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

improvementEnhancing existing functionality

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions