Skip to content

Cron Reference

Coverage License NPM Version Open Issues Size

⏲️ Cron Quartz and Cron UNIX expression parser.

Usage

📦 Node

Install @lou.codes/cron as a dependency:

Terminal window
pnpm add @lou.codes/cron
# or
npm install @lou.codes/cron
# or
yarn add @lou.codes/cron

Import it and use it:

import { parseStringQuartz, parseCronQuartz } from "@lou.codes/cron";
const cron = parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10");
/*
{
seconds: { every: 3, start: { from: 1, to: 2 } },
minutes: [{ from: 1, to: 2 }, 3, 4],
hours: "*",
dayOfMonth: { nearest: 2 },
month: ["SEP", "OCT"],
dayOfWeek: { last: 1 },
year: { every: 10, start: "*" }
}
*/
parseCronQuartz(cron); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10"

🦕 Deno

Import @lou.codes/cron using the npm: prefix, and use it directly:

import { parseStringQuartz, parseCronQuartz } from "npm:@lou.codes/cron";
const cron = parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10");
/*
{
seconds: { every: 3, start: { from: 1, to: 2 } },
minutes: [{ from: 1, to: 2 }, 3, 4],
hours: "*",
dayOfMonth: { nearest: 2 },
month: ["SEP", "OCT"],
dayOfWeek: { last: 1 },
year: { every: 10, start: "*" }
}
*/
parseCronQuartz(cron); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10"

🌎 Browser

Import @lou.codes/cron using esm.sh, and use it directly:

<script type="module">
import {
parseStringQuartz,
parseCronQuartz,
} from "https://esm.sh/@lou.codes/cron";
const cron = parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10");
/*
{
seconds: { every: 3, start: { from: 1, to: 2 } },
minutes: [{ from: 1, to: 2 }, 3, 4],
hours: "*",
dayOfMonth: { nearest: 2 },
month: ["SEP", "OCT"],
dayOfWeek: { last: 1 },
year: { every: 10, start: "*" }
}
*/
parseCronQuartz(cron); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L */10"
</script>

To do

A big change is coming with stricter types and a better DX. Stay tuned.

Common

splitExpression

splitExpression(source): string[]

Splits given string by spaces (even if multiple).

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

string[]

An array with all elements of the given expression.

Example

splitExpression(" 1 2 3 4 5 "); // ["1", "2", "3", "4", "5"]
splitExpression("1 2 3 4 5"); // ["1", "2", "3", "4", "5"]
splitExpression("12345"); // ["12345"]

View source


validateOr

validateOr(...validations): (value: unknown) => boolean

Run several validations in the same string, true if any is true.

Parameters

NameTypeDescription
...validationsreadonly (value: unknown) => boolean[]List of validations.

Returns

fn

Curried function with validations in context.

▸ (value): boolean

Parameters
NameType
valueunknown
Returns

boolean

Example

validateOr([])("1"); // false
validateOr([item => item === "1", item => parseInt(item as string, 10) === 1])(
"1",
); // true
validateOr([item => item === "1", item => parseInt(item as string, 10) === 2])(
"1",
); // true
validateOr([item => item === "2", item => parseInt(item as string, 10) === 2])(
"1",
); // false

View source

Other

CronDayOfMonth

Cron day of month.

View source


CronDayOfMonthValue

Ƭ CronDayOfMonthValue: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31

Cron day of the month value (1-31).

View source


CronDayOfWeek

Cron day of week.

View source


CronDayOfWeekValue

Cron day of week value (0-7 | SUN-SAT).

View source


CronDayOfWeekValueNumber

Ƭ CronDayOfWeekValueNumber: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7

Cron day of week number value (0-7).

View source


CronDayOfWeekValueString

Ƭ CronDayOfWeekValueString: "FRI" | "MON" | "SAT" | "SUN" | "THU" | "TUE" | "WED"

Cron day of week string value (SUN-SAT).

View source


CronEvery

Ƭ CronEvery: typeof CRON_EVERY

Cron every (*).

View source


CronHours

Ƭ CronHours: CronPart<CronHoursValue>

Cron hours.

View source


CronHoursValue

Ƭ CronHoursValue: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23

Cron hours value (0-23).

View source


CronLast

Ƭ CronLast: typeof CRON_LAST

Cron every (L).

View source


CronLastValue

Ƭ CronLastValue: Object

Cron last object. It gets turned into the string ${last}L.

Type declaration

NameType
lastCronDayOfWeekValueNumber

View source


CronList

Ƭ CronList<Value>: ReadonlyArray<CronListItem<Value>>

Cron list (value1,value2,valueN).

Type parameters

Name
Value

View source


CronListItem

Ƭ CronListItem<Value>: CronRange<Value> | CronSteps<Value> | Value

Cron list item.

Type parameters

Name
Value

View source


CronMinutes

Ƭ CronMinutes: CronPart<CronMinutesValue>

Cron minutes.

View source


CronMinutesValue

Ƭ CronMinutesValue: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59

Cron minutes value (0-59).

View source


CronMonth

Ƭ CronMonth: CronPart<CronMonthValue>

Cron month.

View source


CronMonthValue

Cron month value (1-12 and JAN-DEC).

View source


CronMonthValueNumber

Ƭ CronMonthValueNumber: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

Cron month number value (1-12).

View source


CronMonthValueString

Ƭ CronMonthValueString: "APR" | "AUG" | "DEC" | "FEB" | "JAN" | "JUL" | "JUN" | "MAR" | "MAY" | "NOV" | "OCT" | "SEP"

Cron month string value (JAN-DEC).

View source


CronNearest

Ƭ CronNearest: typeof CRON_NEAREST

Cron every (W).

View source


CronNearestDayOfMonth

Ƭ CronNearestDayOfMonth: Object

Nearest day of month object It gets turned into the string ${nearest}W.

Type declaration

NameType
nearestCronDayOfMonthValue

View source


CronPart

Ƭ CronPart<Value>: CronEvery | CronList<Value> | CronRange<Value> | CronSteps<Value> | Value

Cron part.

Type parameters

Name
Value

View source


CronPartExtended

Ƭ CronPartExtended<Value>: CronLast | CronPart<Value> | CronStartOrBlank

Cron part extended (used by CronDayOfWeek and DayOfMonth).

Type parameters

Name
Value

View source


CronQuartz

Ƭ CronQuartz: CronQuartzExtension & CronUnix

Cron object (Quartz).

View source


CronQuartzExtension

Ƭ CronQuartzExtension: Object

Cron expression parts coming with Quartz.

Type declaration

NameTypeDescription
secondsCronSecondsCron CronSeconds object.
yearCronYearCron CronYear object.

View source


CronRange

Ƭ CronRange<Value>: Object

Cron range (from-to).

Type parameters

Name
Value

Type declaration

NameType
fromValue
toValue

View source


CronSeconds

Ƭ CronSeconds: CronPart<CronSecondsValue>

Cron seconds.

View source


CronSecondsValue

Ƭ CronSecondsValue: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59

Cron seconds value (0-59).

View source


CronSpecificDayOfWeek

Ƭ CronSpecificDayOfWeek: Object

Cron specific day of week object. It gets turned into the string ${day}#${week}.

Type declaration

NameType
dayCronDayOfWeekValueNumber
weekCronWeekValue

View source


CronStartOrBlank

Ƭ CronStartOrBlank: typeof CRON_START_OR_BLANK

Cron start or blank value (?).

View source


CronSteps

Ƭ CronSteps<Value>: Object

Cron steps (start/every).

Type parameters

Name
Value

Type declaration

NameType
everynumber
startCronEvery | CronRange<Value> | Value

View source


CronUnix

Ƭ CronUnix: Object

Cron expression (UNIX).

Type declaration

NameTypeDescription
dayOfMonthCronDayOfMonthCron CronDayOfMonth object.
dayOfWeekCronDayOfWeekCron CronDayOfWeek object.
hoursCronHoursCron CronHours object.
minutesCronMinutesCron CronMinutes object.
monthCronMonthCron CronMonth object.

View source


CronValueParser

Ƭ CronValueParser<Value>: Unary<Value, Maybe<string>>

Parses a value into a string or undefined if invalid.

Type parameters

Name
Value

View source


