New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dzen

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dzen

A query language for describing repeating intervals

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
2
-50%
Maintainers
1
Weekly downloads
 
Created
Source

A query language for describing repeating task intervals

Yeah.. don't know how to describe it better. The language executes your query and returns the closest future date (rounded down to day) that matches. Think of it as a cron for humans.

Syntax examples

// "every" keyword in the beginning can be omitted
// plural and singular variations of the time unit keywords are interchangable (ex. day/days, week/weeks, month/months)
// "st", "nd", "rd" and "th" suffixes on the end of dates are required, but are interchangable
// "everyday" and "daily" are shorthands for "every day"
// "weekly" is a shorthand for "every week"
// "monthly" is a shorthand for "every month"
// "yearly" and "annually" are shorthands for "every year"
// oh, and also this thing is completely case-insensitive


// relative commands (add days to the "now")

every day     // now + 1d
every 2 days  // now + 2d
every week    // now + 7d
every month   // now + 1m
every year    // now + 1y
every 5 years // now + 5y

// absolute commands (pick a nearest future date from the "now", that matches a certain query)

every sunday
every monday, tuesday, wednesday

every 8th
every 1st, 10th, 16th

every 32nd // error
every 8th, 10th, 32nd // error

every february 8th
every 1st, january 2nd, january 3rd, february 11th, march 21st

// execute arbitrary functions to calculate task offset in days
// (unsafe JavaScript code execution, this feature is turned off by default but can be enabled in settings for more advanced queries)

every f{:: (now) => Math.random() * 10 ::}

Usage

npm install dzen
import Dzen from "./classes/dzen";
import DzenError from "./classes/error";

const text = "every 5 days";

const dzen = new Dzen({
    now: new Date(), // can be any date object
    settings: {
        allowUnsafeCodeExecution: false // turn on to allow executing arbitrary JavaScript functions in queries
    }
});

const result = dzen.runLine(text); // you can also use dzen.runBlock(text) to run multiple queires at once

if (result instanceof DzenError) {
    console.log(result.toString());
} else {
    console.log(result.toLocaleDateString());
}

Keywords

dzen

FAQs

Package last updated on 13 Feb 2023

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