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

tempex

v0.0.3

Published

temporal expressions, somehow similar to Martin Fowler's

Downloads

6

Readme

Temporal Expressions in Javascript

Introduction

Temporal expressions allow defining and querying recurring events on calendars. This little library roughly follows the ideas of Martin Fowler's article about recurring events.

Example: Races take place Wednesdays in summer (September until April, in the Southern Hemisphere) and Saturdays in winter (May until August).

var t = require('tempex');

var winterMonths = t.months([4, 5, 6, 7]); // we use Javascript convention: May=4, June=5, ...
var summerMonths = t.negate(winterMonths);
var raceSchedule = t.union([
  // summer
  t.intersectionOf(
    summerMonths,
    t.onWeekdays([ 3 ]) // Wednesday=3
  ),
  // winter
  t.intersectionOf(
    winterMonths,
    t.onWeekdays([ 6 ]) // Saturdays=6
  ),
])

To determine the actual occurrences (days) of this schedule in a time range:

t.occurrences(raceSchedule, new Date(2015, 2, 1), new Date(2015, 5, 31));

will produce:

[ Wed Mar 04 2015 00:00:00 GMT+0200 (SAST),
  Wed Mar 11 2015 00:00:00 GMT+0200 (SAST),
  Wed Mar 18 2015 00:00:00 GMT+0200 (SAST),
  Wed Mar 25 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 01 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 08 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 15 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 22 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 29 2015 00:00:00 GMT+0200 (SAST),
  Sat May 02 2015 00:00:00 GMT+0200 (SAST),
  Sat May 09 2015 00:00:00 GMT+0200 (SAST),
  Sat May 16 2015 00:00:00 GMT+0200 (SAST),
  Sat May 23 2015 00:00:00 GMT+0200 (SAST),
  Sat May 30 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 06 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 13 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 20 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 27 2015 00:00:00 GMT+0200 (SAST) ]

If we want to express that there won't be races during the Easter holidays:

var holidays = t.intersectionOf( t.onOrAfter(new Date(2015, 2, 30)), t.onOrBefore(new Date(2015, 3, 17))) var raceDays = t.intersectionOf(raceSchedule, t.negate(holidays))

Then

t.occurrences(raceDays, new Date(2015, 2, 1), new Date(2015, 5, 31))

will give us the occurrences:

[ Wed Mar 04 2015 00:00:00 GMT+0200 (SAST),
  Wed Mar 11 2015 00:00:00 GMT+0200 (SAST),
  Wed Mar 18 2015 00:00:00 GMT+0200 (SAST),
  Wed Mar 25 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 22 2015 00:00:00 GMT+0200 (SAST),
  Wed Apr 29 2015 00:00:00 GMT+0200 (SAST),
  Sat May 02 2015 00:00:00 GMT+0200 (SAST),
  Sat May 09 2015 00:00:00 GMT+0200 (SAST),
  Sat May 16 2015 00:00:00 GMT+0200 (SAST),
  Sat May 23 2015 00:00:00 GMT+0200 (SAST),
  Sat May 30 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 06 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 13 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 20 2015 00:00:00 GMT+0200 (SAST),
  Sat Jun 27 2015 00:00:00 GMT+0200 (SAST) ]

API Documentation

Is here.