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

pikola

v0.1.4

Published

Library for advanced scheduling

Downloads

4

Readme

Pikola.js - Advanced scheduling library

Build Status Coverage Status npm version Dependency Status

This project is under heavy development. New functionality will be added continuously. It is not recommended to use it in production scenario just yet.

Installation

npm install pikola --save

Usage

Importing pikola library

import pikola from 'pikola'

Creating a trigger

const trigger = pikola()

The default trigger fires every millisecond. (theoretically) you can modify it with provided functions.

  • EveryMillisecond(interval)
  • EverySecond(interval)
  • EveryMinute(interval)
  • EveryHour(interval)
  • EveryDay(interval)
  • EveryWeek(interval)
  • EveryMonth(interval)
  • OnMillisecond(orderNumber)
  • OnSecond(orderNumber)
  • OnMinute(orderNumber)
  • OnHour(orderNumber)
  • OnDayOfWeek(orderNumber)
  • OnDayOfMonth(orderNumber)
  • OnWeek(orderNumber)

Functions starting with Every will return a trigger which will execute in specified interval. For example:

const trigger = pikola()
    .EveryMonth(4)

will execute every 4 months. The interval has to be at least 1.

Functions starting with On will return a trigger executing exactly on that specific date or time (in theory - milliseconds are tricky). The order number parameter of these functions is zero based.

For example this trigger will execute on the first day of every week (Monday):

const trigger = pikola()
    .OnDayOfWeek(0)

You can combine these function to customize the result trigger.

const trigger = pikola()
    .EveryMonth(4)
    .OnWeek(1)
    .OnDayOfWeek(4)
    .EveryHour(4)
    .OnMinute(21)
    .OnSecond(12)
    .EveryMillisecond(333)

This trigger will execute every four months on the second week of that particular month on the fourth day of that week every four hours on every 21st minute on 12th second and inside that second every 333 milliseconds. (Total insanity)

Order of calling these functions doesn't matter following example will produce the same result. It's recommended though to start from the highest resolution. It's more readable that way

const trigger = pikola()
  .EveryMillisecond(333)
  .OnSecond(12)
  .OnWeek(1)
  .EveryMonth(4)
  .EveryHour(4)
  .OnDayOfWeek(4)
  .OnMinute(21)

After defining a trigger you can check future (or past) execution date calling the GetExecutionDatesAfter function as following:

const trigger = pikola()....

const numberOfDates = 10
const from = new Date()

const dates = trigger.GetExecutionDatesAfter(from, numberOfDates)

This will return an array of dates specifying planned execution dates from the specified date.

For actually executing the trigger you need to first hook to an OnFire event and then call the start function as following example illustrates:

import pikola from 'pikola'

const trigger = pikola()
.EverySecond(2)
.OnMillisecond(333)
.OnFire(() => {
  //do your trigger stuff here
})

trigger.Start()

Inside the OnFire callback you can return false to stop it.

Roadmap

There is so much more stuff I want to add to this library but here is a simple list of some of the ones that will come first:

  • [ ] Possibility to define multiple On recurrences something like OnHour(1,4,8,22)
  • [ ] Internationalization - Some values are now fixed. like for example that Monday is the first day of the week. That needs to be changed
  • [ ] Better validation mechanism. Some combinations of functions forming trigger doesn't make too much sense. Throw warning about them (e.g. trigger.EveryHour(2).EveryMinute(80))
  • [ ] Control functions for limiting boundaries of certain layers (e.g. FromHour - ToHour)
  • [ ] Control functions for stopping the trigger. (Returning false in callback just won't cut it)
  • [ ] CRON adapter
  • [ ] Think about what to do with timezones