CronWeekValue

Ƭ CronWeekValue: 1 | 2 | 3 | 4 | 5

Cron week value (1-5).

View source


CronYear

Ƭ CronYear: CronPart<CronYearValue>

Cron year.

View source


CronYearValue

Ƭ CronYearValue: 1970 | 1971 | 1972 | 1973 | 1974 | 1975 | 1976 | 1977 | 1978 | 1979 | 1980 | 1981 | 1982 | 1983 | 1984 | 1985 | 1986 | 1987 | 1988 | 1989 | 1990 | 1991 | 1992 | 1993 | 1994 | 1995 | 1996 | 1997 | 1998 | 1999 | 2000 | 2001 | 2002 | 2003 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 2010 | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | 2026 | 2027 | 2028 | 2029 | 2030 | 2031 | 2032 | 2033 | 2034 | 2035 | 2036 | 2037 | 2038 | 2039 | 2040 | 2041 | 2042 | 2043 | 2044 | 2045 | 2046 | 2047 | 2048 | 2049 | 2050 | 2051 | 2052 | 2053 | 2054 | 2055 | 2056 | 2057 | 2058 | 2059 | 2060 | 2061 | 2062 | 2063 | 2064 | 2065 | 2066 | 2067 | 2068 | 2069 | 2070 | 2071 | 2072 | 2073 | 2074 | 2075 | 2076 | 2077 | 2078 | 2079 | 2080 | 2081 | 2082 | 2083 | 2084 | 2085 | 2086 | 2087 | 2088 | 2089 | 2090 | 2091 | 2092 | 2093 | 2094 | 2095 | 2096 | 2097 | 2098 | 2099

Cron year value (1970-2099).

View source


LimitTuple

Ƭ LimitTuple: readonly [lowerLimit: number, upperLimit: number]

Lower and upper limit of a number value.

View source


StringValueParser

Ƭ StringValueParser<Value>: Unary<string, Maybe<Value>>

Parses a string into a value of given type or undefined if invalid

Type parameters

Name
Value

View source


CRON_EVERY

Const CRON_EVERY: "*"

View source


CRON_LAST

Const CRON_LAST: "L"

View source


CRON_LIST_SEPARATOR

Const CRON_LIST_SEPARATOR: ","

View source


CRON_NEAREST

Const CRON_NEAREST: "W"

View source


CRON_RANGE_SEPARATOR

Const CRON_RANGE_SEPARATOR: "-"

View source


CRON_SPECIFIC_SEPARATOR

Const CRON_SPECIFIC_SEPARATOR: "#"

View source


CRON_START_OR_BLANK

Const CRON_START_OR_BLANK: "?"

View source


CRON_STEPS_SEPARATOR

Const CRON_STEPS_SEPARATOR: "/"

View source


QUARTZ_DAY_OF_MONTH_POSITION

Const QUARTZ_DAY_OF_MONTH_POSITION: 3

View source


QUARTZ_DAY_OF_WEEK_POSITION

Const QUARTZ_DAY_OF_WEEK_POSITION: 5

View source


QUARTZ_HOURS_POSITION

Const QUARTZ_HOURS_POSITION: 2

View source


QUARTZ_MINUTES_POSITION

Const QUARTZ_MINUTES_POSITION: 1

View source


QUARTZ_MONTH_POSITION

Const QUARTZ_MONTH_POSITION: 4

View source


QUARTZ_SECONDS_POSITION

Const QUARTZ_SECONDS_POSITION: 0

View source


QUARTZ_YEAR_POSITION

Const QUARTZ_YEAR_POSITION: 6

View source


UNIX_DAY_OF_MONTH_POSITION

Const UNIX_DAY_OF_MONTH_POSITION: 2

View source


UNIX_DAY_OF_WEEK_POSITION

Const UNIX_DAY_OF_WEEK_POSITION: 4

View source


UNIX_HOURS_POSITION

Const UNIX_HOURS_POSITION: 1

View source


UNIX_MINUTES_POSITION

Const UNIX_MINUTES_POSITION: 0

View source


UNIX_MONTH_POSITION

Const UNIX_MONTH_POSITION: 3

View source


isCronSecondsValue

isCronSecondsValue(value): value is CronSecondsValue

Check if given is CronSecondsValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronSecondsValue

Returns true if is CronSecondsValue, false otherwise.

Example

isCronSecondsValue(30); // true
isCronSecondsValue(80); // false

View source

Parsers

parseCronDayOfMonth

parseCronDayOfMonth(source): Maybe<string>

Parses CronDayOfMonth into a string.

Parameters

NameTypeDescription
sourceCronDayOfMonthCronDayOfMonth to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronDayOfMonth(10); // "10"
parseCronDayOfMonth("*"); // "*"
parseCronDayOfMonth("?"); // "?"
parseCronDayOfMonth({ every: 10, start: 2 }); // "2/10"
parseCronDayOfMonth({ every: 10, start: "L" }); // "L/10"
parseCronDayOfMonth([1, 2, 3, 4]); // "1,2,3,4"
parseCronDayOfMonth({ from: 5, to: 10 }); // "5-10"
parseCronDayOfMonth([1, 2, 3, 4, { from: 5, to: 10 }]); // "1,2,3,4,5-10"
parseCronDayOfMonth("L"); // "L"
parseCronDayOfMonth({ nearest: 1 }); // "1W"
parseCronDayOfMonth({ every: 99, start: "*" }); // undefined

View source


parseCronDayOfMonthValue

parseCronDayOfMonthValue(...input): Maybe<string>

Parses CronDayOfMonthValue into a string.

Parameters

NameType
...inputSingle<CronDayOfMonthValue>

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronDayOfMonthValue(1); // "1"
parseCronDayOfMonthValue(31); // "31"
parseCronDayOfMonthValue(99); // undefined

View source


parseCronDayOfWeek

parseCronDayOfWeek(source): Maybe<string>

Parses CronDayOfWeek into a string.

Parameters

NameTypeDescription
sourceCronDayOfWeekCronDayOfWeek to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronDayOfWeek(6); // "6"
parseCronDayOfWeek("*"); // "*"
parseCronDayOfWeek("?"); // "?"
parseCronDayOfWeek({ every: 6, start: 2 }); // "2/6"
parseCronDayOfWeek({ every: 6, start: "L" }); // "L/6"
parseCronDayOfWeek([1, 2, 3, 4]); // "1,2,3,4"
parseCronDayOfWeek({ from: 1, to: 5 }); // "1-5"
parseCronDayOfWeek({ from: "MON", to: "SAT" }); // "MON-SAT"
parseCronDayOfWeek([1, 2, 3, { from: 5, to: 7 }]); // "1,2,3,5-7"
parseCronDayOfWeek("L"); // "L"
parseCronDayOfWeek({ last: 2 }); // "2L"
parseCronDayOfWeek({ day: 1, week: 5 }); // "1#5"

View source


parseCronDayOfWeekValue

parseCronDayOfWeekValue(...input): Maybe<string>

Parses CronDayOfWeekValue into a string.

Parameters

NameType
...inputSingle<CronDayOfWeekValue>

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronDayOfWeekValue(1); // "1"
parseCronDayOfWeekValue(7); // "7"
parseCronDayOfWeekValue(99); // undefined

View source


parseCronEvery

parseCronEvery(source): undefined | "*"

Parses a CronEvery into a string.

Parameters

NameTypeDescription
sourcestringCronEvery to be parsed.

Returns

undefined | "*"

A string or undefined if invalid.

Example

parseCronEvery("*"); // "*"
parseCronEvery("💩"); // undefined

View source


parseCronHours

parseCronHours(source): Maybe<string>

Parses CronHours into a string.

Parameters

NameTypeDescription
source"*" | CronHoursValue | CronList<CronHoursValue> | CronRange<CronHoursValue> | CronSteps<CronHoursValue>CronHours to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronHours(10); // "10"
parseCronHours("*"); // "*"
parseCronHours({ every: 10, start: 2 }); // "2/10"
parseCronHours([1, 2, 3, 4]); // "1,2,3,4"
parseCronHours({ from: 5, to: 10 }); // "5-10"
parseCronHours([1, 2, 3, 4, { from: 5, to: 10 }]); // "1,2,3,4,5-10"

