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

schyntax

v1.0.3

Published

A simple utility for parsing schedule strings, and finding the next scheduled event time.

Downloads

23

Readme

schyntax

npm version Build Status

A simple Node.js utility for parsing Schyntax schedule strings, and finding the next scheduled event time.

Schyntax is not a scheduled task runner. It simply helps you determine when a task should run. If you're looking for a task runner built on Schyntax, try Schtick.

Install

npm install schyntax

Examples

Find the next weekday (Monday through Friday) at 16:00 UTC:

var schyntax = require('schyntax');

var schedule = schyntax('hours(16), days(mon..fri)');
console.log(schedule.next());

Find noon on the next day which isn't the Fourth of July or December 25th:

var schedule = schyntax('hours(12), dates(!12/25, !7/4)');
console.log(schedule.next());

Find the next seven dates which are either 10AM on a weekday, or noon on a weekend by using schedule groups (expressions grouped inside curly braces):

var schedule = schyntax('{hours(10), days(!sat..sun)} {hours(12), days(sat..sun)}');
var dates = [];
var d = null;
for (var i = 0; i < 7; i++) {
  d = schedule.next(d);
  dates.push(d);
}
console.log(dates);

Methods

schyntax#next

Accepts an optional after argument in the form of a Date object or numeric Unix timestamp in milliseconds. If no argument is provided, the current time is used.

Returns a Date object representing the next timestamp which matches the scheduling criteria. The date will always be greater than, never equal to, after. If no timestamp could be found which matches the scheduling criteria, a ValidTimeNotFoundError error is thrown, which generally indicates conflicting scheduling criteria (explicitly including and excluding the same day or time).

schyntax#previous

Same as schyntax#next accept that its return value will be less than or equal to the current time or optional atOrBefore argument. This means that if you want to find the last n-previous events, you should subtract at least a millisecond from the result before passing it back to the function. For example, here is the reverse of one of the prior examples:

var schedule = schyntax('{ hours(10), days(!sat..sun) } { hours(12), days(sat..sun) }');
var dates = [];
var d = null;
for (var i = 0; i < 7; i++) {
  d = schedule.previous(d ? d - 1 : null);
  dates.push(d);
}
console.log(dates);

Syntax

For complete documentation on the Schyntax domain-specific language, see the Schyntax project.