-
-
Notifications
You must be signed in to change notification settings - Fork 943
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(helpers): add fromRegExp method #1569
feat(helpers): add fromRegExp method #1569
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #1569 +/- ##
==========================================
- Coverage 99.62% 99.62% -0.01%
==========================================
Files 2450 2450
Lines 239453 239748 +295
Branches 1226 1272 +46
==========================================
+ Hits 238559 238847 +288
- Misses 872 879 +7
Partials 22 22
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
However, we have to decide whether we want to introduce this as a new method (e.g. faker.string.forRegex
) because it changes the behavior of the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm with @ST-DDT, but I would maybe name it string.fromRegExp
from
instead of for
because it relates to the input parameter
and RegExp
because that is how the class is named in JS
Good idea, then it should accept actual Regexp types as well. if (pattern instanceof RegExp) {
pattern = pattern.toString();
} it should also be prepared for regexp options such as case (in)sensitive. |
Looking around online, I came across another library called RandExp.js that does exactly this. We can just use this library to facilitate that functionality. What do you guys think? |
|
Hmm you have a point. I'm new to open source, so tell me if this sounds crazy or not: I copy their implementation and use calls to faker's random number generation. That way we can have their functionality, and also keep the deterministic nature of the function. This also sounds like overkill but its more realistic than writing one from scratch, that may have errors and bugs all over the place. |
IMO we should use the current implementation as a basic implementation. We can add a comment in the jsdocs that for complete regex support the users can use that library and explain how you can use it with faker (e.g. EDIT: That library is no longer maintained, so I don't think we should explicitly link it. |
For now my first thought would that this is definitely to much code (in terms of IMO even the current PR looks really long for just one function Not sure what I can suggest you now to proceed or maybe just wait, but this could take months 😕 |
I guess there's no rush right? As you mentioned <1% of users probably use this functionality anyways. For now, I'll just wait 😐 |
Sorry for the long wait. Team decision
|
Alright noted. This seems like it has become a more complex problem as tokenising RegEx is needed to properly generate correct text (according to the previously mentioned library). If I were to try to implement it it might be a huge change. Whats the course of action now? |
Fixes #1359
Example: