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

@saugatedith/isleap

v1.0.0

Published

Zero-dependency utility to check leap years, with full edge-case handling, TypeScript types, and calendar-system awareness.

Readme

@saugatedith/isleap

Zero-dependency utility to check leap years — Gregorian, Julian, and proleptic.
Includes TypeScript types, edge-case handling, and a rich set of helper functions.

npm version license


Installation

npm install @saugatedith/isleap

Quick start

const { isLeap } = require("@saugatedith/isleap");

isLeap(2024);  // true
isLeap(1900);  // false  ← century, not divisible by 400
isLeap(2000);  // true   ← divisible by 400
isLeap(2023);  // false

Or use isLeapYear — both do the same thing:

const { isLeapYear } = require("@saugatedith/isleap");

isLeapYear(2024);  // true
isLeapYear(1900);  // false  ← century, not divisible by 400
isLeapYear(2000);  // true   ← divisible by 400
isLeapYear(2023);  // false

Calendar rules

Gregorian (default, ISO 8601)

| Condition | Leap? | |------------------------------------|-------| | Divisible by 400 | ✅ Yes | | Divisible by 100 (but not by 400) | ❌ No | | Divisible by 4 (but not by 100) | ✅ Yes | | Not divisible by 4 | ❌ No |

Julian

Simply: divisible by 4 → leap. No century exception.
Used before the Gregorian reform of 1582.


API

All functions that accept a year throw a TypeError if the value is not a finite integer.


isLeap(year)boolean

Alias for isLeapYear(). Simple leap year check matching the package name.

isLeap(2024)   // true
isLeap(1900)   // false
isLeap(2000)   // true
isLeap(0)      // true  (year 0 = 1 BC, proleptic Gregorian)
isLeap(-4)     // true  (5 BC)

isLeapYear(year)boolean

Gregorian leap year check (same as isLeap).

isLeapYear(2024)   // true
isLeapYear(1900)   // false
isLeapYear(2000)   // true
isLeapYear(0)      // true  (year 0 = 1 BC, proleptic Gregorian)
isLeapYear(-4)     // true  (5 BC)

isLeapYearJulian(year)boolean

Julian calendar leap year check.

isLeapYearJulian(1900)  // true  ← unlike Gregorian
isLeapYearJulian(2023)  // false

daysInFebruary(year)28 | 29

daysInFebruary(2024)  // 29
daysInFebruary(2023)  // 28

daysInYear(year)365 | 366

daysInYear(2024)  // 366
daysInYear(2023)  // 365

nextLeapYear(year)number

Returns the next leap year ≥ year.

nextLeapYear(2023)  // 2024
nextLeapYear(2024)  // 2024  (same year counts)
nextLeapYear(2025)  // 2028
nextLeapYear(1900)  // 1904  (century skip)

prevLeapYear(year)number

Returns the previous leap year ≤ year.

prevLeapYear(2023)  // 2020
prevLeapYear(2024)  // 2024
prevLeapYear(1900)  // 1896

leapYearsInRange(start, end)number[]

Returns every leap year in [start, end], inclusive.

leapYearsInRange(2000, 2020)
// [2000, 2004, 2008, 2012, 2016, 2020]

leapYearsInRange(1897, 1905)
// [1904]   ← 1900 excluded (century non-leap)

Throws RangeError if start > end.


countLeapYears(start, end)number

Counts leap years in [start, end] using an O(1) formula (no loop).

countLeapYears(1900, 2000)  // 25
countLeapYears(2000, 2024)  // 7

Throws RangeError if start > end.


yearInfo(year)YearInfo

Returns a structured info object.

yearInfo(2024)
// {
//   year:           2024,
//   isLeap:         true,
//   daysInYear:     366,
//   daysInFebruary: 29,
//   nextLeap:       2024,
//   prevLeap:       2024,
//   calendar:       "Gregorian"
// }

TypeScript

Full types are included out of the box — no @types/ package needed.

import { isLeap, isLeapYear, yearInfo, YearInfo } from "@saugatedith/isleap";
const leap: boolean    = isLeapYear(2024);
const leap: boolean    = isLeap(2024);      // or use isLeapYear
const info: YearInfo   = yearInfo(2024);

Common gotchas

| Year | Gregorian | Julian | Why | |------|-----------|--------|-----| | 1900 | ❌ No | ✅ Yes | century non-leap in Gregorian | | 2000 | ✅ Yes | ✅ Yes | divisible by 400 in Gregorian | | 0 | ✅ Yes | ✅ Yes | year 0 = 1 BC | | -100 | ❌ No | ✅ Yes | century rule applies negatively |


Running tests

npm test

License

MIT © Your Name