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

hijri-utils

v1.0.1

Published

A lightweight, zero-dependency JavaScript utility library for Hijri (Islamic calendar) date conversions and operations.

Readme

hijri-utils

A lightweight, zero-dependency JavaScript utility library for Hijri (Islamic calendar) date conversions and operations.

  • Convert between Gregorian and Hijri dates
  • Get the current Hijri date
  • Format Hijri dates as readable strings (English & Arabic)
  • Compare Hijri dates
  • Check leap years and month lengths
  • Works fully offline — uses the tabular/arithmetic algorithm (no API calls)
  • Supports both CommonJS (require) and ESM (import)

Installation

npm install hijri-utils

Quick Start

// ESM
import { toHijri, formatHijri } from 'hijri-utils';

// CommonJS
const { toHijri, formatHijri } = require('hijri-utils');

const hijri = toHijri(new Date());
console.log(formatHijri(hijri)); // "14 Shawwal 1447"

API Reference

toHijri(date) / toHijri(year, month, day)

Convert a Gregorian date to a Hijri date.

Parameters:

| Param | Type | Description | |-------|------|-------------| | date | Date | A JavaScript Date object | | year | number | Gregorian year (alternative form) | | month | number | Gregorian month, 1-12 (alternative form) | | day | number | Gregorian day (alternative form) |

Returns: { year: number, month: number, day: number }

toHijri(new Date(2025, 0, 1));    // { year: 1446, month: 7, day: 1 }
toHijri(2025, 1, 1);              // { year: 1446, month: 7, day: 1 }

toGregorian(year, month, day)

Convert a Hijri date to a Gregorian Date object.

Parameters:

| Param | Type | Description | |-------|------|-------------| | year | number | Hijri year | | month | number | Hijri month (1-12) | | day | number | Hijri day |

Returns: Date

toGregorian(1446, 7, 1);
// Date: 2025-01-01T00:00:00.000

getCurrentHijri()

Get today's Hijri date.

Returns: { year: number, month: number, day: number }

getCurrentHijri();
// { year: 1447, month: 10, day: 14 }  (example)

formatHijri(hijriDate, options?)

Format a Hijri date as a human-readable string.

Parameters:

| Param | Type | Description | |-------|------|-------------| | hijriDate | { year, month, day } | A Hijri date object | | options.locale | 'en' | 'ar' | Language for month name (default: 'en') |

Returns: string

formatHijri({ year: 1446, month: 9, day: 15 });
// "15 Ramadan 1446"

formatHijri({ year: 1446, month: 9, day: 15 }, { locale: 'ar' });
// "15 رمضان 1446"

compareHijri(a, b)

Compare two Hijri dates. Works as an Array.sort comparator.

Parameters:

| Param | Type | Description | |-------|------|-------------| | a | { year, month, day } | First Hijri date | | b | { year, month, day } | Second Hijri date |

Returns: -1 if a < b, 0 if equal, 1 if a > b

const a = { year: 1445, month: 12, day: 10 };
const b = { year: 1446, month: 1, day: 1 };

compareHijri(a, b); // -1 (a is before b)

// Sort an array of Hijri dates
const dates = [b, a];
dates.sort(compareHijri);
// [a, b]

isHijriLeapYear(year)

Check if a Hijri year is a leap year in the 30-year tabular cycle.

Leap years are years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29 within each cycle.

Parameters:

| Param | Type | Description | |-------|------|-------------| | year | number | Hijri year |

Returns: boolean

isHijriLeapYear(1436); // true
isHijriLeapYear(1446); // false

hijriMonthDays(year, month)

Get the number of days in a given Hijri month.

Parameters:

| Param | Type | Description | |-------|------|-------------| | year | number | Hijri year | | month | number | Hijri month (1-12) |

Returns: number (29 or 30)

hijriMonthDays(1446, 1);   // 30 (Muharram — odd month)
hijriMonthDays(1446, 2);   // 29 (Safar — even month)
hijriMonthDays(1436, 12);  // 30 (Dhul Hijjah in a leap year)

HIJRI_MONTHS_EN / HIJRI_MONTHS_AR

Arrays of the 12 Hijri month names in English and Arabic.

HIJRI_MONTHS_EN[0];  // "Muharram"
HIJRI_MONTHS_EN[8];  // "Ramadan"
HIJRI_MONTHS_AR[8];  // "رمضان"

Algorithm

This library uses the tabular Islamic calendar (arithmetic/civil algorithm) for conversions. It is based on a fixed 30-year cycle and does not depend on moon sighting or astronomical observation. Results may differ by ±1–2 days from the observational Hijri calendar used in some countries.

All conversions go through an intermediate Julian Day Number (JDN):

Gregorian → JDN → Hijri
Hijri → JDN → Gregorian

Requirements

  • Node.js >= 18.0.0
  • Zero runtime dependencies

Running Tests

npm test

Tests use Node's built-in test runner (node:test).

License

MIT