java-faker
java-faker copied to clipboard
Idea: Lorem Ipsum with fixed length
Is your feature request related to a problem? Please describe. currently, you can only get fixed length lorem ipsum without spaces
eg.
faker.lorem().characters(maxLength)
if you want spaced words or sentences of fixed length, you need to do something like this:
faker.lorem()
.sentence(wordCount)
.substring(0, maxLength)
.trim()
- the
trim
is needed whenString::substring
stops on a space -
an exception is thrown if
maxLength
is shorter than the output of::sentence
- Apache Commons StringUtils.substring helps, but it makes the code even more verbose
it's terribly inconvenient :smile:
Describe the solution you'd like
something like faker.lorem().maxLengthSentence(maxChars)
Describe alternatives you've considered See code snippet above for attempted alternatives
Additional context Add any other context or screenshots about the feature request here.
Hi, we will volunteer to work on this issue in October/November. For the project maintainer, please let us know if this is okay and if you want it fixed.
@wcarmon Is this something you are looking for?
faker.lorem().maxLengthSentence(10); output: "Quia quaer"
That would be excellent
This method is available in Datafaker (https://www.datafaker.net), if anyone needs it.
This method is available in Datafaker (https://www.datafaker.net), if anyone needs it.
Is there a built-in functionality to limit the length of other DataFaker outputs? Like if I wanted to have a maxLength for faker.name().lastName() for example?
Tricky. The values are created in different ways, like a full name is sometimes a first name, middle name, and last name. Hard to get that under, or above, a certain number programmatically. You could brute force it perhaps, but it's tricky to have a general solution for this.