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

next-renew-js

v1.0.11

Published

A versatile JavaScript library for efficiently scheduling and managing upcoming renewals on a daily, weekly, monthly, or annual basis.

Downloads

10

Readme

next-renew-js

The next-renew-js library efficiently calculates upcoming renewal dates with flexible interval options. It seamlessly handles daily, weekly, monthly, or yearly scenarios, allowing you to customize calculations based on parameters like interval and start date. Ensure accurate results, even in special cases, for precise renewal date integration.

Installation

npm install next-renew-js

Options

| Option | Type | Description | | ------------------ | ----------------- | ----------- | | interval | number | Represents the interval in which the renewal occurs. Example: An interval of 2 means the renewal occurs every two days, weeks, months, or years. Optional. | | from | Date | Optional. Specifies the starting date from which the renewal should begin. Default: (current Date). | | numberOfRenewals | number | Optional. Indicates the total number of renewals that should occur. | | end_date | Date | Optional. Specifies an end date for the renewals. | | timezone | string | Optional. Specifies the timezone in which the renewals should occur. Default: undefined. | | type | string | Required. Specifies the type of renewal. Choose one of the following: day, week, month, year. | | weekDay | number | Required for week type. Specifies the day of the week for weekly renewal (0 for Monday, and so on). Accepted values: 0 to 6. | | monthDay | number | Required for month and year types. Specifies the day of the month when the renewal should happen. Accepted values: 1 to 31. | | month | number | Required for year type. Specifies the month of the year when the yearly renewal should happen. Accepted values: 0 to 11. |

Result

| Property | Type | Description | | -------- | -------- | ------------------------------------------------- | | date | Date | The date of the next renewal. | | list | Date[] | A list of upcoming renewal dates |

Usage

import nextRenew, { NextRenewOptions } from "next-renew-js";

const startingDate = new Date("2023-01-15T00:00:00.000Z")

const options: NextRenewOptions = {
  type: "month",
  monthDay: 25,
  from: startingDate, // Optional (for demonstration purposes)
};

console.log(result.date); // 2023-01-25T00:00:00.000Z
console.log(result.list); // [2023-01-25T00:00:00.000Z, 2023-02-25T00:00:00.000Z, 2023-03-25T00:00:00.000Z, ...]

In some scenarios, special situations may arise that go beyond the basic settings. One such case involves calculating the renewal day when it exceeds the maximum for the current month. In this context, if the specified day exceeds the maximum number of days in the current month, the library behaves in a special way, considering the last day of the month as the renewal day.

For example, if you specify the 31st day for monthly renewal and the current month has fewer than 31 days, the library will automatically adapt the calculation using the last day of the month.

import nextRenew, { NextRenewOptions } from "next-renew-js";

const startingDate = new Date("2023-01-15T00:00:00.000Z")

const options: NextRenewOptions = {
  type: "month",
  monthDay: 31,
  from: startingDate, // Optional (for demonstration purposes)
};

console.log(result.date); // 2023-01-31T00:00:00.000Z
console.log(result.list); // [2023-01-31T00:00:00.000Z, 2023-02-28T00:00:00.000Z, 2023-03-31T00:00:00.000Z, ...]

Utility Functions

The next-renew-js library provides the following utility functions for additional flexibility and convenience.

| Function | Description | | ------------------ | ---------------------------------------------------------------------------------------------------------------- | | monthsToMillis | Converts the specified number of months to milliseconds. | | daysToMillis | Converts the specified number of days to milliseconds. | | hoursToMillis | Converts the specified number of hours to milliseconds. | | minutesToMillis | Converts the specified number of minutes to milliseconds. | | cloneDate | Creates a new Date object with the same time value as the provided Date object. | | convertToLocale | Converts the provided date to the local timezone. | | convertToUTC | Converts the provided date to Coordinated Universal Time (UTC) based on the specified timezone. | | numDays | Calculates the number of days between two given dates. | | weekDayDistance | Calculates the distance (number of days) between two weekdays (e.g., Monday to Friday). |