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>parseList.ts
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>>;