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

crontalk

v0.0.24

Published

A pure JS parser for natural language repeated events expressions

Downloads

4

Readme

crontalk v0.0.24

A pure JS parser for natural language repeated events expressions

coverage/lcov-report/index.html coverage/lcov-report/index.html

Installation

npm install --save crontalk

Why?

Tired of messing with asterisks when scheduling jobs? Crontalk allows you to easily parse natural language expressions such as "every 3 days from next monday" and convert them to a JS object.

Usage

const ct = require('crontalk');

let occurrences = ct.parse('every 3 days from the last day of september this year');

console.log(occurrences);

Structure of the returned object

The parser returns a JS object representing the schedule. The object structure depends on the clauses used in the expression.

Every (frequency)

The first format of the every clause allows you to specify the frequency of repetition. For instance, the expression

every 3 days and 5 hours and 2 minutes

results in the following object:

"span": {
	"days": 3,
	"hours": 5,
	"minutes": 2
}

Lapse

The from...to construct (Lapse clause) lets you define a time interval during which to apply the rule. The following example:

every three days from the 12th of june 2017 to the 3rd of september 2017

will give you the object:

"span": {
	"days": 3,
	"lapse": {
		"from": {
			"day": 12,
			"month": 5,
			"year": 2017
		},
		"to": {
			"day": 2,
			"month": 8,
			"year": 2017
		}
	}
}

You can use constructions such as "the last day of november" or "the second last minute of the fourth hour". The "last" keyword will yield negative values for the related unit of measure (-1 means last, -2 means second last, etc).

Every (phase)

The second format of the every clause must be used in conjuntion with a Lapse clause and allows you to specify a condition for the repetition. Consider the following example:

every third january from february 1980 to 1999

this results in:

"span": {
	"years": 3,
	"lapse": {
		"from": {
			"year": 1980,
			"month": 1
		},
		"to": {
			"year": 1999
		}
	},
	"on": {
		"year": 2,
		"_month": 0
	}
}

Note the "_month" property. The underscore in front of the unit name in the "on" property means that property must be interpreted as an absolute offset, not a relative one. I.E. "_month": 0 always means January, while "month": 0 means the first month of the Lapse clause.

Deixis

Your can use the keywords "this", "last", "next", and "today", "yesterday", and "tomorrow" in most places when it's appropriate. This will result in the values "this", "last", and "next", being returned instead of a number in the related property of the object.

every 3 days from last year

Will be transformed into:

"span": {
	"days": 3,
	"lapse": {
		"from": {
			"year": "last" 
		}
	}
}

Documentation

Install the package and look at /docs/railroad.html for the railroad diagrams of Crontalk's DSL.

Look at the tests for usage examples.

Licensing

This package is released under the MIT License