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>stringifyField.ts
import type { Field } from "./Field.ts"; import type { FieldString } from "./FieldString.ts"; import { isAllToken } from "./isAllToken.ts"; import { stringifyList } from "./stringifyList.ts"; import { stringifyRange } from "./stringifyRange.ts"; /** * Takes a cron object and returns a string expression. * * @example * ```typescript * stringifyField("*"); // "*" * stringifyField(13); // "13" * stringifyField([10, 11, 13]); // "10,11,13" * stringifyField({ from: 1, to: 10 }); // "1-10" * ``` * @see {@linkcode isAllToken} * @see {@linkcode stringifyList} * @see {@linkcode stringifyRange} * * @param field Cron object field. * @returns Cron string field. */ export const stringifyField = (field: Field<number>): FieldString => isAllToken(field) ? field : ( (stringifyList(field) ?? stringifyRange(field) ?? `${field as number}`) as FieldString );