java-faker icon indicating copy to clipboard operation
java-faker copied to clipboard

Idea: Lorem Ipsum with fixed length

Open wcarmon opened this issue 2 years ago • 6 comments

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 when String::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.

wcarmon avatar Oct 08 '21 23:10 wcarmon

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.

komminen avatar Oct 16 '21 17:10 komminen

@wcarmon Is this something you are looking for?

faker.lorem().maxLengthSentence(10); output: "Quia quaer"

NatalieSty avatar Nov 21 '21 23:11 NatalieSty

That would be excellent

wcarmon avatar Nov 21 '21 23:11 wcarmon

This method is available in Datafaker (https://www.datafaker.net), if anyone needs it.

bodiam avatar Feb 14 '22 12:02 bodiam

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?

mfoltin avatar Oct 31 '23 09:10 mfoltin

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.

bodiam avatar Oct 31 '23 09:10 bodiam