2.3.3 • Published 1 year ago

@lou.codes/cron v2.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Coverage License NPM Version Open Issues Size

ā²ļø Standard cron expression tools.

Usage

šŸ“¦ Node

Install @lou.codes/cron as a dependency:

pnpm add @lou.codes/cron
# or
npm install @lou.codes/cron
# or
yarn add @lou.codes/cron

Import it and use it:

import { parse, stringify } from "@lou.codes/cron";

const cron = parse("1-2,3,4 * 2 8,9 1");
/*
	{
		minutes: [{ from: 1, to: 2 }, 3, 4],
		hours: "*",
		dayOfMonth: 2,
		month: [8, 9],
		dayOfWeek: 1
	}
*/

stringify(cron); // "1-2,3,4 * 2 8,9 1"

// Also works with partials:
stringify({ hours: 13 }); // "* 13 * * *"

// Only parses with valid dates:
parse("* * 31 2 *"); // undefined because 2/31 is invalid

šŸ¦• Deno

Import @lou.codes/cron using the npm: prefix, and use it directly:

import { parse, stringify } from "@lou.codes/cron";

const cron = parse("1-2,3,4 * 2 8,9 1");
/*
	{
		minutes: [{ from: 1, to: 2 }, 3, 4],
		hours: "*",
		dayOfMonth: 2,
		month: [8, 9],
		dayOfWeek: 1
	}
*/

stringify(cron); // "1-2,3,4 * 2 8,9 1"

// Also works with partials:
stringify({ hours: 13 }); // "* 13 * * *"

// Only parses with valid dates:
parse("* * 31 2 *"); // undefined because 2/31 is invalid

šŸŒŽ Browser

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

<script type="module">
	import { parse, stringify } from "https://esm.sh/@lou.codes/cron";

	const cron = parse("1-2,3,4 * 2 8,9 1");
	/*
	{
		minutes: [{ from: 1, to: 2 }, 3, 4],
		hours: "*",
		dayOfMonth: 2,
		month: [8, 9],
		dayOfWeek: 1
	}
*/

	stringify(cron); // "1-2,3,4 * 2 8,9 1"

	// Also works with partials:
	stringify({ hours: 13 }); // "* 13 * * *"

	// Only parses with valid dates:
	parse("* * 31 2 *"); // undefined because 2/31 is invalid
</script>

Useful links

To do

Soon a human readable parser will be added, so we can do stuff like:

readable("* * * * *"); // "Every minute"
readable("5 * * * *"); // "Minute 5 of every hour"
readable("* 5 * * *"); // "Every minute at 5 AM"
readable("* * 5 * *"); // "Every minute at the 5th day of every month"
readable("* * * 5 *"); // "Every minute in May"
readable("* * * * 5"); // "Every minute on Friday"
readable("5 5 5 5 5"); // "At 5:05 AM, the 5th day of May on Friday"
2.3.0

1 year ago

2.2.1

1 year ago

2.0.3

1 year ago

2.2.0

1 year ago

2.0.2

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.3

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.2

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago