Skip to main content

@coven/cron@0.3.3
Built and signed on GitHub Actions

⏳ Fantastic cron parser and constructor.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 months ago (0.3.3)
Package root>parseField.ts
import { parseDecimal } from "jsr:@coven/parsers@^0.3.3"; import type { Maybe } from "jsr:@coven/types@^0.3.3"; import type { AllToken } from "./AllToken.ts"; import { isAllToken } from "./isAllToken.ts"; import type { ListField } from "./ListField.ts"; import { parseList } from "./parseList.ts"; import { parseRange } from "./parseRange.ts"; import type { RangeField } from "./RangeField.ts"; /** * Parses a cron field. * * @example * ```typescript * parseField("*"); // "*" * parseField("13"); // 13 * parseField("10,11,13"); // [10, 11, 13] * parseField("1-10"); // { from: 1, to: 10 } * ``` * @see {@linkcode isAllToken} * @see {@linkcode parseList} * @see {@linkcode parseRange} * * @param field Cron field value (should be validated before this). * @returns Parsed field. */ export const parseField = ( field: string, ): AllToken | Maybe<number> | RangeField<number> | ListField<number> => isAllToken(field) ? field : ( parseList(field) ?? parseRange(field) ?? parseDecimal(field) );