View source


parseCronHoursValue

parseCronHoursValue(...input): Maybe<string>

Parses CronHoursValue into a string.

Parameters

NameType
...inputSingle<CronHoursValue>

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronHoursValue(10); // "10"
parseCronHoursValue(23); // "23"
parseCronHoursValue(99); // undefined

View source


parseCronLast

parseCronLast(source): undefined | "L"

Parses CronLast into a string.

Parameters

NameTypeDescription
sourcestringCronLast to be parsed.

Returns

undefined | "L"

A string or undefined if invalid.

Example

parseCronLast("L"); // "L"
parseCronLast("💩"); // undefined

View source


parseCronLastValue

parseCronLastValue(source): undefined | string

Parses CronLastValue into a string.

Parameters

NameTypeDescription
sourceCronLastValueCronLastValue to be parsed.

Returns

undefined | string

A string or undefined if invalid.

Example

parseCronLastValue({ last: 1 }); // "1L"
parseCronLastValue({ last: 99 }); // undefined

View source


parseCronList

parseCronList(limit): <Value>(parser: CronValueParser<Value>) => (source: CronList<Value>) => undefined | string

Parses CronList into a string.

Parameters

NameTypeDescription
limitLimitTupleLimitTuple to be used when parsing CronSteps.

Returns

fn

Curried function with limit on context.

▸ <Value>(parser): (source: CronList<Value>) => undefined | string

Type parameters
Name
Value
Parameters
NameType
parserCronValueParser<Value>
Returns

fn

▸ (source): undefined | string

Parameters
NameType
sourceCronList<Value>
Returns

undefined | string

Example

const parseCronSecondsList = parseCronList([0, 59])(parseCronSecondsValue);
parseCronSecondsList([13, 10]); // "13,10",
parseCronSecondsList([{ from: 13, to: 10 }, 10]); // "13-10,10",
parseCronSecondsList([{ every: 10, start: 13 }, 10]); // "13/10,10",
parseCronSecondsList([{ every: 10, start: { from: 13, to: 10 } }, 10]); // "13-10/10,10"
parseCronSecondsList([{ every: 10, start: "L" }, 10]); // "L/10,10"
parseCronSecondsList([]); // undefined

View source


parseCronMinutes

parseCronMinutes<Source>(source): Maybe<string>

Parses CronMinutes into a string.

Type parameters

NameType
Sourceextends number

Parameters

NameTypeDescription
source"*" | Source | CronList<Source> | CronRange<Source> | CronSteps<Source>CronMinutes to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronMinutes(10); // "10"
parseCronMinutes("*"); // "*"
parseCronMinutes({ every: 10, start: 2 }); // "2/10"
parseCronMinutes([1, 2, 3, 4]); // "1,2,3,4"
parseCronMinutes({ from: 5, to: 10 }); // "5-10"
parseCronMinutes([1, 2, 3, 4, { from: 5, to: 10 }]); // "1,2,3,4,5-10"

View source


parseCronMinutesValue

parseCronMinutesValue<Source>(source): Source extends CronMinutesValue ? `${Source}` : Maybe<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31" | "32" | "33" | "34" | "35" | "36" | "37" | "38" | "39" | "40" | "41" | "42" | "43" | "44" | "45" | "46" | "47" | "48" | "49" | "50" | "51" | "52" | "53" | "54" | "55" | "56" | "57" | "58" | "59">

Parses CronMinutesValue into a string.

Type parameters

NameType
Sourceextends number

Parameters

NameTypeDescription
sourceSourceCronMinutesValue to be parsed.

Returns

Source extends CronMinutesValue ? `${Source}` : Maybe<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31" | "32" | "33" | "34" | "35" | "36" | "37" | "38" | "39" | "40" | "41" | "42" | "43" | "44" | "45" | "46" | "47" | "48" | "49" | "50" | "51" | "52" | "53" | "54" | "55" | "56" | "57" | "58" | "59">

A string or undefined if invalid.

Example

parseCronMinutesValue(0); // "0"
parseCronMinutesValue(59); // "59"

View source


parseCronMonth

parseCronMonth(source): Maybe<string>

Parses CronMonth into a string.

Parameters

NameTypeDescription
source"*" | CronMonthValue | CronList<CronMonthValue> | CronRange<CronMonthValue> | CronSteps<CronMonthValue>CronMonth to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronMonth(10); // "10"
parseCronMonth("*"); // "*"
parseCronMonth({ every: 6, start: 2 }); // "2/6"
parseCronMonth([1, 2, 3, 4]); // "1,2,3,4"
parseCronMonth({ from: 1, to: 5 }); // "1-5"
parseCronMonth({ from: "JAN", to: "OCT" }); // "JAN-OCT"
parseCronMonth([1, 2, 3, { from: 5, to: 7 }]); // "1,2,3,5-7"

View source


parseCronMonthValue

parseCronMonthValue(...input): Maybe<string>

Parses CronMonthValue into a string.

Parameters

NameType
...inputSingle<CronMonthValue>

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronMonthValue(1); // "1"
parseCronMonthValue(12); // "12"
parseCronMonthValue(99); // undefined

View source


parseCronNearestDayOfMonth

parseCronNearestDayOfMonth(source): undefined | string

Parses CronNearestDayOfMonth into a string.

Parameters

NameTypeDescription
sourceCronNearestDayOfMonthCronNearestDayOfMonth to be parsed.

Returns

undefined | string

A string or undefined if invalid.

Example

parseCronNearestDayOfMonth({ nearest: 2 }); // "2W"
parseCronNearestDayOfMonth({ nearest: 99 }); // undefined

View source


parseCronPart

parseCronPart(limit): <Value>(parser: CronValueParser<Value>) => (source: "*" | Value | CronList<Value> | CronRange<Value> | CronSteps<Value>) => Maybe<string>

Parses CronPart into a string.

Parameters

NameTypeDescription
limitLimitTupleLimitTuple to be used when parsing CronSteps.

Returns

fn

Curried function with limit on context.

▸ <Value>(parser): (source: "*" | Value | CronList<Value> | CronRange<Value> | CronSteps<Value>) => Maybe<string>

Type parameters
Name
Value
Parameters
NameType
parserCronValueParser<Value>
Returns

fn

▸ (source): Maybe<string>

Parameters
NameType
source"*" | Value | CronList<Value> | CronRange<Value> | CronSteps<Value>
Returns

Maybe<string>

Example

const parseCronPartSeconds = parseCronPart([0, 59])(parseCronSecondsValue);
parseCronPartSeconds("*"); // "*"
parseCronPartSeconds([13, 10]); // "13,10"
parseCronPartSeconds([{ from: 13, to: 10 }, 10]); // "13-10,10"
parseCronPartSeconds([{ every: 10, start: 13 }, 10]); // "13/10,10"
parseCronPartSeconds([{ every: 99, start: 13 }, 10]); // undefined
parseCronPartSeconds([
{
every: 10,
start: { from: 13, to: 10 },
},
10,
]); // "13-10/10,10"
parseCronPartSeconds([{ every: 10, start: "?" }, 10]); // "?/10,10"
parseCronPartSeconds({ every: 10, start: 13 }); // "13/10"
parseCronPartSeconds({
every: 10,
start: { from: 13, to: 10 },
}); // "13-10/10"
parseCronPartSeconds({ every: 10, start: "?" }); // "?/10"
parseCronPartSeconds({
from: 13,
to: 10,
}); // "13-10"

View source


parseCronQuartz

parseCronQuartz(cronQuartz): undefined | string

Parses CronQuartz into a string.

Parameters

NameType
cronQuartzCronQuartz

Returns

undefined | string

A string or undefined if invalid.

Example

parseCronQuartz({
dayOfMonth: "*",
dayOfWeek: "*",
hours: "*",
minutes: "*",
month: "*",
seconds: "*",
year: "*",
}); // wanted: "* * * * * * *"
parseCronQuartz({
dayOfMonth: [1, 2],
dayOfWeek: [1, 2],
hours: [1, 2],
minutes: [1, 2],
month: [1, 2],
seconds: [1, 2],
year: [1989, 2020],
}); // "1,2 1,2 1,2 1,2 1,2 1,2 1989,2020"
parseCronQuartz({
dayOfMonth: { from: 1, to: 2 },
dayOfWeek: { from: 1, to: 2 },
hours: { from: 1, to: 2 },
minutes: { from: 1, to: 2 },
month: { from: 1, to: 2 },
seconds: { from: 1, to: 2 },
year: { from: 1989, to: 2020 },
}); // "1-2 1-2 1-2 1-2 1-2 1-2 1989-2020"
parseCronQuartz({
dayOfMonth: { every: 2, start: 1 },
dayOfWeek: { every: 2, start: 1 },
hours: { every: 2, start: 1 },
minutes: { every: 2, start: 1 },
month: { every: 2, start: 1 },
seconds: { every: 2, start: 1 },
year: { every: 10, start: 1989 },
}); // "1/2 1/2 1/2 1/2 1/2 1/2 1989/10"
parseCronQuartz({
dayOfMonth: { nearest: 2 },
dayOfWeek: { last: 1 },
hours: "*",
minutes: [{ from: 1, to: 2 }, 3, 4],
month: ["SEP", "OCT"],
seconds: { every: 3, start: { from: 1, to: 2 } },
year: { every: 10, start: "?" },
}); // "1-2/3 1-2,3,4 * 2W SEP,OCT 1L ?/10",
parseCronQuartz({
dayOfMonth: undefined,
dayOfWeek: "*",
hours: "*",
minutes: "*",
month: "*",
seconds: "*",
year: "*",
}); // undefined,

View source


parseCronRange

parseCronRange<Value>(parser): (source: CronRange<Value>) => undefined | string

Parses CronRange into a string.

Type parameters

Name
Value

Parameters

NameTypeDescription
parserCronValueParser<Value>CronValueParser for CronRange.

Returns

fn

Curried function with parser in context.

▸ (source): undefined | string

Parameters
NameType
sourceCronRange<Value>
Returns

undefined | string

Example

parseCronRangeSeconds({ from: 13, to: 10 }); // "13-10"
parseCronRangeSeconds({ from: 999, to: 999 }); // undefined

View source


parseCronSeconds

parseCronSeconds(source): Maybe<string>

Parses CronSeconds into a string.

Parameters

NameTypeDescription
source"*" | CronSecondsValue | CronList<CronSecondsValue> | CronRange<CronSecondsValue> | CronSteps<CronSecondsValue>CronSeconds to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronSeconds(10); // "10",
parseCronSeconds("*"); // "*",
parseCronSeconds({ every: 10, start: 2 }); // "2/10",
parseCronSeconds([1, 2, 3, 4]); // "1,2,3,4",
parseCronSeconds({ from: 5, to: 10 }); // "5-10",
parseCronSeconds([1, 2, 3, 4, { from: 5, to: 10 }]); // "1,2,3,4,5-10",

View source


parseCronSecondsValue

parseCronSecondsValue(...input): Maybe<string>

Parses CronSecondsValue into a string.

Parameters

NameType
...inputSingle<CronSecondsValue>

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronSecondsValue(10); // "10"
parseCronSecondsValue(59); // "59"
parseCronSecondsValue(99); // undefined

View source


parseCronSpecificDayOfWeek

parseCronSpecificDayOfWeek(source): undefined | string

Parses CronSpecificDayOfWeek into a string.

Parameters

NameTypeDescription
sourcestring | CronSpecificDayOfWeekCronSpecificDayOfWeek to be parsed.

Returns

undefined | string

A string or undefined if invalid.

Example

parseCronSpecificDayOfWeek({ day: 1, week: 5 }); // "1#5"
parseCronSpecificDayOfWeek({ day: 99, week: 99 }); // undefined

View source


parseCronStartOrBlank

parseCronStartOrBlank(source): undefined | "?"

Parses CronStartOrBlank into a string.

Parameters

NameTypeDescription
sourcestringCronStartOrBlank to be parsed.

Returns

undefined | "?"

A string or undefined if invalid.

Example

parseCronStartOrBlank("?"); // "?"
parseCronStartOrBlank("💩"); // undefined

View source


parseCronSteps

parseCronSteps(limit): <Value>(parser: CronValueParser<Value>) => (source: CronSteps<Value>) => undefined | string

Parses CronSteps into a string.

Parameters

NameTypeDescription
limitLimitTupleLimitTuple to be used when parsing CronSteps.

Returns

fn

Curried function with limit on context.

▸ <Value>(parser): (source: CronSteps<Value>) => undefined | string

Type parameters
Name
Value
Parameters
NameType
parserCronValueParser<Value>
Returns

fn

▸ (source): undefined | string

Parameters
NameType
sourceCronSteps<Value>
Returns

undefined | string

Example

const parseCronStepsSeconds = parseCronSteps([0, 59])(parseCronSecondsValue);
parseCronStepsSeconds({ every: 10, start: 13 }); // "13/10"
parseCronStepsSeconds({ every: 99, start: 13 }); // undefined
parseCronStepsSeconds({
every: 10,
start: { from: 13, to: 10 },
}); // "13-10/10"
parseCronStepsSeconds({ every: 10, start: "?" }); // "?/10"

View source


parseCronUnix

parseCronUnix(cronUnix): undefined | string

Parses Cron (UNIX) into a string.

Parameters

NameType
cronUnixCronUnix

Returns

undefined | string

A string or undefined if invalid.

Example

parseCronUnix({
dayOfMonth: "*",
dayOfWeek: "*",
hours: "*",
minutes: "*",
month: "*",
}); // "* * * * *"
parseCronUnix({
dayOfMonth: [1, 2],
dayOfWeek: [1, 2],
hours: [1, 2],
minutes: [1, 2],
month: [1, 2],
}); // "1,2 1,2 1,2 1,2 1,2"
parseCronUnix({
dayOfMonth: { from: 1, to: 2 },
dayOfWeek: { from: 1, to: 2 },
hours: { from: 1, to: 2 },
minutes: { from: 1, to: 2 },
month: { from: 1, to: 2 },
}); // "1-2 1-2 1-2 1-2 1-2"
parseCronUnix({
dayOfMonth: { every: 2, start: 1 },
dayOfWeek: { every: 2, start: 1 },
hours: { every: 2, start: 1 },
minutes: { every: 2, start: 1 },
month: { every: 2, start: 1 },
}); // "1/2 1/2 1/2 1/2 1/2"
parseCronUnix({
dayOfMonth: { nearest: 2 },
dayOfWeek: { last: 1 },
hours: "*",
minutes: [{ from: 1, to: 2 }, 3, 4],
month: ["SEP", "OCT"],
}); // "1-2,3,4 * 2W SEP,OCT 1L"
parseCronUnix({
dayOfMonth: undefined,
dayOfWeek: "*",
hours: "*",
minutes: "*",
month: "*",
}); // undefined

View source


parseCronYear

parseCronYear(source): Maybe<string>

Parses CronYear into a string.

Parameters

NameTypeDescription
source"*" | CronYearValue | CronList<CronYearValue> | CronRange<CronYearValue> | CronSteps<CronYearValue>CronYear to be parsed.

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronYear(1989); // "1989"
parseCronYear("*"); // "*"
parseCronYear({ every: 10, start: 1989 }); // "1989/10"
parseCronYear({ every: 10, start: "?" }); // "?/10"
parseCronYear([1989, 1991, 2015, 2020]); // "1989,1991,2015,2020"
parseCronYear({ from: 1989, to: 2020 }); // "1989-2020"
parseCronYear([1989, 1989, 1991, 2015, 2020, { from: 1989, to: 2020 }]); // "1989,1991,2015,2020,1989-2020"

View source


parseCronYearValue

parseCronYearValue(...input): Maybe<string>

Parses CronYearValue into a string.

Parameters

NameType
...inputSingle<CronYearValue>

Returns

Maybe<string>

A string or undefined if invalid.

Example

parseCronYearValue(1989); // "1989"
parseCronYearValue(2022); // "2022"
parseCronYearValue(1969); // undefined
parseCronYearValue(3000); // undefined

View source


parseStringDayOfMonth

parseStringDayOfMonth(source): Maybe<CronDayOfMonth>

Parses a string into a CronDayOfMonth.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronDayOfMonth>

