toObject

Converts the month to a plain object with its display year and month strings and an _isMonth brand. It is a pure month view: the hidden day anchor is never included.

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

Month.from("2025-01").toObject();
// { _isMonth: true, year: "2025", month: "01" }

Month.from("2025-01-31").toObject();
// { _isMonth: true, year: "2025", month: "01" } — no day anchor

// Round-trips through Month.from for the month value.
Month.from(Month.from("2025-01").toObject()).toString(); // "2025-01"

API Reference

Signature

month.toObject(): { _isMonth: true; year: string; month: string };

Parameters

None.

Returns

Returns a MonthObject: _isMonth is true, year is the four-digit year string, and month is the zero-padded month string. No day or anchor field is included.

Agent Contract

FieldValue
Kindconversion
Canonical nametoObject
Mutates receiverNo
ReturnsMonthObject
Includes day anchorNo
Related methodstoString, from

Agent Notes

  • toObject() never exposes the day anchor, and Month.from(...) object input never reads one. An object round-trip therefore drops the anchor, so day precision is unavailable afterward — keep the string or the Month instance if you need the day.
  • Use toObject() for a plain month view; use toJSON or toString for string output.