faker
faker copied to clipboard
Add Greetings
Clear and concise description of the problem
Sometimes, there is the need to generate random greetings, but faker-js does not currently have one
Suggested solution
adding an API for generating random greetings, based on the following:
- Random greeting (for any time:
morning,afternoon,evening,neutral) - Random greeting based on time of the day (
morning,afternoon,evening,neutral)
Note;
neutralis for neutral greetings (greetings that can be used at any time of the day like "Hello", "Hi", etc.)- Users can optionally provide variables like
name, for which the greeting would be generated (e.g. Hello {{name}}, Hi {{name}}, etc.)
Alternative
No response
Additional context
No response
Thank you for your feature proposal.
We marked it as "waiting for user interest" for now to gather some feedback from our community:
- If you would like to see this feature be implemented, please react to the description with an up-vote (:+1:).
- If you have a suggestion or want to point out some special cases that need to be considered, please leave a comment, so we are aware about them.
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements.
We will start the implementation based on:
- the number of votes (:+1:) and comments
- the relevance for the ecosystem
- availability of alternatives and workarounds
- and the complexity of the requested feature
We do this because:
- There are plenty of languages/countries out there and we would like to ensure that every method can cover all or almost all of them.
- Every feature we add to faker has "costs" associated to it:
- initial costs: design, implementation, reviews, documentation
- running costs: awareness of the feature itself, more complex module structure, increased bundle size, more work during refactors
Good morning @mathiasayivor. Could you please describe how the API for that method should look like? Which module should contain that method?
Sure @ST-DDT
API:
/**
* Generates random greetings based on the time of day and other options.
*
* @param {TimeOfDay} [timeOfDay] - The time of day for the greeting. Defaults to any time of day.
* @param {GreetingOptions} [options] - Additional options for greeting generation.
* @returns {Greeting} - A random greeting message.
*/
function greeting(timeOfDay?: TimeOfDay): GreetingWithoutName;
function greeting(options?: GreetingOptions): Greeting;
function greeting(timeOfDay?: TimeOfDay, options: GreetingOptions): Greeting;
/**
* Represents different times of the day.
*/
type TimeOfDay = 'morning' | 'afternoon' | 'evening' | 'neutral';
/**
* Options for generating greetings.
*/
interface GreetingOptions {
name?: string; // The name to include in the greeting.
timeOfDay?: TimeOfDay; // The time of day for the greeting.
includeNeutral?: boolean; // Whether to include random neutral greetings.
includePunctuation?: boolean; // Whether to include punctuation marks in the greeting.
}
/**
* Represents a greeting message.
*/
type Greeting = GreetingWithName | GreetingWithoutName;
/**
* A greeting containing a name. E.g: "Hello Jack," "Good Morning Jack," etc.
*/
type GreetingWithName = string;
/**
* A greeting without a name. E.g: "Hello," "Good Morning," etc.
*/
type GreetingWithoutName = string;
Explanation:
- When no parameters are provided, the method returns a random greeting message of type
GreetingWithoutNamefor anyTimeOfDay. E.g:
const randomGreetingWithoutName = faker.module.greeting() // "Good morning" or "Hello" or "Good evening"
- If both
timeOfDayandnameare provided, the method generates a random greeting message based on the specifiedtimeOfDayand includes the providednamein the greeting. For example,faker.module.greeting('morning', { name: 'Jack' })could return 'Good morning Jack.' - If only
timeOfDayis provided, the method generates a random greeting message based on thetimeOfDay. Optionally, if theincludeNeutraloption is enabled, neutral greetings like 'Hello' or 'Hi' may also be included. - If only
nameis provided, the method generates a random greeting message that includes the providednamefor anyTimeOfDay. For instance,faker.module.greeting({ name: 'Jack' })could return 'Good morning Jack.'
For the module, I suggest creating a dedicated 'faker.greeting' module. This approach allows us to accommodate various forms of greetings, such as salutations for emails, in the future. Alternatively, we could consider adding it to the 'date' module.
Should we take things like Mr/Mrs/Dr into account?
What about Dear Sir or Madame?
What is the intention behind includePunctuation?
IMO the punctuation is very context sensitive.
e.g. in chat: Hi Xyz! or Hi Xyz
e.g. in letters: Dear Mr X, \n ...
also I'm not sure whether all languages use punctuations in greetings.
For the module, I suggest creating a dedicated 'faker.greeting' module. This approach allows us to accommodate various forms of greetings, such as salutations for emails, in the future. Alternatively, we could consider adding it to the 'date' module.
IMO having a greeting module is very specific and there is little else to be added. I'm not sure whether having different kind of greeting methods is worth it. It's not like we are trying to replace chat gpt or similar tools so a generic/unspecific greeting is probably fine.
Maybe if we go for a conversation module, then you could also add things like
request():Could you please pass me the tea please?response():Sure, but I have to entertain it first.information()/statement():The flowers are green.assumption():I believe that rocks can fly.emotion():I love wooden frames!ending()?:Sincerely yours, Tommy
It would fit ok in faker.word module
faker.word.greeting() // ' Hello'
What is the intention behind
includePunctuation?
Some users may prefer to perform additional operations on the generated greeting before using it. However, it may not be necessary to do so, especially considering the extra overhead required to ensure that the greeting does not contain punctuation. As you rightly pointed out, punctuation marks are very context-sensitive.
Should we take things like Mr/Mrs/Dr into account? What about
Dear Sir or Madame?
As you suggested, adding a module, like conversation module would indeed be a more organised approach. Within this module, we can implement separate methods to handle various aspects, including salutations.
To address the question regarding titles like Mr/Mrs/Dr and greetings like Dear Sir or Madam, we can create a dedicated method, such as salutation(gender?: 'male' | 'female'), within the conversation module.
More than the API you'd also have to consider how formal/informal you expect this to be. I might jocularly say "Howdy" in a game, but I don't want my bank to greet me with "Howdy" 😀
Hello Hey Hi Hi there Howdy! Hiya What's up Sup! Ahoy!
Do we include also saying goodbye? Bye Sincerelly Aloha ...
Aloha only if you are in the Hawaiian locale 😀