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

feat: add formatPhone #155

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: add formatPhone #155

wants to merge 4 commits into from

Conversation

linconkusunoki
Copy link
Contributor

related: #146

@codecov
Copy link

codecov bot commented Sep 25, 2020

Codecov Report

Merging #155 into main will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #155   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           51        51           
  Lines          938       955   +17     
  Branches       113       122    +9     
=========================================
+ Hits           938       955   +17     
Impacted Files Coverage Δ
src/utilities/index.ts 100.00% <100.00%> (ø)
src/utilities/phone/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a45427...400c0f1. Read the comment docs.

@@ -107,3 +108,25 @@ describe('isValid', () => {
});
});
});

describe('format', () => {
test('should format phone', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be interesting to add tests using a string with non numeric characters and strings with length larger than a phone number length.
i.e.:
expect(format('11988#887AB777')).toBe('(11) 9888-877777'); expect(format('11988887777123123123')).toBe('(11) 9888-877777')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after the change suggested by @hyanmandian this test case:

expect(format('11988887777123123123')).toBe('(11) 9888-877777')

will be impossible, instead it'll return:

+11 (98) 88877-77123123123

is this ok?

Copy link
Contributor

@pedrovsp pedrovsp left a comment

Choose a reason for hiding this comment

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

I think you could add a few more test cases, I suggested two examples in the test file.

@hyanmandian
Copy link
Member

Hello nice MR @linconkusunoki and thanks @pedrovsp for the review! Another thing that I think could be improved is the removal of the config param... I know that I've suggested this but looking at the code and the test cases, maybe its better to just format the prefix when receiving this prefix. Something like:

format('5133333333') // (51) 3333-3333
format('555133333333') // +55 (51) 3333-3333

What do you think about it?

@linconkusunoki
Copy link
Contributor Author

hey guys thanks for the feedback and sorry for the late, I'll work on these changes

@rfoel
Copy link
Contributor

rfoel commented Oct 19, 2020

I like the idea of receiving the phone number and format the country code if it is present (eg. length > 11).

@hyanmandian
Copy link
Member

Hello guys, do you need some help?

@linconkusunoki
Copy link
Contributor Author

hey @hyanmandian for me it's ok if anyone wants to get this task #186, maybe close this PR and open another one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants