@lou.codes/cron
v1.0.28
Published
⏲️ Cron Quartz and Cron UNIX expression parser
Downloads
560
Maintainers
Readme
⏲️ Cron Quartz and Cron UNIX expression parser.
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 { parseStringQuartz, parseCronQuartz } from "@lou.codes/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 @lou.codes/cron
using the npm:
prefix, and use it directly:
import { parseStringQuartz, parseCronQuartz } from "npm:@lou.codes/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 @lou.codes/cron
using esm.sh, and use it directly:
<script type="module">
import {
parseStringQuartz,
parseCronQuartz,
} from "https://esm.sh/@lou.codes/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
- 📝 Documentation: TypeDoc generated documentation.
- ⏳ Changelog: List of changes between versions.
- ✅ Tests Coverage: Coveralls page with tests coverage.
To do
A big change is coming with stricter types and a better DX. Stay tuned.