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

crondate

v1.0.1

Published

Class to create and manage cron-friendly dates.

Downloads

3

Readme

CronDate

CronDate is a small JavaScript class to create and manage cron-friendly dates.

1. Introduction

Cron is a very powerful tool. CronDate is only a JavaScript class that can manipulate (JavaScript objects that represent) dates that are cron-friendly.

What is a cron-friendly date?

A cron-friendly date is a date representation that fits the type of date representations that cron expects to find.

What is CronDate for, then?

CronDate was made in order to be combined with other tools, or directly with cron itself. So, in a few words, to ease the management of dates that follow the cron format.

Note: there are different implementations of cron. We use as reference the standard cron syntax.

2. Installation

You can install CronDate from NPM. From your command-line, type:

~$ npm install crondate

3. Usage

1) Import the module from your code:

var CronDate = require("crondate");

2) Create a new CronDate:

var crondate1 = new CronDate();
var crondate2 = CronDate();
var crondate3 = CronDate({
  minute: 5,
  hour: 3,
  day: 5,
  month: 10,
  dayOfWeek: 1
});

3) Override the default values of the date:

crondate1.set({
  day: 25,
  month: 12,
  hour: "*",
  minute: 0
});

4) Obtain the string (the true cron date now):

var cronRef1 = crondate1.asString();
// Expect: "0 * 25 12 *"

4. Reference: CronDate API

1) The format for cron dates is:

{minute} {hour} {day} {month} {day of the week}

2) The default value that CronDate takes is:

0 * * * *

Which means:

for minute 0 of every hour, of every day, of every month and in any day of the week

3) Methods of a CronDate instance:

{CronDate}.set(overrider)

Description:

You can use this method to change the minute, hour, day, month or dayOfWeek of the current {CronDate} instance.

Parameters:
  • overrider: {Object} set of properties and values to be added to the CronDate instance. Mainly, you will want to modify: minute, hour, day, month, dayOfWeek.
Returns

The {CronDate} instance itself.

{CronDate}.asString()

Description:

With this method, you can obtain the {CronDate} instance representation, in a cron-friendly format.

Returns

A {String} representing the current state of this {CronDate} instance, but in a cron-friendly format.

4) Properties of a CronDate instance:

  • minute: by default 0.

  • hour: by default *.

  • day: by default *.

  • month: by default *.

  • dayOfWeek: by default *.