-
-
Notifications
You must be signed in to change notification settings - Fork 919
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
Add phone.number generation options #1542
Comments
We actually have a real-world issue related to this: We use react-phone-number-input with a restriction for Therefore, we encounter this warning within our unit tests:
|
if you do |
I guess I can just wait for #1735 to be merged, which makes |
There's a difference between the default locale So |
Hmm, the problem is we use When switching to use |
This issue is exactly there for that (to add options to get only the expected formats without manually passing it to the method). |
Yeah, perfect! Then I will eagerly await the new functionality ;) I can also offer to test changes out with our codebase if you guys have the need for it. |
perhaps |
This might be how you write it to your database, but that is not how your users will put it into your input fields. |
That would work too. |
Team Decision
We might add a parameter that allows choosing whether the number should follow the standard or was "input" by a user. |
It would be nice if at least a few options were available before the deprecation took effect. |
the direct replacement for |
Yes, that would be helpful, if it's not too niche, or link to more docs somewhere? Will the behavior differ at all between those two (in terms of which numbers can show up in which positions)? I'd thought of using string methods on the number, but that seems messier, and I don't like seeing the deprecation errors. |
Nope, if you pass a format parameter to faker.phone.number it directly passes it to the replaceSymbolWithNumber method at the moment |
For the original issue, i think the new API should be kept fairly minimal to start with, given the number of possible different "axes" which would make this hard to localize and test:
So maybe there's only a single parameter like "style" =
Then if users say "hey we really need a new style for this use case" it can be added without worrying too much about breaking existing functionality, you would just need to add a new definition file for the style. |
IMO this patter can be very easily generated by |
IIRC that method is going to get deprecated as well. See #1994 for more details. |
In some cases we have a But the examples for a possible implementation above seem preferable if / when they’re implemented. |
hmm, now i think about it, i think while saying that method "is mostly a black box that does some arbritary char -> digit transformations" is true, those are generally transformations which are useful for phone numbers. So maybe it would make sense to not deprecate it, for example if you want phone numbers in a non-standard but fixed pattern say |
The issue there is that It can easily achieved with js string.replace, faker.string.numeric, or faker.helpers.fromRegexp. |
sure, but i would say there is no hurry to deprecate replaceSymbolWithNumber at least until we have more flexible options for phone.number() - that way anyone who is currently using a fixed format pattern has the option to either switch to one of the new patterns, or build their own. |
Anyway this discussion is a bit offtopic, lets discuss deprecation further on #1994 this issue can be for the future options for the phone.number method. |
Sorry, but the two methods are not the same, replacing them in our application results in tests failures. |
Well, AFAICT they are: faker/src/modules/phone/index.ts Lines 36 to 43 in 5e900d2
Unless you don't always provide the format or the JS runtime processes the fallback path even though it doesn't have to. |
Seems identical for a given seed: faker.seed(123); faker.helpers.replaceSymbolWithNumber('##########')
// 6724265774
faker.seed(123); faker.phone.number('##########')
// 6724265774 |
Comparing to https://www.npmjs.com/package/libphonenumber-js
|
My use case is mostly providing default data from my database models so for me it would be nice to get a "parsed" phone number and only mobile numbers.
I can see the use case for the "human input" format as well, but that is currently not something I use it for. But an argument with "style" I guess could work. Guess that is applicable to many different things. I looked in the documentation for amount for example, which also is prone to many different input formats. But as I said, my use case is mostly for output so I would want a consistent format, but it would be nice to be able to generate "input" data as well. |
Just FYI, there's no way in the North American Numbering Plan to distinguish between mobile and landlines. https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes |
Would people be OK with me proceeding with a PR to introduce this "style" parameter? |
Yes, although this will probably end up in v9.x. As I want to wrap up v8.x and start with v9.0. |
+1 for generating mobile (cell) numbers. My registration form only allows mobile numbers and currently GB Landline: 02392 232456 Edit: solved temporarily with |
considering this has already been solved very well by the FFaker gem would it not make sense to copy their implementation since this already shares the same name and has alot of crossover already and solves all the issues mentioned in this thread? https://www.rubydoc.info/github/ffaker/ffaker/FFaker/PhoneNumber |
It looks like FFaker has quite a different philosophy for dealing with localisation Eg the different localisations for phone numbers in FFaker contain Ruby code. Eg https://github.com/ffaker/ffaker/blob/main/lib/ffaker/phone_number_au.rb Whereas in faker-js the localisations are typically simple data and any logic is kept in centralised methods. That would make it hard to port the logic directly. |
As this issue is already closed, please add any further suggestions for phone improvements here: #2883 this will ensure it doesn't get lost. |
Clear and concise description of the problem
Currently the phone.number method generates phone numbers in various formats.
However, the usually the phone number inputs require specific input formats e.g. an international telephone number.
Suggested solution
It would be nice if it is possible to be more specific which addresses should be generated.
type?: 'landline' | 'cell-phone'
format?: 'international' | 'national'
It is not a goal to generate phone numbers that are normalized beyond the given options. So the user might still have to strip whitespace or other "human" additions.
Alternative
Additional context
No response
The text was updated successfully, but these errors were encountered: