npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

salutation-generator

v0.1.3

Published

A flexible TypeScript library for generating personalized greetings based on time of day, user context, professionalism level, and relationship status

Readme

salutation-generator

Generate contextual, personalized greetings like "Good morning, Mr. Smith" with support for professionalism levels, anonymous users, custom time boundaries, and flexible data injection. Built for modern applications that care about user experience.

Installation

npm install salutation-generator
# or
pnpm add salutation-generator
# or
yarn add salutation-generator

Usage

import { generateGreeting } from 'salutation-generator';

const result = generateGreeting({
  getFirstName: () => 'Tom',
  getGender: () => 'male',
  getRelationshipStatus: () => 'single',
  professionalism: 'formal',
  getDateTime: () => new Date(),
});

console.log(result.fullMessage); // "Good morning, Mr. Tom"

API

generateGreeting(config: GreetingConfig): GreetingResult

Generates a personalized greeting message.

Config

interface GreetingConfig {
  getFirstName: () => string | undefined;
  getGender: () => 'male' | 'female' | 'non-binary' | undefined;
  getRelationshipStatus: () => 'single' | 'married' | 'other' | undefined;
  professionalism: 'formal' | 'casual' | 'neutral';
  getDateTime: () => Date;
  nameFallback?: string | (() => string);
  canBidGoodNight?: boolean;
}
  • getFirstName: Returns user's first name. Returns undefined for anonymous users.
  • getGender: Returns user's gender identity.
  • getRelationshipStatus: Returns relationship status (affects honorifics for females in formal mode).
  • professionalism: Determines greeting style:
    • 'formal': Uses honorifics (Mr., Mrs., Ms., Mx.)
    • 'casual': Uses "Hey [Name]!" format
    • 'neutral': Uses time-based greeting with name only
  • getDateTime: Function that returns a Date object for determining time of day.
  • nameFallback: Optional fallback name for anonymous users when gender is unavailable.
  • canBidGoodNight: Optional boolean (default: true). Whether to say "Good night" during night hours (9 PM - 4:59 AM). If false, uses "Good evening" instead.

Return Value

interface GreetingResult {
  timeOfDay: 'morning' | 'afternoon' | 'evening' | 'night';
  greeting: string;
  honorific?: 'Mr.' | 'Mrs.' | 'Ms.' | 'Mx.';
  name?: string;
  fullMessage: string;
}

Examples

Formal Business Context

const result = generateGreeting({
  getFirstName: () => 'Johnson',
  getGender: () => 'male',
  getRelationshipStatus: () => 'married',
  professionalism: 'formal',
  getDateTime: () => new Date(),
});
// Result: "Good morning, Mr. Johnson"

Casual Friend Context

const result = generateGreeting({
  getFirstName: () => 'Alex',
  getGender: () => 'non-binary',
  getRelationshipStatus: () => 'single',
  professionalism: 'casual',
  getDateTime: () => new Date(),
});
// Result: "Hey Alex!"

Anonymous User with Fallback

const result = generateGreeting({
  getFirstName: () => undefined,
  getGender: () => undefined,
  getRelationshipStatus: () => undefined,
  professionalism: 'neutral',
  getDateTime: () => new Date(),
  nameFallback: 'Guest',
});
// Result: "Good morning, Guest"

Using Result Components

const result = generateGreeting({
  getFirstName: () => 'Sarah',
  getGender: () => 'female',
  getRelationshipStatus: () => 'married',
  professionalism: 'formal',
  getDateTime: () => new Date(),
});

// Build custom message
const customMessage = `${result.greeting}! Welcome back, ${result.honorific} ${result.name}!`;
// "Good morning! Welcome back, Mrs. Sarah!"

Controlling Night Greetings

// Default behavior - says "Good night" during night hours
const result1 = generateGreeting({
  getFirstName: () => 'Tom',
  getGender: () => 'male',
  getRelationshipStatus: () => 'single',
  professionalism: 'formal',
  getDateTime: () => new Date('2024-01-01T22:00:00'), // 10 PM
});
// Result: "Good night, Mr. Tom"

// Disable "Good night" - uses "Good evening" instead
const result2 = generateGreeting({
  getFirstName: () => 'Tom',
  getGender: () => 'male',
  getRelationshipStatus: () => 'single',
  professionalism: 'formal',
  getDateTime: () => new Date('2024-01-01T22:00:00'), // 10 PM
  canBidGoodNight: false,
});
// Result: "Good evening, Mr. Tom"

Time of Day Boundaries

  • Morning: 5:00 AM - 11:59 AM
  • Afternoon: 12:00 PM - 4:59 PM
  • Evening: 5:00 PM - 8:59 PM
  • Night: 9:00 PM - 4:59 AM

Honorific Rules

Formal Professionalism

  • Male: Always uses Mr.
  • Female:
    • Married → Mrs.
    • Single/Other → Ms.
  • Non-binary: Always uses Mx.

Casual & Neutral

No honorifics are used.

Anonymous Users

When getFirstName() returns undefined:

  1. If formal professionalism + gender available → Uses honorific without period (e.g., "Good morning, Mr")
  2. If nameFallback provided → Uses fallback value
  3. Otherwise → Returns greeting only (e.g., "Good morning")

Complementary Packages

  • humanparser - Parse full names into components (first, last, salutation, etc.)
  • greeting-time - If you need customizable time boundaries

Using with humanparser for Full Name Parsing

If you need to parse full names, you can combine this with the humanparser package:

TypeScript Support

Full TypeScript support with comprehensive type definitions included.

License

MIT © Oghenetefa Okotete

Contributing

Issues and pull requests welcome at github.com/everurstruly/salutation-generator