You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With JavaFaker, it's possibly to quickly generate strings or numbers with numerify, letterify, bothify and regexify. It's a little hidden, only documented in the javadoc.
numerify replaces # with numbers in a string,
letterify replaces ? with uppercase lettrs in a string,
and bothify does both.
regexify generates a string that matches the a given regular expression.
It would be nice if those were availablein kotlin-faker too, especially if they could also be made unique.
I see the FakerService does have numerify, letterify and generexify, but it seems those are only used for implementing the various providers, and not meant to be used directly?
Basically, it would be great to just write something like,
List(100) { faker.unique.letterify("foo???bar") }
If I could, I would just add the following locally, but FakerService and AbstractFakeDataProvider are package internal.
class Template constructor(fakerService: FakerService) : AbstractFakeDataProvider<Template>(fakerService) {
override val categoryName = "Template"
override val localUniqueDataProvider = LocalUniqueDataProvider<Template>()
override val unique by UniqueProviderDelegate(localUniqueDataProvider)
fun numerify(template: String) = with(fakerService) { template.numerify() }
fun letterify(template: String) = with(fakerService) { template.letterify() }
fun bothify(template: String) = with(fakerService) { template.letterify().numerify() }
fun regexify(template: String) = with(fakerService) { template.generexify() }
}
Is there a way to add a custom provider like that without having to reference internal classes?
The text was updated successfully, but these errors were encountered:
I can definitely see the point in having letterify and the rest as part of the public API. Should be quite easy to add also, just need to think where these functions would fit best "semantically". I'll take a look at adding this stuff later this week.
I've also been thinking about how one could create own implementations of AbstractFakeDataProvider. There are a few limitations with that:
it would require to open up a lot of internal functionality
and since most of Data Providers read from .yml files, I would also like to support this in the custom implementations. But there's no functionality in place to do that yet (see also Provide ability to extend a dictionary #63)
probably more stuff that I'm forgetting as well
But I'm definitely open to doing this, however I'd prefer to keep issues separated, so for this thing it's better to create a new issue.
Great, thanks! With those functions kotlin-faker would be a nice drop-in replacement for JavaFaker. Adding custom providers is only something I was wondering about, not something that I would really need at the moment.
Thanks, that was quick! I gave the snapshot a try and it works just as I had hoped.
The unqiue value generation is super handy (for those new functions and in general). I had a similar wrapper for generating unique values from JavaFaker, but having it out of the box for all providers is just great.
With JavaFaker, it's possibly to quickly generate strings or numbers with
numerify
,letterify
,bothify
andregexify
. It's a little hidden, only documented in the javadoc.numerify replaces # with numbers in a string,
letterify replaces ? with uppercase lettrs in a string,
and bothify does both.
regexify generates a string that matches the a given regular expression.
It would be nice if those were availablein kotlin-faker too, especially if they could also be made unique.
I see the
FakerService
does havenumerify
,letterify
andgenerexify
, but it seems those are only used for implementing the various providers, and not meant to be used directly?Basically, it would be great to just write something like,
If I could, I would just add the following locally, but
FakerService
andAbstractFakeDataProvider
are package internal.Is there a way to add a custom provider like that without having to reference internal classes?
The text was updated successfully, but these errors were encountered: