range

Generates a month sequence between two endpoints.

import { Month } from "@teakit/month";

Month.range("2025-01", "2025-03").map(String);
// ["2025-01", "2025-02", "2025-03"]

Month.range("2025-03", "2025-01").map(String);
// ["2025-03", "2025-02", "2025-01"]

Month.range("2025-01", "2025-06", { step: 2, inclusive: false }).map(String);
// ["2025-01", "2025-03", "2025-05"]

API Reference

Signature

Month.range(start: MonthValue, end: MonthValue, options?: MonthRangeOptions): MonthInstance[];

Parameters

ParameterTypeRequiredNotes
startMonthValueYesFirst month in the sequence.
endMonthValueYesBoundary month.
options.inclusivebooleanNoDefaults to true.
options.stepnumberNoSafe non-zero integer. Defaults to 1 for ascending ranges and -1 for descending ranges.

Returns

Returns an array of immutable MonthInstance values.

Throws

  • Throws when step is 0.
  • Throws when step moves away from end.

Agent Contract

FieldValue
Kindstatic sequence utility
Canonical namerange
AliasesNone
Mutates inputsNo
ReturnsMonthInstance[]

Agent Notes

  • Use .map(String) or .map((month) => month.toString()) when string output is needed.
  • Be careful with large ranges because this method allocates the full array.