A CronDayOfMonth or undefined if invalid.

Example

parseStringDayOfMonth("10"); // 10,
parseStringDayOfMonth("*"); // "*",
parseStringDayOfMonth("?"); // "?",
parseStringDayOfMonth("2/10"); // { every: 10, start: 2 },
parseStringDayOfMonth("?/10"); // { every: 10, start: "?" },
parseStringDayOfMonth("1,2,3,4"); // [1, 2, 3, 4],
parseStringDayOfMonth("5-10"); // { from: 5, to: 10 },
parseStringDayOfMonth("1,2,3,4,5-10"); // [1, 2, 3, 4, { from: 5, to: 10 }],
parseStringDayOfMonth("L"); // "L",
parseStringDayOfMonth("1W"); // { nearest: 1 },
parseStringDayOfMonth("INVALID"); // undefined,
parseStringDayOfMonth("1,2,3,4,INVALID"); // undefined,

View source


parseStringDayOfMonthValue

parseStringDayOfMonthValue(...input): Maybe<CronDayOfMonthValue>

Parses a string into a CronDayOfMonthValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronDayOfMonthValue>

A CronDayOfMonthValue or undefined if invalid.

Example

parseStringDayOfMonthValue("13"); // 13
parseStringDayOfMonthValue("99"); // undefined

View source


parseStringDayOfWeek

parseStringDayOfWeek(source): Maybe<CronDayOfWeek>

Parses a string into a CronDayOfWeek.

Parameters

NameTypeDescription
sourcestringString to be parsed.

Returns

Maybe<CronDayOfWeek>

A CronDayOfWeek or undefined if invalid.

Example

parseStringDayOfWeek("6"); // 6
parseStringDayOfWeek("*"); // "*"
parseStringDayOfWeek("?"); // "?"
parseStringDayOfWeek("2/6"); // { every: 6, start: 2 }
parseStringDayOfWeek("?/6"); // { every: 6, start: "?" }
parseStringDayOfWeek("1,2,3,4"); // [1, 2, 3, 4]
parseStringDayOfWeek("1-5"); // { from: 1, to: 5 }
parseStringDayOfWeek("MON-SAT"); // { from: "MON", to: "SAT" }
parseStringDayOfWeek("mon-sat"); // { from: "MON", to: "SAT" }
parseStringDayOfWeek("1,2,3,5-7"); // [1, 2, 3, { from: 5, to: 7 }]
parseStringDayOfWeek("L"); // "L"
parseStringDayOfWeek("2L"); // { last: 2 }
parseStringDayOfWeek("1#5"); // { day: 1, week: 5 }
parseStringDayOfWeek("INVALID"); // undefined
parseStringDayOfWeek("1,2,3,4,INVALID"); // undefined

View source


parseStringDayOfWeekValue

parseStringDayOfWeekValue(...input): Maybe<CronDayOfWeekValue>

Parses a string into a CronDayOfWeekValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronDayOfWeekValue>

A CronDayOfWeekValue or undefined if invalid.

Example

parseStringDayOfWeekValue("5"); // 5
parseStringDayOfWeekValue("FRI"); // "FRI"
parseStringDayOfWeekValue("fri"); // "FRI"
parseStringDayOfWeekValue("8"); // undefined
parseStringDayOfWeekValue("IDK"); // undefined

View source


parseStringHours

parseStringHours(source): Maybe<CronPart<CronHoursValue>>

Parses a string into a CronHours.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronPart<CronHoursValue>>

A CronHours or undefined if invalid.

Example

parseStringHours("10"); // 10
parseStringHours("*"); // "*"
parseStringHours("2/10"); // { every: 10, start: 2 }
parseStringHours("?/10"); // { every: 10, start: "?" }
parseStringHours("1,2,3,4"); // [1, 2, 3, 4]
parseStringHours("5-10"); // { from: 5, to: 10 }
parseStringHours("1,2,3,4,5-10"); // [1, 2, 3, 4, { from: 5, to: 10 }]
parseStringHours("INVALID"); // undefined
parseStringHours("1,2,3,4,INVALID"); // undefined

View source


parseStringHoursValue

parseStringHoursValue(...input): Maybe<CronHoursValue>

Parses a string into a CronHoursValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronHoursValue>

A CronHoursValue or undefined if invalid.

Example

parseStringHoursValue("10"); // 10
parseStringHoursValue("25"); // undefined

View source


parseStringLastValue

parseStringLastValue(source): Maybe<CronLastValue>

Parses a string into a CronLastValue.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronLastValue>

A CronLastValue or undefined if invalid.

Example

parseStringLastValue("5L"); // { last: 5 }
parseStringLastValue("INVALID"); // undefined

View source


parseStringList

parseStringList(limit): <Value>(parser: StringValueParser<Value>) => (source: string) => undefined | CronList<Value>

Parses a string into a CronList.

Parameters

NameTypeDescription
limitLimitTupleLimitTuple to be used when parsing CronSteps.

Returns

fn

Curried function with limit in context.

▸ <Value>(parser): (source: string) => undefined | CronList<Value>

Type parameters
Name
Value
Parameters
NameType
parserStringValueParser<Value>
Returns

fn

▸ (source): undefined | CronList<Value>

Parameters
NameType
sourcestring
Returns

undefined | CronList<Value>

Example

parseStringListSeconds("13,10"); // [13, 10]
parseStringListSeconds("13-10,10"); // [{ from: 13, to: 10 }, 10]
parseStringListSeconds("13/10,10"); // [{ every: 10, start: 13 }, 10]
parseStringListSeconds("13-10/10,10"); // [{ every: 10, start: { from: 13, to: 10 } }, 10]
parseStringListSeconds("?/10,10"); // [{ every: 10, start: "?" }, 10]
parseStringListSeconds("13,INVALID"); // undefined
parseStringListSeconds("INVALID"); // undefined

View source


parseStringMinutes

parseStringMinutes(source): Maybe<CronPart<CronMinutesValue>>

Parses a string into a CronMinutes.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronPart<CronMinutesValue>>

A CronMinutes or undefined if invalid.

Example

parseStringMinutes("10"); // 10
parseStringMinutes("*"); // "*"
parseStringMinutes("2/10"); // { every: 10, start: 2 }
parseStringMinutes("?/10"); // { every: 10, start: "?" }
parseStringMinutes("1,2,3,4"); // [1, 2, 3, 4]
parseStringMinutes("5-10"); // { from: 5, to: 10 }
parseStringMinutes("1,2,3,4,5-10"); // [1, 2, 3, 4, { from: 5, to: 10 }]
parseStringMinutes("INVALID"); // undefined
parseStringMinutes("1,2,3,4,INVALID"); // undefined

View source


parseStringMinutesValue

parseStringMinutesValue(...input): Maybe<CronMinutesValue>

Parses a string into a CronMinutesValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronMinutesValue>

A CronMinutesValue or undefined if invalid.

Example

parseStringMinutesValue("10"); // 10
parseStringMinutesValue("61"); // undefined

View source


parseStringMonth

parseStringMonth(source): Maybe<CronPart<CronMonthValue>>

Parses a string into a CronMonth.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronPart<CronMonthValue>>

A CronMonth or undefined if invalid.

Example

parseStringMonth("10"); // 10
parseStringMonth("*"); // "*"
parseStringMonth("2/6"); // { every: 6, start: 2 }
parseStringMonth("?/6"); // { every: 6, start: "?" }
parseStringMonth("1,2,3,4"); // [1, 2, 3, 4]
parseStringMonth("1-5"); // { from: 1, to: 5 }
parseStringMonth("JAN-OCT"); // { from: "JAN", to: "OCT" }
parseStringMonth("jan-oct"); // { from: "JAN", to: "OCT" }
parseStringMonth("1,2,3,5-7"); // [1, 2, 3, { from: 5, to: 7 }]
parseStringMonth("INVALID"); // undefined
parseStringMonth("1,2,3,4,INVALID"); // undefined

View source


parseStringMonthValue

parseStringMonthValue(...input): Maybe<CronMonthValue>

Parses a string into a CronMonthValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronMonthValue>

A CronMonthValue or undefined if invalid.

Example

