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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@herongxhr/sayhi

v1.0.2

Published

A framework-agnostic greeting generator based on time, date, and weekday with multi-language support

Readme

Greeting Generator

A lightweight, framework-agnostic TypeScript library to generate dynamic greetings based on time, date, and weekday. Supports multi-language configurations and customizable time slots.

Installation

npm install greeting-generator

Usage

Basic Example

import { GreetingGenerator } from "greeting-generator";

// Initialize with default settings (Chinese, 'zh-CN')
const greeter = new GreetingGenerator();

// Generate a greeting based on the current time, date, and weekday
console.log(greeter.generateGreeting()); // e.g., "早上好" (if morning)

// Switch language to English
greeter.setLocale("en-US");
console.log(greeter.generateGreeting()); // e.g., "Good morning" (if morning)

Custom Configuration

You can customize the language and time slots when creating an instance:

import { GreetingGenerator } from 'greeting-generator';
import { type Composer } from 'vue-i18n'
import i18n from '@/locales'

const greeter = new GreetingGenerator({
  locale: 'zh-CN',
  languages: {
       'ja-JP': {
        timeslots: {
          morning: 'おはよう',
          afternoon: 'こんにちは',
          evening: 'こんばんは',
          night: 'おやすみ',
        },
        dates: {
          '01-01': '新年おめでとう',
        },
        weekdays: {
          0: '日曜日',
        },
      },
    'zh-CN': {
      weekdays: { 0: '', 1: '', 2: '', 3: '', 4: '', 5: '', 6: '' },
    },
  },
})

const greeting = computed(() => {
  const locale = (i18n.global as Composer).locale.value
  greeter.setLocale(locale) // 切换语言
  return greeter.generateGreeting()
})

Features

  • Dynamic Greetings: Generates greetings based on time of day (e.g., "Good morning"), special dates (e.g., "Happy New Year"), and weekdays (e.g., "Happy Monday").
  • Multi-Language Support: Comes with default languages (e.g., 'zh-CN', 'en-US') and allows custom language definitions.
  • Customizable Time Slots: Define your own time ranges for morning, afternoon, evening, and night.
  • Framework-Agnostic: Works in any JavaScript environment (Node.js, browsers, etc.).

Configuration

GreetingGenerator(options)

Constructor options:

  • options.locale: Initial language code (default: 'zh-CN'). Must match a key in languages.
  • options.timeSlots: Custom time slot definitions (default: morning 6-12, afternoon 12-18, evening 18-22, night 22-6).
    • Format: { [key: string]: { start: number; end: number } }.
  • options.languages: Custom language data to override or extend defaults.
    • Format: { [locale: string]: { timeslots: Record<string, string>, dates?: Record<string, string>, weekdays?: Record<number, string> } }.

Default Language Pack

The library includes default greetings for zh-CN and en-US. You can extend or override them via the languages option. Example structure from languages.ts:

{
  'zh-CN': {
    timeslots: {
      morning: '早上好',
      afternoon: '下午好',
      evening: '晚上好',
      night: '晚安'
    },
    dates: {
      '01-01': '新年快乐'
    },
    weekdays: {
      0: '星期日'
    }
  },
  'en-US': {
    timeslots: {
      morning: 'Good morning',
      afternoon: 'Good afternoon',
      evening: 'Good evening',
      night: 'Good night'
    },
    dates: {
      '01-01': 'Happy New Year'
    },
    weekdays: {
      0: 'Sunday'
    }
  }
}

API

Methods

  • generateGreeting(): string
    Generates a greeting based on the current date, weekday, and time. Combines date, weekday, and time slot parts (if defined), joined by spaces.

    • Example: "新年快乐 星期日 早上好" (if it's January 1st, Sunday, morning).
  • setLocale(locale: string): void
    Switches to a different language. Throws an error if the locale is not found in the language pack.

    • Example: greeter.setLocale('en-US').

Notes

  • The greeting consists of three parts: date (e.g., "Happy New Year"), weekday (e.g., "Sunday"), and time slot (e.g., "Good morning"). Empty parts are omitted.
  • Time slots are evaluated based on a 24-hour clock, with special handling for the "night" slot (spanning midnight).

License

MIT