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>stringifyRange.ts
import type { Maybe } from "jsr:@coven/types@^0.3.3"; import type { Field } from "./Field.ts"; import type { RangeString } from "./RangeString.ts"; import { isRangeField } from "./isRangeField.ts"; import { FROM_NAME, TO_NAME } from "./rangeFieldNames.ts"; import { RANGE_EXPRESSION_SEPARATOR_TOKEN } from "./tokens.ts"; /** * Turn a cron range into a string. * * @example * ```typescript * stringifyRange({ from: 1, to: 13 }); // "1-13" * ``` * @see {@linkcode isRangeField} * * @param field Cron field to turn into a string. * @returns String ranged of `undefined` if it isn't a range object. */ export const stringifyRange = <Predicated extends number>( field: Readonly<Field<Predicated>>, ): Maybe<RangeString> => (isRangeField(field) ? `${field[FROM_NAME]}${RANGE_EXPRESSION_SEPARATOR_TOKEN}${ field[TO_NAME] }` : undefined) as Maybe<RangeString>;