parseStringMonthValue("10"); // 10
parseStringMonthValue("OCT"); // "OCT"
parseStringMonthValue("oct"); // "OCT"
parseStringMonthValue("24"); // undefined
parseStringMonthValue("IDK"); // undefined

View source


parseStringNearestDayOfMonth

parseStringNearestDayOfMonth(source): undefined | CronNearestDayOfMonth

Parses a string into a CronNearestDayOfMonth.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

undefined | CronNearestDayOfMonth

A CronNearestDayOfMonth or undefined if invalid.

Example

parseStringNearestDayOfMonth("2W"); // { nearest: 2 }
parseStringNearestDayOfMonth("INVALID"); // undefined

View source


parseStringPart

parseStringPart(limit): <Value>(parser: StringValueParser<Value>) => (source: string) => Maybe<CronPart<Value>>

Parses a string into a CronPart.

Parameters

NameTypeDescription
limitLimitTupleLimitTuple to be used when parsing CronSteps.

Returns

fn

Curried function with limit in context.

▸ <Value>(parser): (source: string) => Maybe<CronPart<Value>>

Type parameters
Name
Value
Parameters
NameType
parserStringValueParser<Value>
Returns

fn

▸ (source): Maybe<CronPart<Value>>

Parameters
NameType
sourcestring
Returns

Maybe<CronPart<Value>>

Example

const parseStringPartSeconds = parseStringPart([0, 59])(
parseStringSecondsValue,
);
parseStringPartSeconds("*"); // "*"
parseStringPartSeconds("13,10"); // [13, 10]
parseStringPartSeconds("13-10,10"); // [{ from: 13, to: 10 }, 10]
parseStringPartSeconds("13/10,10"); // [{ every: 10, start: 13 }, 10]
parseStringPartSeconds("?/10,10"); // [{ every: 10, start: "?" }, 10]
parseStringPartSeconds("13/10"); // { every: 10, start: 13 }
parseStringPartSeconds("?/10"); // { every: 10, start: "?" }
parseStringPartSeconds("13-10"); // { from: 13, to: 10 }

View source


parseStringQuartz

parseStringQuartz(source): Maybe<CronQuartz>

Parses a string into a CronQuartz.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronQuartz>

A Cron or undefined if invalid.

Example

parseStringQuartz("* * * * * * *");
// {
// dayOfMonth: "*",
// dayOfWeek: "*",
// hours: "*",
// minutes: "*",
// month: "*",
// seconds: "*",
// year: "*",
// }
parseStringQuartz("* * * * *");
// {
// dayOfMonth: "*",
// dayOfWeek: "*",
// hours: "*",
// minutes: "*",
// month: "*",
// seconds: "*",
// year: "*",
// }
parseStringQuartz("1,2 1,2 1,2 1,2 1,2 1,2 1989,2020");
// {
// dayOfMonth: [1, 2],
// dayOfWeek: [1, 2],
// hours: [1, 2],
// minutes: [1, 2],
// month: [1, 2],
// seconds: [1, 2],
// year: [1989, 2020],
// }
parseStringQuartz("1-2 1-2 1-2 1-2 1-2 1-2 1989-2020");
// {
// dayOfMonth: { from: 1, to: 2 },
// dayOfWeek: { from: 1, to: 2 },
// hours: { from: 1, to: 2 },
// minutes: { from: 1, to: 2 },
// month: { from: 1, to: 2 },
// seconds: { from: 1, to: 2 },
// year: { from: 1989, to: 2020 },
// }
parseStringQuartz("1/2 1/2 1/2 1/2 1/2 1/2 1989/10");
// {
// dayOfMonth: { every: 2, start: 1 },
// dayOfWeek: { every: 2, start: 1 },
// hours: { every: 2, start: 1 },
// minutes: { every: 2, start: 1 },
// month: { every: 2, start: 1 },
// seconds: { every: 2, start: 1 },
// year: { every: 10, start: 1989 },
// }
parseStringQuartz("1-2/3 1-2,3,4 * 2W SEP,OCT 1L ?/10");
// {
// dayOfMonth: { nearest: 2 },
// dayOfWeek: { last: 1 },
// hours: "*",
// minutes: [{ from: 1, to: 2 }, 3, 4],
// month: ["SEP", "OCT"],
// seconds: { every: 3, start: { from: 1, to: 2 } },
// year: { every: 10, start: "?" },
// }
parseStringQuartz("INVALID"); // undefined

View source


parseStringQuartzExpression

parseStringQuartzExpression(source): undefined | readonly [string, string, string, string, string, string, string]

Parses given string expression.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

undefined | readonly [string, string, string, string, string, string, string]

An array of 7 elements or undefined if invalid.

Example

parseStringQuartzExpression("1 1 1 1 1"); // ["*", "1", "1", "1", "1", "1", "*"]
parseStringQuartzExpression("1 1 1 1 1 1989"); // ["*", "1", "1", "1", "1", "1", "1989"]
parseStringQuartzExpression("1 1 1 1 1 1"); // ["1", "1", "1", "1", "1", "1", "*"]
parseStringQuartzExpression("1 1 1 1 1 1 1"); // ["1", "1", "1", "1", "1", "1", "1"]
parseStringQuartzExpression(" 1 1 1 1 1 1 1 "); // ["1", "1", "1", "1", "1", "1", "1"]
parseStringQuartzExpression("1 1 1 1 1 1 1 1"); // undefined
parseStringQuartzExpression("1 1 1 1"); // undefined

View source


parseStringRange

parseStringRange<Value>(parser): (source: string) => Maybe<CronRange<Value>>

Parses a string into a CronRange.

Type parameters

Name
Value

Parameters

NameTypeDescription
parserStringValueParser<Value>StringValueParser for CronRange.

Returns

fn

Curried function with parser in context.

▸ (source): Maybe<CronRange<Value>>

Parameters
NameType
sourcestring
Returns

Maybe<CronRange<Value>>

Example

const parseStringRangeSeconds = parseStringRange(parseStringSecondsValue);
parseStringRangeSeconds("13-10"); // { from: 13, to: 10 }
parseStringRangeSeconds("INVALID"); // undefined

View source


parseStringSeconds

parseStringSeconds(source): Maybe<CronPart<CronSecondsValue>>

Parses a string into a CronSeconds.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronPart<CronSecondsValue>>

A CronSeconds or undefined if invalid.

Example

parseStringSeconds("10"); // 10
parseStringSeconds("*"); // "*"
parseStringSeconds("2/10"); // { every: 10, start: 2 }
parseStringSeconds("?/10"); // { every: 10, start: "?" }
parseStringSeconds("1,2,3,4"); // [1, 2, 3, 4]
parseStringSeconds("5-10"); // { from: 5, to: 10 }
parseStringSeconds("1,2,3,4,5-10"); // [1, 2, 3, 4, { from: 5, to: 10 }]
parseStringSeconds("INVALID"); // undefined
parseStringSeconds("1,2,3,4,INVALID"); // undefined

View source


parseStringSecondsValue

parseStringSecondsValue(...input): Maybe<CronSecondsValue>

Parses a string into a CronSecondsValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronSecondsValue>

A CronSecondsValue or undefined if invalid.

Example

parseStringSecondsValue("10"); // 10
parseStringSecondsValue("61"); // undefined

View source


parseStringSpecificDayOfWeek

parseStringSpecificDayOfWeek(source): Maybe<CronSpecificDayOfWeek>

Parses a string into a CronSpecificDayOfWeek.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronSpecificDayOfWeek>

A CronSpecificDayOfWeek or undefined if invalid.

Example

parseStringSpecificDayOfWeek("1#5"); // { day: 1, week: 5 }
parseStringSpecificDayOfWeek("INVALID"); // undefined

View source


parseStringSteps

parseStringSteps(limit): <Value>(parser: StringValueParser<Value>) => (source: string) => Maybe<CronSteps<Value>>

Parses a string into a CronSteps.

Parameters

NameTypeDescription
limitLimitTupleLimitTuple for CronSteps.

Returns

fn

Curried function with limit in context.

▸ <Value>(parser): (source: string) => Maybe<CronSteps<Value>>

Type parameters
Name
Value
Parameters
NameType
parserStringValueParser<Value>
Returns

fn

