Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ordermentum/lunartick

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ordermentum/lunartick

[![npm version](https://badge.fury.io/js/lunartick.svg)](https://badge.fury.io/js/lunartick) [![Build Status](https://travis-ci.org/ordermentum/lunartick.svg?branch=master)](https://travis-ci.org/ordermentum/lunartick) [![npm](https://img.shields.io/npm/l

  • 0.0.19
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Lunartick

npm version Build Status npm npm

Description

Based on the RFC5545 spec for Internet Calendaring and Scheduling Core Object Specification.

Lunartick!! ... get it!?

It's a pun on lunar and a crazy person, because that's what I feel like after working on this. It's a joke.

Anyway...

Lunartick allows you to parse an RRULE string to return an object of the properties in JS format. The returned object has an iterator() to either get the next run time based on a start time passed in (.getNext())or over the next X instances based on the RRULE COUNT or defaults to 1000 if no COUNT is present. If no start date is given, it will fetch the next run time based on the current time.

Please note that this package only supports ES6 friendly codebases.

Usage

NPM users

npm i lunartick

Yarn users

yarn add lunartick

Import the library and pass in an RRULE string to the .parse() method. The resulting instance supports the following properties: frequency, interval, count, bySetPos, byYearDay, byMonth, byMonthDay, byWeekNo, byEaster, byDay, byHour, byMinute, bySecond, tzId and dtStart.

const Rule = require('lunartick');
const rruleString = 'FREQ=DAILY;INTERVAL=1;BYHOUR=14;BYMINUTE=3;BYSECOND=0;DTSTART=19701101T020000';
const rule = Rule.parse(rruleString);
 /*{
   frequency: 2,
   interval: 1,
   byHour: [14],
   byMinute: [3],
   bySecond: [0],
   dtStart: '19701101T020000'
}*/

Once a string has been parsed, it can be converted back to an RRULE string using the .toString() method. This method does not take any parameters.

const string = rule.toString();
// 'FREQ=DAILY;INTERVAL=1;BYHOUR=14;BYMINUTE=3;BYSECOND=0;DTSTART=19701101T020000'

To fetch the next run time for this schedule call the .getNext() method with an optional from date, you can pass in the .dtStart property if you want to use it. If no from date is passed in, it will fetch the next run time base on the current time.

const nextRun = rule.getNext(rule.dtStart);
// Sun Nov 01 1970 14:03:00 GMT+1000

The rule instance will also have an iterator to fetch the next X runtimes for the rule. You can use a for-of loop on rule.iterator() which takes two optional parameters. The first one is the from date (default is also the current time). The second parameter is how many iterations should be fetched. If a number is passed in, it will take precedence, if a .count property exists in the rule, it will be used next and if neither are available it will default to 52 iterations.

const iterator = rule.iterator(rule.dtStart, 5);

for (const nextDate of iterator) {
  nextDate.toString();
}
// OR
Array.from(iterator);
/*
  Sun Nov 01 1970 14:03:00 GMT+1000
  Mon Nov 02 1970 14:03:00 GMT+1000
  Tue Nov 03 1970 14:03:00 GMT+1000
  Wed Nov 04 1970 14:03:00 GMT+1000
  Thu Nov 05 1970 14:03:00 GMT+1000
*/

Limitations

  • Currently does not support multiple values for byDay, byHour, byMinute and bySecond.

Licensing

Lunartick is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Originally developed by Michael Cooper - Development sponsored by Ordermentum.

FAQs

Package last updated on 10 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc