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

hijrah-date-ts

v1.0.1

Published

TypeScript definitions and implementation for hijrah-date

Readme

hijrah-date-ts

TypeScript implementation of the hijrah-date library with full backward compatibility.

Installation

npm install hijrah-date-ts

Usage

import HijrahDate, { HijriMonth } from 'hijrah-date-ts';

// Create a new Hijri date
const hijriDate = new HijrahDate(1444, HijriMonth.RAMADAN, 15);

// Convert to Gregorian
const gregorianDate = hijriDate.toGregorian();
console.log(gregorianDate); // JS Date object

// Get today's date in Hijri calendar
const today = HijrahDate.now();
console.log(today.format('yyyy-MM-dd')); // e.g., 1444-09-15

// Format a date
console.log(hijriDate.format('dd/MM/yyyy')); // 15/09/1444

// Parse a date string
const parsedDate = HijrahDate.parse('1444-09-15');

// Add days, months, or years
const nextMonth = hijriDate.plusMonths(1);
const nextYear = hijriDate.plusYears(1);
const tenDaysLater = hijriDate.plusDays(10);

// Compare dates
if (hijriDate.isBefore(nextMonth)) {
  console.log('hijriDate is before nextMonth');
}

// Get month name
console.log(hijriDate.getMonthName()); // رمضان
console.log(hijriDate.getMonthNameEn()); // Ramadan

// Register adjustments (for different calculation methods)
HijrahDate.registerAdjustments([
  { month: 8, days: 1 } // Adjust Ramadan by +1 day
]);

API Reference

Class: HijrahDate

Static Methods

  • now(): Returns current date as HijrahDate
  • fromGregorian(date: Date): Converts Gregorian date to HijrahDate
  • parse(dateStr: string): Parses string in format "yyyy-MM-dd" to HijrahDate
  • daysInMonth(year: number, month: number): Returns days in specific Hijri month
  • isLeapYear(year: number): Checks if year is a Hijri leap year
  • registerAdjustments(adjustments: AdjustmentOptions[]): Registers custom adjustments
  • daysBetween(start: HijrahDate, end: HijrahDate): Calculates days between two dates

Instance Methods

  • toGregorian(): Converts to JavaScript Date object
  • format(format?: string): Formats date with optional pattern
  • getFullYear(): Returns Hijri year
  • getMonth(): Returns Hijri month (0-based)
  • getDate(): Returns day of month
  • getDay(): Returns day of week (0 = Sunday)
  • plusDays(days: number): Adds days and returns new date
  • plusMonths(months: number): Adds months and returns new date
  • plusYears(years: number): Adds years and returns new date
  • compareTo(other: HijrahDate): Compares with another date
  • equals(other: HijrahDate): Checks if dates are equal
  • isBefore(other: HijrahDate): Checks if this date is before other
  • isAfter(other: HijrahDate): Checks if this date is after other
  • toString(): Returns string representation
  • endOfMonth(): Returns date representing last day of month
  • startOfMonth(): Returns date representing first day of month
  • getMonthName(): Returns Arabic name of month
  • getMonthNameEn(): Returns English name of month
  • getDayName(): Returns Arabic name of day of week
  • getDayNameEn(): Returns English name of day of week

Enum: HijriMonth

Constants for Hijri months (0-based):

  • MUHARRAM: 0
  • SAFAR: 1
  • RABI_AL_AWWAL: 2
  • RABI_AL_THANI: 3
  • JUMADA_AL_AWWAL: 4
  • JUMADA_AL_THANI: 5
  • RAJAB: 6
  • SHABAN: 7
  • RAMADAN: 8
  • SHAWWAL: 9
  • DHU_AL_QIDAH: 10
  • DHU_AL_HIJJAH: 11

Interface: AdjustmentOptions

  • days?: number: Days adjustment (positive or negative)
  • month?: number: Specific month to adjust (0-based)
  • year?: number: Specific year to adjust

IMPORTANT:
npm run test yields 1 failed test (as of 17th Mar 2025):

npm run test

Any contributions appreciated 🙏🏻🙇🏻

License

MIT