▸ (source): Maybe<CronSteps<Value>>

Parameters
NameType
sourcestring
Returns

Maybe<CronSteps<Value>>

Example

const parseSecondsSteps = parseStringSteps([0, 59])(parseStringSecondsValue);
parseSecondsSteps("13/10"); // { every: 10, start: 13 }
parseSecondsSteps("13-10/10"); // { every: 10, start: { from: 13, to: 10 } }
parseSecondsSteps("?/10"); // { every: 10, start: "?" }
parseSecondsSteps("13"); // undefined

View source


parseStringUnix

parseStringUnix(source): Maybe<CronUnix>

Parses a string into a CronUnix.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronUnix>

A CronUnix or undefined if invalid.

Example

parseStringUnix("* * * * *");
// {
// dayOfMonth: "*",
// dayOfWeek: "*",
// hours: "*",
// minutes: "*",
// month: "*",
// }
parseStringUnix("* * * * *");
// {
// dayOfMonth: "*",
// dayOfWeek: "*",
// hours: "*",
// minutes: "*",
// month: "*",
// }
parseStringUnix("1,2 1,2 1,2 1,2 1,2");
// {
// dayOfMonth: [1, 2],
// dayOfWeek: [1, 2],
// hours: [1, 2],
// minutes: [1, 2],
// month: [1, 2],
// }
parseStringUnix("1-2 1-2 1-2 1-2 1-2");
// {
// dayOfMonth: { from: 1, to: 2 },
// dayOfWeek: { from: 1, to: 2 },
// hours: { from: 1, to: 2 },
// minutes: { from: 1, to: 2 },
// month: { from: 1, to: 2 },
// }
parseStringUnix("1/2 1/2 1/2 1/2 1/2");
// {
// dayOfMonth: { every: 2, start: 1 },
// dayOfWeek: { every: 2, start: 1 },
// hours: { every: 2, start: 1 },
// minutes: { every: 2, start: 1 },
// month: { every: 2, start: 1 },
// }
parseStringUnix("1-2,3,4 * 2W SEP,OCT 1L");
// {
// dayOfMonth: { nearest: 2 },
// dayOfWeek: { last: 1 },
// hours: "*",
// minutes: [{ from: 1, to: 2 }, 3, 4],
// month: ["SEP", "OCT"],
// }
parseStringUnix("INVALID"); // undefined

View source


parseStringUnixExpression

parseStringUnixExpression(source): undefined | readonly [string, string, string, string, string]

Parses given expression or undefined if invalid.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

undefined | readonly [string, string, string, string, string]

An array of 5 elements or undefined if invalid.

Example

parseStringUnixExpression("1 1 1 1 1"); // ["1", "1", "1", "1", "1"]
parseStringUnixExpression(" 1 1 1 1 1 "); // ["1", "1", "1", "1", "1"]
parseStringUnixExpression("1 1 1 1 1 1"); // undefined
parseStringUnixExpression("1 1 1 1"); // undefined

View source


parseStringYear

parseStringYear(source): Maybe<CronPart<CronYearValue>>

Parses a string into a CronYear.

Parameters

NameTypeDescription
sourcestringstring to be parsed.

Returns

Maybe<CronPart<CronYearValue>>

A CronYear or undefined if invalid.

Example

parseStringYear("1989"); // 1989,
parseStringYear("*"); // "*",
parseStringYear("1989/10"); // { every: 10, start: 1989 },
parseStringYear("?/10"); // { every: 10, start: "?" },
parseStringYear("1989,1991,2015,2020"); // [1989, 1991, 2015, 2020],
parseStringYear("1989-2020"); // { from: 1989, to: 2020 },
parseStringYear("1989,1991,2015,2020,1989-2020"); // [1989, 1991, 2015, 2020, { from: 1989, to: 2020 }],
parseStringYear("INVALID"); // undefined,
parseStringYear("1,2,3,4,INVALID"); // undefined,

View source


parseStringYearValue

parseStringYearValue(...input): Maybe<CronYearValue>

Parses a string into a CronYearValue.

Parameters

NameType
...inputSingle<string>

Returns

Maybe<CronYearValue>

A CronYearValue or undefined if invalid.

Example

parseStringYearValue("1989"); // 1989
parseStringYearValue("3000"); // undefined

View source

Predicates

isCronDayOfMonthValue

isCronDayOfMonthValue(value): value is CronDayOfMonthValue

Check if given is CronDayOfMonthValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronDayOfMonthValue

Returns true if is CronDayOfMonthValue, false otherwise.

Example

isCronDayOfMonthValue(13); // true
isCronDayOfMonthValue(50); // false

View source


isCronDayOfWeekValue

isCronDayOfWeekValue(value): value is CronDayOfWeekValue

Check if given is CronDayOfWeekValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronDayOfWeekValue

Returns true if is CronDayOfWeekValue, false otherwise.

Example

isCronDayOfWeekValue(5); // true
isCronDayOfWeekValue("FRI"); // true
isCronDayOfWeekValue("fri"); // true
isCronDayOfWeekValue("FRIDAY"); // false
isCronDayOfWeekValue(10); // false
isCronDayOfWeekValue("INVALID"); // false

View source


isCronDayOfWeekValueNumber

isCronDayOfWeekValueNumber(value): value is CronDayOfWeekValueNumber

Check if given is CronDayOfWeekValueNumber.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronDayOfWeekValueNumber

Returns true if is CronDayOfWeekValueNumber, false otherwise.

Example

isCronDayOfWeekValueNumber(5); // true
isCronDayOfWeekValueNumber(10); // false
isCronDayOfWeekValueNumber("INVALID"); // false

View source


isCronDayOfWeekValueString

isCronDayOfWeekValueString(value): value is CronDayOfWeekValueString

Check if given is CronDayOfWeekValueString.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronDayOfWeekValueString

Returns true if is CronDayOfWeekValueString, false otherwise.

Example

isCronDayOfWeekValueString("FRI"); // true
isCronDayOfWeekValueString("fri"); // true
isCronDayOfWeekValueString("FRIDAY"); // false

View source


isCronEvery

isCronEvery(value): value is ”*“

Check if given is CronEvery.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is ”*“

Returns true if is CronEvery, false otherwise.

Example

isCronEvery("*"); // true
isCronEvery("INVALID"); // false

View source


isCronHoursValue

isCronHoursValue(value): value is CronHoursValue

Check if given is CronHoursValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronHoursValue

Returns true if is CronHoursValue, false otherwise.

Example

isCronHoursValue(12); // true
isCronHoursValue(50); // false

View source


isCronLast

isCronLast(value): value is “L”

Check if given is CronLast.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is “L”

Returns true if is CronLast, false otherwise.

Example

isCronLast("L"); // true
isCronLast("INVALID"); // false

View source


isCronLastValue

isCronLastValue(value): value is CronLastValue

Check if given is CronLastValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronLastValue

Returns true if is CronLastValue, false otherwise.

Example

isCronLastValue({ last: 7 }); // true
isCronLastValue({ last: 100 }); // false

View source


isCronList

isCronList<Value>(value): value is CronList<Value>

Check if given is CronList.

Type parameters

Name
Value

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronList<Value>

Returns true if is CronList, false otherwise.

Example

isCronList(["value", "value", "value"]); // true

View source


isCronMinutesValue

isCronMinutesValue(value): value is CronMinutesValue

Check if given is CronMinutesValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronMinutesValue

Returns true if is CronMinutesValue, false otherwise.

Example

isCronMinutesValue(30); // true
isCronMinutesValue(80); // false

View source


isCronMonthValue

isCronMonthValue(value): value is CronMonthValue

Check if given is CronMonthValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronMonthValue

Returns true if is CronMonthValue, false otherwise.

Example

isCronMonthValue(10); // true
isCronMonthValue("OCT"); // true
isCronMonthValue("oct"); // true
isCronMonthValue("OCTOBER"); // false
isCronMonthValue(50); // false
isCronMonthValue("INVALID"); // false

View source


isCronMonthValueNumber

isCronMonthValueNumber(value): value is CronMonthValueNumber

Check if given is CronMonthValueNumber.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronMonthValueNumber

Returns true if is CronMonthValueNumber, false otherwise.

