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

@cantabile/date-helper

v1.4.2

Published

Helper class for date handling

Readme

@cantabile/date-helper

npm version License: ISC

DateHelper is a lightweight TypeScript library that simplifies date and time handling, including:

  • Buddhist calendar (B.E.) conversion
  • English/Thai localization
  • Human-readable display utilities
  • Time delta, tuple-based date composition, and more

📦 Installation

Install using your preferred package manager:

# with npm
npm install @cantabile/date-helper

# with bun
bun add @cantabile/date-helper

🧩 Basic Usage

import DateHelper from "@cantabile/date-helper";

// Create a new instance
const dh = new DateHelper("2024-03-01T00:00:00");

// Display date in AD
console.log(dh.getDisplayDate()); // "01 March 2024"

// Display in Buddhist Era (B.E.) with Thai language
const thai = new DateHelper("2024-03-01", { lang: "th", useBD: true });
console.log(thai.getDisplayDate()); // "01 มีนาคม 2567"

⚙️ Configuration

| Option | Type | Default | Description | | ----------------- | -------------- | ------- | --------------------------------------------- | | lang | "en" \| "th" | "en" | Language for month and weekday names | | useShortText | boolean | false | Use abbreviated month names (Jan, Feb, …) | | useBD | boolean | false | Use Buddhist Era (B.E.) instead of Gregorian | | use12HourFormat | boolean | false | Display time in 12-hour (AM/PM) format | | showSeconds | boolean | false | Display seconds in time output | | isUTC | boolean | false | Treat input date as UTC time |


🔧 API Highlights

Static methods

  • DateHelper.now(config?) → Create instance for current date/time

  • DateHelper.fromDateTupleAndTime(tuple, time?)

  • DateHelper.isSameDay(d1, d2)

  • DateHelper.timeStringToTime("13:45")

  • DateHelper.deltaMinutes(d1, d2)

  • DateHelper.getInstanceWithOffset(date, offset)

  • DateHelper.findPreviousMonthYear(month, year)

  • DateHelper.findNextMonthYear(month, year)

  • DateHelper.getLanguageConstants() → access MONTHS, WEEKDAYS, timeAgo etc.

Instance Methods

  • getDisplayDate() → "01 March 2024"

  • getDisplayTime() → "14:30"

  • getDisplayDateAndTime() → "01 March 2024 14:30"

  • getTimeRelativeToNow() → "3 minutes ago"

  • toISODate() → "2024-03-01"

  • toMoment() → returns a Moment.js instance


🧪 Testing

This package uses Bun for testing:

bun test

Example test:

import DateHelper from "@cantabile/date-helper";
import { describe, expect, it } from "bun:test";

describe("DateHelper", () => {
  it("should display correctly in B.E. (Thai)", () => {
    const dh = new DateHelper("2024-03-01", { lang: "th", useBD: true });
    expect(dh.getDisplayDate()).toBe("01 มีนาคม 2567");
  });
});

🪄 Build

bun run build

Outputs:

dist/
 ├─ index.mjs     (ESM)
 ├─ index.cjs     (CommonJS)
 ├─ index.d.ts    (TypeScript types)
 └─ *.map         (Source maps)

📜 License

Licensed under the ISC © Wallop Opasakhun (ChampClarinet)


💖 Support

If this library helps your work, you can support the maintainer here:

Buy Me a Coffee

Every cup fuels more open-source love and cleaner TypeScript for everyone! 💫