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

actionabledate

v0.0.2

Published

Identify when to act acrross iterations of a date value.

Downloads

2

Readme

Node.js CI install size License node version

ActionableDate

Get triggerred when a date passes. This NodeJS module allows you to track changes in dates and get triggered when a specified date has passed. If subsequent observations of the specified date yield different values, then it will trigger accordingly.

Example usecase

You may want to send an e-mail to support staff to prepare for an employee's departure from the company. You observe an employeeLastDay Date field in HR. You calculate employeeLastDay-10 days as the day when you send the e-mail. You run a repeat batch to make this observation and decide when to act. While you make repeat observations, e.g. daily, the employeeLastDay field may change. On the last working day an employee may decide to stay on longer. They may decide to stop earlier than previously announced. By feeding the calculated employeeLastDay-10 days into ActionableDevice it will trigger three types of events:

  • Announce: There is no prior history and the specified date has passed. This is when you would send the e-mail.
  • Cancel: The specified date changed to null or changed to a future date, which renders an earlier Announce obsolete. At this point in time there is no need to act. Use this event to alert support staff no action is needed at this time.
  • Move: The specified date changed, but is still in the past. Inform support staff of the updated timestamp.

Installation

npm install actionabledate --save

Using CommonJS:

const ActionableDate = require('actionabledate');

Using TypeScript:

import * as ActionableDate from 'actionabledate';

Usage

The actionabledate module exports the track function which takes newDate als the most recent observation of the timestamp under consideration. It takes oldDate as the most recent prior observation of that date and oldDone as the most recent prior observation of wether the passing of newDate has already lead to an Announce.

`ActionableDate.track({
    newDate: new Date('2020-01-01'), 
    oldDate: null,
    oldDone: null,
    onSaveDate: (date: Date | null) => {
        // save the new date value
    },
    onSaveDone: (done: boolean) => {
        // save the done state
    },
    onAnnounce: () => {
        // take action when the date is met and hasn't been announced before
    },
    onMove: () => {
        // take action when the date is met but has been moved from a previously announced date
    },
    onCancel: () => {
        // take action to cancel if previously announced action is no longer valid
    }
});

If newDate differs from oldDate then onSaveDate is called and you are required to persist the updated date until the next iteration of the batch. Similarly onSaveDone is called to indicate wether an Announce or Move has been made. ActionableDate sets done to true after calling onAnnounce and onMove. It sets done to false after calling onCancel.