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

localized-greeting

v1.0.0

Published

Time-of-day greetings in the user's locale. Zero dependencies.

Downloads

14

Readme

localized-greeting

Time-of-day greetings ("Good morning", "Guten Tag", "Bonsoir") in the user's locale. Zero runtime dependencies. Works in Node 18+ and modern browsers.

Install

npm install localized-greeting

Basic usage

import { getGreeting, getTimeOfDay } from 'localized-greeting';

// Uses the runtime locale and current time automatically
console.log(getGreeting());                          // e.g. "Good morning"

// Explicit locale
console.log(getGreeting({ locale: 'de' }));          // "Guten Morgen"
console.log(getGreeting({ locale: 'fr' }));          // "Bonjour"

// Explicit date
const d = new Date('2024-01-01T20:00:00');
console.log(getGreeting({ locale: 'es', date: d })); // "Buenas noches"

// Just the time bucket
console.log(getTimeOfDay());                         // "morning" | "afternoon" | "evening"

Custom locale registration

import { registerLocale, getGreeting, getSupportedLocales } from 'localized-greeting';

registerLocale('ja', {
  morning: 'おはようございます',
  afternoon: 'こんにちは',
  evening: 'こんばんは',
});

console.log(getGreeting({ locale: 'ja' })); // "おはようございます" (in the morning)
console.log(getSupportedLocales());          // [..., 'ja']

registerLocale can also override a built-in locale at runtime.

Locale resolution

  1. Try the full BCP 47 tag (e.g. de-AT).
  2. Try the base language (de).
  3. Fall back to en.

Underscores are normalised to hyphens (de_ATde-AT) and matching is case-insensitive.

When no locale option is passed, the library reads Intl.DateTimeFormat().resolvedOptions().locale (the system/browser locale) and falls back to "en" if unavailable.

Note: Time-of-day detection uses the local system clock of the environment running the code (Node.js process or browser tab). The date option lets you override this with any Date object.

Time buckets

| Hour range | Bucket | | ---------- | ----------- | | 05 – 11 | morning | | 12 – 17 | afternoon | | 18 – 04 | evening |

Built-in locales

en, de, es, fr, it, pt, nl, sv, da, pl

API

type TimeOfDay = 'morning' | 'afternoon' | 'evening';
type GreetingTranslations = Record<TimeOfDay, string>;

interface GreetingOptions {
  locale?: string; // BCP 47, defaults to runtime locale then "en"
  date?: Date;     // defaults to new Date()
}

function getGreeting(options?: GreetingOptions): string;
function getTimeOfDay(date?: Date): TimeOfDay;
function registerLocale(locale: string, translations: GreetingTranslations): void;
function getSupportedLocales(): string[];

Development

npm install
npm run build      # tsup → dist/
npm test           # vitest
npm run typecheck  # tsc --noEmit
npm run lint       # eslint
npm run format     # prettier

License

MIT