Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced libphonenumber-js with custom functions #6205

Closed

Conversation

print-Sathvik
Copy link
Contributor

@print-Sathvik print-Sathvik commented Sep 1, 2023

WHAT

Replaced libphonenumber-js with custom functions

Proposed Changes

  • Fixes remove libphonenumber-js #6082
  • Deleted libphonenumber-js
  • Implemented methods to parse phone number, format phone number, check its validity, and fetch country code from phone number

@coronasafe/care-fe-code-reviewers @coronasafe/code-reviewers

HOW

  • For getting country name from phone number, the country whose country code is longer is returned in case there are multiple matches. For example when +1242 is typed, the country returned is Bahamas(+1242) instead of US(+1) or Canada(+1)
  • When there is a clash in country codes(like many North American countries have +1 as country code), their area code is checked.
  • Only Indian phone numbers are formatted as +91 nnnnn nnnnn. To format phone numbers of other countries we will need their area codes and there are many rules to be considered which is not practical without using library
  • Landline numbers will be formatted as cc nnnn nnnn or ccc nnn nnnn or cccc nnn nnn where 'c' is a digit of area code. Also the leading zeros for area codes are removed. This was how the function from libphonenumber-js was formatting.

🤖 Generated by Copilot at e1dd23a

@print-Sathvik print-Sathvik requested a review from a team September 1, 2023 10:59
@print-Sathvik print-Sathvik requested a review from a team as a code owner September 1, 2023 10:59
@vercel
Copy link

vercel bot commented Sep 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
care-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2023 8:17pm

@netlify
Copy link

netlify bot commented Sep 1, 2023

Deploy Preview for care-egov-staging ready!

Name Link
🔨 Latest commit 4c3be57
🔍 Latest deploy log https://app.netlify.com/sites/care-egov-staging/deploys/64f4e9b042ede40008c72a64
😎 Deploy Preview https://deploy-preview-6205--care-egov-staging.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +57 to +59
if (value.length > 12 && value.startsWith("+910")) {
value = "+91" + value.slice(4);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this intend to do? Can you add comments for the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It eliminates 0 if any at the beginning of a number after +91. For ex +9109876543214 will be formatted as +919876543214. The libphonenumber-js library was also doing this. Hyderabad's area code for landline is 40 but I have never seen landline number with 40, everyone uses 040 followed by 8 digits. Similarly for other areas. That 0 should be eliminated while storing it in E164 format. Later I also noticed that chrome's autofill feature adds a 0 at the beginning after country code. So this will handle that too.

src/Utils/utils.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Sep 1, 2023
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

👋 Hi, @print-Sathvik,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@print-Sathvik
Copy link
Contributor Author

I am closing this PR as the diff shows others' work as part of this PR

@print-Sathvik print-Sathvik deleted the remove_libphonenumber-js branch September 4, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge conflict pull requests with merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove libphonenumber-js
2 participants