Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
⏳ Fantastic cron parser and constructor.
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
JSR Score
100%
Published
2 months ago (0.3.3)
import { iterableToArray, unique } from "jsr:@coven/iterables@^0.3.3"; import type { Maybe } from "jsr:@coven/types@^0.3.3"; import type { ListField } from "./ListField.ts"; import { isListString } from "./isListString.ts"; import { parseListMap } from "./parseListMap.ts"; import { LIST_EXPRESSION_SEPARATOR_TOKEN } from "./tokens.ts"; /** * Parses a cron list into an array. * * @example * ```typescript * parseList("10,11,13"); // [10, 11, 13] * ``` * @see {@linkcode isListString} * * @param value String that might be a list. * @returns Parsed list of `undefined` if it isn't a list string. */ export const parseList = <Predicated extends number>( value: string, ): Maybe<ListField<Predicated>> => (isListString(value) ? iterableToArray( unique(parseListMap(value.split(LIST_EXPRESSION_SEPARATOR_TOKEN))), ) : undefined) as Maybe<ListField<Predicated>>;