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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gennyboy/leap-year-finder

v1.0.1

Published

A library with handy methods for identifying leap years or determining if a given year is a leap year.

Downloads

2

Readme

leap-year-finder

leap-year-finder is a simple JavaScript library that provides functions for calculating leap years.

Install

$ npm install @gennyboy/leap-year-finder

Usage

To use the package, import the desired functions and call them with the appropriate arguments.

import { isLeapYear, getNextLeapYear } from "@gennyboy/leap-year-finder";

isLeapYear(2020); // true
getNextLeapYear(2020); // 2024

API

isLeapYear(year)

Returns true if the given year is a leap year, false otherwise.

year

The year to check. If not specified, the current year is used.

Must be a number or a Date object.

isLeapYear(2020);
//=> true

isLeapYear(2021);
//=> false

isLeapYear(); // Check if the current year is a leap year or not.

isCurrentYearLeap()

Returns true if the current year is a leap year, false otherwise.

// Executes in 2020
isCurrentYearLeap();
//=> true

// Executes in 2021
isCurrentYearLeap();
//=> false

getNextLeapYear(year)

Returns the next leap year after the given year (or the current year if not specified).

year

The year to check. If not specified, the current year is used.

Must be a number or a Date object.

getNextLeapYear(2019);
//=> 2020

getNextLeapYear(2020);
//=> 2024

// Executes in 2019
getNextLeapYear();
//=> 2020

getPreviousLeapYear(year)

Returns the previous leap year before the given year (or the current year if not specified).

year

The year to check. If not specified, the current year is used.

Must be a number or a Date object.

getPreviousLeapYear(2021);
//=> 2020

getPreviousLeapYear(2020);
//=> 2016

// Executes in 2021
getPreviousLeapYear();
//=> 2020

getNextLeapYears(numberOfYears, year)

Returns an array of the next numberOfYears leap years after the given year (or the current year if not specified).

numberOfYears

The number of leap years to return.

Must be a number in range of 1 to 10.

year

The year to check. If not specified, the current year is used.

Must be a number or a Date object.

getNextLeapYears(3, 2020);
//=> [2024, 2028, 2032]

getNextLeapYears(3, 2019);
//=> [2020, 2024, 2028]

// Executes in 2019
getNextLeapYears(3);
//=> [2020, 2024, 2028]

getPreviousLeapYears(numberOfYears, year)

Returns an array of the previous numberOfYears leap years before the given year (or the current year if not specified).

numberOfYears

The number of leap years to return.

Must be a number in range of 1 to 10.

year

The year to check. If not specified, the current year is used.

Must be a number or a Date object.

getPreviousLeapYears(3, 2020);
//=> [2016, 2012, 2008]

getPreviousLeapYears(3, 2021);
//=> [2020, 2016, 2012]

// Executes in 2021
getPreviousLeapYears(3);
//=> [2020, 2016, 2012]

getDateForLastDayOfFebruary(year)

Returns the date object for the last day of February for the given year (or the current year if not specified).

year

The year to check. If not specified, the current year is used.

Must be a number or a Date object.

getDateForLastDayOfFebruary(2020);
//=> Sat Feb 29 2020 00:00:00 GMT+0900

getDateForLastDayOfFebruary(2021);
//=> Sun Feb 28 2021 00:00:00 GMT+0900

// Executes in 2021
getDateForLastDayOfFebruary();
//=> Sun Feb 28 2021 00:00:00 GMT+0900

getDateForNextLeapYearLastDayOfFebruary()

Returns the date object for the last day of February for the next leap year.

// Executes in 2019
getDateForNextLeapYearLastDayOfFebruary();
//=> Sat Feb 29 2020 00:00:00 GMT+0900

// Executes in 2020
getDateForNextLeapYearLastDayOfFebruary();
//=> Sat Feb 29 2024 00:00:00 GMT+0900

getDateForPreviousLeapYearLastDayOfFebruary()

Returns the date object for the last day of February for the previous leap year.

// Executes in 2021
getDateForPreviousLeapYearLastDayOfFebruary();
//=> Sun Feb 28 2020 00:00:00 GMT+0900

// Executes in 2020
getDateForPreviousLeapYearLastDayOfFebruary();
//=> Sun Feb 28 2016 00:00:00 GMT+0900