-
-
Notifications
You must be signed in to change notification settings - Fork 953
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 character length parameter to lorem.text
#1546
Comments
Currently blocked by #1486 |
@mrzmyr No, it is no longer blocked. Do you wish to work on this? |
@ST-DDT, nope, just wanted to ping. |
@ST-DDT How should this be approached? If I understood things correctly then once faker is initialized all the Module classes are initialized. To implement the A few approaches that I can think of are:
|
Currently yes, this might change when we implement proper tree shaking.
I'm not sure about that. Could you please explain your idea in more detail? I think having a avg or mean length is sufficient to determine what to generate (sentence, paragraph, ...). Also I think generating that on the fly is fast enough for now. |
Let's say we need a sentence that is exactly 150 characters long. We have a list of words of variable lengths per locale. So to generate a sentence for a locale:
To be able to randomly choose a word from the list:
Do we know how the APIs are generally invoked? Eg: Will the import faker from ''; test("#1", () => { /* faker.text for en */ }); test("#2", () => { /* faker.text for de */ }); test("#3", () => { /* faker.text for es */ }); |
I think we could do that a tad more easily. We generate a paragraph/sentences until the char limit is exceeded, then excess chars are trimmed, finally the end of the sentence/paragraph is pseudo restored.
|
I would like to work on this issue. |
@bmulholland If you would like to work on this, please leave a comment so we can assign the issue to you. |
I'd love to, it's just not high on my priority list. |
Awesome. No hurry. |
Clear and concise description of the problem
Sometimes we just want a text that has a particular length instead of conforming to arbitrary length units (lines/paragraphs).
Suggested solution
Add length parameter to the
lorem.text
method.faker.lorem.text({ length: number | { min: number, max: number }})
faker.lorem.text({ length: 150 })
Alternative
faker.lorem.paragraphs(<sufficientlyLargeNumber>).substring(0, 150)
Additional context
Originally requested in Discord by kryp71c.
The text was updated successfully, but these errors were encountered: