Support Canadian address parsing with French street type handling#208
Merged
Conversation
Upgrade @sroussey/parse-address to 3.0.0-beta1 and route address street
normalization through the new country-aware parser: US and CA each get a
dedicated parser instance, other countries keep their raw street line.
- Preserve French leading-type ordering ("123 Rue Principale" is not
reordered to "123 Principale Rue") by keying off the source token order.
- Add a token-preservation loss guard: the parser should only abbreviate
and reorder, so a rebuilt line with fewer tokens (the beta CA parser
truncates some French compound names like "Avenue du Parc") falls back
to the raw lines instead of persisting a truncated address.
- Document why the parser's re-extracted city/postal_code are ignored:
EDGAR supplies those as structured fields and the EDGAR zipCode is
authoritative (also why the 3.0 zip->postal_code rename is a no-op here).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Frvs9m4YyEfAoRVkibYSNN
3.0.1 is the first Node-loadable ESM release (3.0.0-beta1 and 3.0.0 were broken); it also ships two changes that affect this consumer: - Token-preservation fallback: feeding the parser the full address string (with EDGAR's SEC region code, e.g. "A8") now trips the parser into returning the whole string as `street`. Fix: hand the parser only the street lines — city/state/postal are already structured from EDGAR and were never read back. Drop the now-unused city/state/zip parameters. - The French-compound truncation the beta had is fixed upstream, so "1500 Avenue du Parc" normalizes to "1500 Ave du Parc" instead of falling back to the raw line; update that test accordingly. - parseLocation now returns a typed ParsedAddress (was `any`), so the street-field filter/map chains need an explicit string type guard. The local loss guard stays as defense-in-depth. Address suite 39/39 green; project typechecks clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Frvs9m4YyEfAoRVkibYSNN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends address normalization to support Canadian addresses alongside US addresses, with special handling for French-language street lines that lead with the street type (e.g., "123 Rue Principale") rather than trailing it. Upgrades the address parser library to v3.0.0-beta1 to enable country-specific parsing.
Key Changes
usAddressParserandcaAddressParser), dispatched via newstreetParserForCountry()functionFRENCH_LEADING_STREET_TYPESset to detect when a street line uses French leading-type ordering, preserving the original word order instead of reordering to English trailing-type formatnormalizeUSStreetAddress()tonormalizeStreetAddress()and made it country-agnostic; now accepts a parser instance and handles both US and Canadian addressesstreetTokenCount()helper to detect when the parser would drop words (e.g., truncating "Avenue du Parc" to "Ave du"), falling back to raw street lines to prevent data losscivic_number_suffixfrom parser output and properly reconstruct house numbers; removed city re-extraction since EDGAR provides city as a structured field@sroussey/parse-addressfrom v2.4.2 to v3.0.0-beta1Implementation Details
normalizeStreetAddress()changed from 4-tuple (including city) to 3-tuple (street components only), since city is already a structured field from EDGARhttps://claude.ai/code/session_01Frvs9m4YyEfAoRVkibYSNN