vangware / cron

⏲️ Cron Quartz and Cron UNIX expression parser.

Home Page:https://lou.codes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This repository's code was moved to lou.codes.


Coverage License NPM Version Open Issues

⏲️ Cron Quartz and Cron UNIX expression parser.

Usage

📦 Node

Install @vangware/cron as a dependency:

pnpm add @vangware/cron
# or
npm install @vangware/cron
# or
yarn add @vangware/cron

Import it and use it:

import { parseStringQuartz, parseCronQuartz } from "@vangware/cron";

const cron = parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10");
/*
	{
		seconds: { every: 3, start: { from: 1, to: 2 } },
		minutes: [{ from: 1, to: 2 }, 3, 4],
		hours: "*",
		dayOfMonth: { nearest: 2 },
		month: ["SEP", "OCT"],
		dayOfWeek: { last: 1 },
		year: { every: 10, start: "*" }
	}
*/

parseCronQuartz(cron); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10"

🦕 Deno

Import @vangware/cron using the npm: prefix, and use it directly:

import { parseStringQuartz, parseCronQuartz } from "npm:@vangware/cron";

const cron = parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10");
/*
	{
		seconds: { every: 3, start: { from: 1, to: 2 } },
		minutes: [{ from: 1, to: 2 }, 3, 4],
		hours: "*",
		dayOfMonth: { nearest: 2 },
		month: ["SEP", "OCT"],
		dayOfWeek: { last: 1 },
		year: { every: 10, start: "*" }
	}
*/

parseCronQuartz(cron); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10"

🌎 Browser

Import @vangware/cron using esm.sh, and use it directly:

<script type="module">
	import {
		parseStringQuartz,
		parseCronQuartz,
	} from "https://esm.sh/@vangware/cron";

	const cron = parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10");
	/*
		{
			seconds: { every: 3, start: { from: 1, to: 2 } },
			minutes: [{ from: 1, to: 2 }, 3, 4],
			hours: "*",
			dayOfMonth: { nearest: 2 },
			month: ["SEP", "OCT"],
			dayOfWeek: { last: 1 },
			year: { every: 10, start: "*" }
		}
	*/

	parseCronQuartz(cron); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10"
</script>

Useful links

To do

A big change is coming with stricter types and a better DX. Stay tuned.

About

⏲️ Cron Quartz and Cron UNIX expression parser.

https://lou.codes

License:MIT License


Languages

Language:TypeScript 99.9%Language:JavaScript 0.1%