feat: handle national trunk prefix in PhoneNumberTransformer#10
Merged
Conversation
Numbers in trunk-prefix countries (e.g. France 06…, UK 07…) were mis-grouped because the formatter treated the leading national-prefix digit as part of the significant number. The generator now emits nationalPrefix for countries whose formats display it (via nationalPrefixFormattingRule), and the worklet strips that prefix before selecting/applying a format, then re-adds it so cursor mapping stays aligned. US/CA (prefix "1", no display rule) are unaffected. Verified against libphonenumber-js AsYouType for FR/GB/JP/AU; tests added to PhoneNumberTransformer.test.ts.
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.
Description
Phone numbers in countries with a national trunk prefix were mis-formatted when the prefix was typed.
PhoneNumberTransformertreated the leading prefix digit as part of the national significant number, so e.g. France0612345678rendered as0 61 23 45 67(wrong grouping, last digit dropped) instead of06 12 34 56 78. NANP countries (US/CA) were unaffected — they have no displayed trunk prefix.Solution
libphonenumber's format patterns describe the national significant number (without the trunk prefix), which is reapplied via a per-format
nationalPrefixFormattingRule(e.g."0$1").nationalPrefixfor a country only when one of its formats has anationalPrefixFormattingRule— so display-prefix countries (FR/GB/DE/JP/AU/…) get it, while US/CA (prefix"1", no rule) keep bare-number formatting.Note:
phone-data.tsis regenerated, so the diff also carries a small libphonenumber-js data refresh (it was last generated against older metadata) on top of thenationalPrefixadditions.Test plan
yarn test— addedPhoneNumberTransformer.test.tscases for FR/GB/JP/AU typed with the leading0, plus a US case asserting a leading1is not treated as a trunk prefix.libphonenumber-jsAsYouType, e.g. FR0612345678→06 12 34 56 78, GB02012345678→020 1234 5678.includeCallingCode: false) now formats FR/GB correctly as you type.