Example

isCronMonthValueNumber(10); // true
isCronMonthValueNumber(50); // false

View source


isCronMonthValueString

isCronMonthValueString(value): value is CronMonthValueString

Check if given is CronMonthValueString.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronMonthValueString

Returns true if is CronMonthValueString, false otherwise.

Example

isCronMonthValueString("OCT"); // true
isCronMonthValueString("oct"); // true
isCronMonthValueString("INVALID"); // false

View source


isCronNearestDayOfMonth

isCronNearestDayOfMonth(value): value is CronNearestDayOfMonth

Check if given is CronNearestDayOfMonth.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronNearestDayOfMonth

Returns true if is CronNearestDayOfMonth, false otherwise.

Example

isCronNearestDayOfMonth({ nearest: 10 }); // true
isCronNearestDayOfMonth({ nearest: 100 }); // false

View source


isCronRange

isCronRange<Value>(value): value is CronRange<Value>

Check if given is CronRange.

Type parameters

Name
Value

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronRange<Value>

Returns true if is CronRange, false otherwise.

Example

isCronRange({ from: 10, to: 20 }); // true
isCronRange({}); // false

View source


isCronSpecificDayOfWeek

isCronSpecificDayOfWeek(value): value is CronSpecificDayOfWeek

Check if given is CronSpecificDayOfWeek.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronSpecificDayOfWeek

Returns true if is CronSpecificDayOfWeek, false otherwise.

Example

isCronSpecificDayOfWeek({ day: 1, week: 5 }); // true
isCronSpecificDayOfWeek({ day: 9, week: 9 }); // false

View source


isCronStartOrBlank

isCronStartOrBlank(value): value is ”?”

Check if given is CronStartOrBlank.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is ”?”

Returns true if is CronStartOrBlank, false otherwise.

Example

isCronStartOrBlank("?"); // true
isCronStartOrBlank("INVALID"); // false

View source


isCronSteps

isCronSteps<Value>(value): value is CronSteps<Value>

Check if given is CronSteps.

Type parameters

Name
Value

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronSteps<Value>

Returns true if is CronSteps, false otherwise.

Example

isCronSteps({ every: 10, start: "value" }); // true
isCronSteps({ every: "invalid" }); // false

View source


isCronWeekValue

isCronWeekValue(value): value is CronWeekValue

Check if given is CronWeekValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronWeekValue

Returns true if is CronWeekValue, false otherwise.

Example

isCronWeekValue(2); // true
isCronWeekValue(8); // false

View source


isCronYearValue

isCronYearValue(value): value is CronYearValue

Check if given is CronYearValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is CronYearValue

Returns true if is CronYearValue, false otherwise.

Example

isCronYearValue(1989); // true
isCronYearValue(3000); // false

View source


isStringDayOfMonthValue

isStringDayOfMonthValue(value): value is string

Check if given is a string representing a CronDayOfMonthValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronDayOfMonthValue, false otherwise.

Example

isStringDayOfMonthValue("13"); // true
isStringDayOfMonthValue("50"); // false

View source


isStringDayOfWeekValue

isStringDayOfWeekValue(value): boolean

Check if given is a string representing a CronDayOfWeekValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

boolean

Returns true if is a string representing a CronDayOfWeekValue, false otherwise.

Example

isStringDayOfWeekValue("5"); // true
isStringDayOfWeekValue("FRI"); // true
isStringDayOfWeekValue("fri"); // true
isStringDayOfWeekValue("FRIDAY"); // false
isStringDayOfWeekValue("10"); // false
isStringDayOfWeekValue("INVALID"); // false

View source


isStringDayOfWeekValueNumber

isStringDayOfWeekValueNumber(value): value is string

Check if given is a string representing a CronDayOfWeekValueNumber.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronDayOfWeekValueNumber, false otherwise.

Example

isStringDayOfWeekValueNumber("5"); // true
isStringDayOfWeekValueNumber("10"); // false

View source


isStringHoursValue

isStringHoursValue(value): value is string

Check if given is a string representing a CronHoursValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronHoursValue, false otherwise.

Example

isStringHoursValue("12"); // true
isStringHoursValue("50"); // false

View source


isStringLastValue

isStringLastValue(value): value is string

Check if given is a string representing a CronLastValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronLastValue, false otherwise.

Example

isStringLastValue("7L"); // true
isStringLastValue("7l"); // true
isStringLastValue("100L"); // false
isStringLastValue("INVALID"); // false

View source


isStringList

isStringList(value): value is string

Check if given is a string representing a CronList.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronList, false otherwise.

Example

isStringList("value,value,value"); // true
isStringList("value"); // false

View source


isStringMinutesValue

isStringMinutesValue(value): value is string

Check if given is a string representing a CronMinutesValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronMinutesValue, false otherwise.

Example

isStringMinutesValue("30"); // true
isStringMinutesValue("80"); // false

View source


isStringMonthValue

isStringMonthValue(value): boolean

Check if given is a string representing a CronMonthValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

boolean

Returns true if is a string representing a CronMonthValue, false otherwise.

Example

isStringMonthValue("10"); // true
isStringMonthValue("OCT"); // true
isStringMonthValue("oct"); // true
isStringMonthValue("OCTOBER"); // false
isStringMonthValue("50"); // false
isStringMonthValue("INVALID"); // false

View source


isStringMonthValueNumber

isStringMonthValueNumber(value): value is string

Check if given is a string representing a CronMonthValueNumber.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronMonthValueNumber, false otherwise.

Example

isStringMonthValueNumber("10"); // true
isStringMonthValueNumber("50"); // false

View source


isStringNearestDayOfMonth

isStringNearestDayOfMonth(value): value is string

Check if given is a string representing a CronNearestDayOfMonth.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronNearestDayOfMonth, false otherwise.

Example

isStringNearestDayOfMonth("10W"); // true
isStringNearestDayOfMonth("10w"); // true
isStringNearestDayOfMonth("100w"); // false
isStringNearestDayOfMonth("INVALID"); // false

View source


isStringRange

isStringRange(value): value is string

Check if given is a string representing a CronRange.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronRange, false otherwise.

Example

isStringRange("10-20"); // true
isStringRange("13-10-1989"); // false
isStringRange("value"); // false

View source


isStringSecondsValue

isStringSecondsValue(value): value is string

Check if given is a string representing a CronSecondsValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronSecondsValue, false otherwise.

Example

isStringSecondsValue("30"); // true
isStringSecondsValue("80"); // false

View source


isStringSpecificDayOfWeek

isStringSpecificDayOfWeek(value): value is string

Check if given is a string representing a CronSpecificDayOfWeek.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronSpecificDayOfWeek, false otherwise.

Example

isStringSpecificDayOfWeek("1#5"); // true
isStringSpecificDayOfWeek("9#9"); // false

View source


isStringSteps

isStringSteps(value): value is string

Check if given is a string representing a CronSteps.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronSteps, false otherwise.

Example

isStringSteps("value/value"); // true
isStringSteps("value/value/value"); // false
isStringSteps("value"); // false

View source


isStringWeekValue

isStringWeekValue(value): value is string

Check if given is a string representing a CronWeekValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronWeekValue, false otherwise.

Example

isStringWeekValue("2"); // true
isStringWeekValue("8"); // false

View source


isStringYearValue

isStringYearValue(value): value is string

Check if given is a string representing a CronYearValue.

Parameters

NameTypeDescription
valueunknownValue to check.

Returns

value is string

Returns true if is a string representing a CronYearValue, false otherwise.

Example

isStringYearValue("1989"); // true
isStringYearValue("3000"); // false

View source


stringIncludesOnlyOnce

stringIncludesOnlyOnce(search): (value: unknown) => value is string

Checks if given search value appears just onces in given value.

Parameters

NameTypeDescription
searchstringValue to search.

Returns

fn

Curried function with search in context.

▸ (value): value is string

Parameters
NameType
valueunknown
Returns

value is string

Example

const includesCommaOnce = stringIncludesOnlyOnce(",");
includesCommaOnce("value,value"); // true
includesCommaOnce("value,value,value"); // false
includesCommaOnce("value"); // false

View source