@mdgascar/date 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Malagasy dates: `Alatsinainy 23 Novambra 2026`, month and weekday names, from Unicode CLDR.
4
4
  Zero dependencies, ESM + CommonJS + types.
5
5
 
6
- Implements spec 0.6.0.
6
+ Implements spec 0.7.0.
7
7
 
8
8
  ```sh
9
9
  npm install @mdgascar/date
package/dist/index.cjs CHANGED
@@ -63,7 +63,7 @@ var MIN_YEAR = 1;
63
63
  var MAX_YEAR = 9999;
64
64
 
65
65
  // src/generated/errors.ts
66
- var SPEC_VERSION = "0.6.0";
66
+ var SPEC_VERSION = "0.7.0";
67
67
  var MdgError = class extends Error {
68
68
  /** Always `'MdgError'`. */
69
69
  name = "MdgError";
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/calendar.ts","../src/names.ts","../src/format.ts"],"names":[],"mappings":";;;AAKO,IAAM,WAAA,GAAc;AAAA,EACzB,EAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,mBAAA,GAAsB;AAAA,EACjC,EAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,aAAA,GAAgB;AAAA,EAC3B,EAAA;AAAA,EACA,aAAA;AAAA,EACA,QAAA;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EAAA,OAAO,QAAQ,OAAA,CAAQ,aAAA,EAAe,CAAC,KAAA,KAAU,MAAA,CAAO,KAAqB,CAAC,CAAA;AAChF;AAoBO,SAAS,UAAA,CACd,IAAA,EACA,KAAA,GAAmB,aAAA,EACX;AACR,EAAA,MAAM,OAAA,GAAU,cAAA,CAAe,GAAA,CAAI,KAAK,CAAA;AACxC,EAAA,IAAI,YAAY,MAAA,EAAW;AACzB,IAAA,MAAM,IAAI,QAAA;AAAA,MACR,cAAA;AAAA,MACA,CAAA,iBAAA,EAAoB,CAAC,GAAG,cAAA,CAAe,MAAM,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,OAAA,EAAS,cAAA,CAAe,IAAI,CAAC,CAAA;AAC7C","file":"index.cjs","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/date/data.yaml, spec 0.6.0.\n\n/** @internal Index = month number; index 0 is unused. */\nexport const MONTH_NAMES = [\n '',\n 'Janoary',\n 'Febroary',\n 'Martsa',\n 'Aprily',\n 'Mey',\n 'Jona',\n 'Jolay',\n 'Aogositra',\n 'Septambra',\n 'Oktobra',\n 'Novambra',\n 'Desambra',\n] as const;\n\n/** @internal Index = month number. */\nexport const MONTH_ABBREVIATIONS = [\n '',\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'Mey',\n 'Jon',\n 'Jol',\n 'Aog',\n 'Sep',\n 'Okt',\n 'Nov',\n 'Des',\n] as const;\n\n/** @internal Index = ISO weekday (Monday 1); index 0 is unused. */\nexport const WEEKDAY_NAMES = [\n '',\n 'Alatsinainy',\n 'Talata',\n 'Alarobia',\n 'Alakamisy',\n 'Zoma',\n 'Asabotsy',\n 'Alahady',\n] as const;\n\n/** @internal Index = ISO weekday. */\nexport const WEEKDAY_ABBREVIATIONS = [\n '',\n 'Alats',\n 'Tal',\n 'Alar',\n 'Alak',\n 'Zom',\n 'Asab',\n 'Alah',\n] as const;\n\n/** Date style for {@link formatDate}; `long` is the default. */\nexport type DateStyle = 'long' | 'full' | 'medium' | 'short' | 'numeric';\n\n/** @internal Style → CLDR pattern; the first entry is the default. */\nexport const STYLE_PATTERNS: ReadonlyMap<DateStyle, string> = new Map<DateStyle, string>([\n ['long', 'd MMMM y'],\n ['full', 'EEEE d MMMM y'],\n ['medium', 'y MMM d'],\n ['short', 'y-MM-dd'],\n ['numeric', 'dd/MM/y'],\n]);\n\n/** @internal */\nexport const DEFAULT_STYLE = 'long' as const;\n\n/** @internal */\nexport const MIN_YEAR = 1 as const;\n\n/** @internal */\nexport const MAX_YEAR = 9999 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.6.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MAX_YEAR, MIN_YEAR, WEEKDAY_NAMES } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * A calendar date: year 1–9999, month 1–12, day of the month.\n *\n * @example\n * ```ts\n * const independenceDay: CalendarDate = { year: 1960, month: 6, day: 26 };\n * ```\n */\nexport interface CalendarDate {\n /** Year, 1 to 9999. */\n readonly year: number;\n /** Month, 1 (Janoary) to 12 (Desambra). */\n readonly month: number;\n /** Day of the month, 1 to 31. */\n readonly day: number;\n}\n\n/** @internal ISO month number. */\nexport type MonthNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;\n/** @internal ISO weekday: Monday 1 … Sunday 7. */\nexport type IsoWeekday = 1 | 2 | 3 | 4 | 5 | 6 | 7;\n\nconst ISO_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DAYS_PER_WEEK = WEEKDAY_NAMES.length - 1;\n// JavaScript numbers Sunday 0; ISO 8601 numbers it 7.\nconst JAVASCRIPT_SUNDAY = 0;\n\n// A UTC date at midnight, so the calendar checks never depend on the local time zone.\nfunction utcDate({ year, month, day }: CalendarDate): Date {\n const date = new Date(0);\n date.setUTCFullYear(year, month - 1, day);\n return date;\n}\n\nfunction isRealDate(date: CalendarDate): boolean {\n const probe = utcDate(date);\n return (\n probe.getUTCFullYear() === date.year &&\n probe.getUTCMonth() === date.month - 1 &&\n probe.getUTCDate() === date.day\n );\n}\n\nfunction checked(\n date: CalendarDate,\n impossibleDateCode: 'INVALID_FORMAT' | 'OUT_OF_RANGE',\n): CalendarDate {\n if (date.year < MIN_YEAR || date.year > MAX_YEAR) {\n throw new MdgError('OUT_OF_RANGE', `Years go from ${String(MIN_YEAR)} to ${String(MAX_YEAR)}.`);\n }\n if (!isRealDate(date)) throw new MdgError(impossibleDateCode, 'This day does not exist.');\n return date;\n}\n\nfunction fromText(text: string): CalendarDate {\n const match = ISO_DATE.exec(text);\n if (match === null) throw new MdgError('INVALID_FORMAT', 'Expected a date as YYYY-MM-DD.');\n const [, year, month, day] = match;\n return checked({ year: Number(year), month: Number(month), day: Number(day) }, 'INVALID_FORMAT');\n}\n\nfunction fromFields(fields: object): CalendarDate {\n const { year, month, day } = fields as Partial<Record<keyof CalendarDate, unknown>>;\n if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) {\n throw new MdgError('INVALID_TYPE', 'Expected whole numbers for year, month and day.');\n }\n return checked({ year, month, day } as CalendarDate, 'OUT_OF_RANGE');\n}\n\nfunction fromDate(date: Date): CalendarDate {\n if (Number.isNaN(date.getTime())) throw new MdgError('INVALID_FORMAT', 'Invalid Date.');\n const fields = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };\n return checked(fields, 'OUT_OF_RANGE');\n}\n\n/**\n * @internal Reads any accepted date input at the public boundary.\n *\n * @param input - `YYYY-MM-DD` text, calendar fields or a `Date`.\n * @returns The validated calendar date.\n */\nexport function toCalendarDate(input: unknown): CalendarDate {\n if (typeof input === 'string') return fromText(input);\n if (input instanceof Date) return fromDate(input);\n if (typeof input === 'object' && input !== null) return fromFields(input);\n throw new MdgError('INVALID_TYPE', 'Expected YYYY-MM-DD text, { year, month, day } or a Date.');\n}\n\n/**\n * @internal ISO weekday of a valid calendar date.\n *\n * @param date - A date already checked by {@link toCalendarDate}.\n * @returns Monday 1 … Sunday 7.\n */\nexport function isoWeekdayOf(date: CalendarDate): IsoWeekday {\n const weekday = utcDate(date).getUTCDay();\n return (weekday === JAVASCRIPT_SUNDAY ? DAYS_PER_WEEK : weekday) as IsoWeekday;\n}\n","import {\n MONTH_ABBREVIATIONS,\n MONTH_NAMES,\n WEEKDAY_ABBREVIATIONS,\n WEEKDAY_NAMES,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport type { IsoWeekday, MonthNumber } from './calendar.ts';\n\n/**\n * Name width: `wide` (`Novambra`, default) or `abbreviated` (`Nov`).\n *\n * @example\n * ```ts\n * const width: NameWidth = 'abbreviated';\n * ```\n */\nexport type NameWidth = 'wide' | 'abbreviated';\n\nconst NAME_WIDTHS: ReadonlySet<unknown> = new Set<NameWidth>(['wide', 'abbreviated']);\n\nfunction checkedNumber(value: unknown, last: number, what: string): number {\n if (typeof value !== 'number' || !Number.isInteger(value)) {\n throw new MdgError('INVALID_TYPE', `Expected a whole ${what} number.`);\n }\n if (value < 1 || value > last) {\n throw new MdgError('OUT_OF_RANGE', `${what} numbers go from 1 to ${String(last)}.`);\n }\n return value;\n}\n\nfunction checkedWidth(width: unknown): NameWidth {\n if (!NAME_WIDTHS.has(width)) throw new MdgError('INVALID_TYPE', 'Width is wide or abbreviated.');\n return width as NameWidth;\n}\n\n/**\n * @internal Month name for a valid month number.\n *\n * @param month - Month 1–12.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy month name.\n */\nexport function monthNameOf(month: MonthNumber, width: NameWidth): string {\n return width === 'wide' ? MONTH_NAMES[month] : MONTH_ABBREVIATIONS[month];\n}\n\n/**\n * @internal Weekday name for a valid ISO weekday.\n *\n * @param weekday - Monday 1 … Sunday 7.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy weekday name.\n */\nexport function weekdayNameOf(weekday: IsoWeekday, width: NameWidth): string {\n return width === 'wide' ? WEEKDAY_NAMES[weekday] : WEEKDAY_ABBREVIATIONS[weekday];\n}\n\n/**\n * The Malagasy name of a month.\n *\n * @param month - Month number, 1 (Janoary) to 12 (Desambra).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The month name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getMonthName(6); // 'Jona'\n * getMonthName(11, 'abbreviated'); // 'Nov'\n * ```\n */\nexport function getMonthName(month: number, width: NameWidth = 'wide'): string {\n const checkedMonth = checkedNumber(month, MONTH_NAMES.length - 1, 'Month');\n return monthNameOf(checkedMonth as MonthNumber, checkedWidth(width));\n}\n\n/**\n * The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).\n *\n * @param isoWeekday - 1 (Alatsinainy) to 7 (Alahady).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The weekday name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getWeekdayName(1); // 'Alatsinainy'\n * getWeekdayName(7, 'abbreviated'); // 'Alah'\n * ```\n */\nexport function getWeekdayName(isoWeekday: number, width: NameWidth = 'wide'): string {\n const checkedWeekday = checkedNumber(isoWeekday, WEEKDAY_NAMES.length - 1, 'Weekday');\n return weekdayNameOf(checkedWeekday as IsoWeekday, checkedWidth(width));\n}\n","import { DEFAULT_STYLE, STYLE_PATTERNS, type DateStyle } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { isoWeekdayOf, toCalendarDate, type CalendarDate, type MonthNumber } from './calendar.ts';\nimport { monthNameOf, weekdayNameOf } from './names.ts';\n\ntype PatternToken = 'EEEE' | 'MMMM' | 'MMM' | 'MM' | 'dd' | 'd' | 'y';\n\n// CLDR pattern letters used by the spec styles; longest first so `MMMM` wins over `MM`.\nconst PATTERN_TOKEN = /EEEE|MMMM|MMM|MM|dd|d|y/g;\nconst TWO_DIGITS = 2;\n\nfunction twoDigits(value: number): string {\n return String(value).padStart(TWO_DIGITS, '0');\n}\n\nfunction render(pattern: string, date: CalendarDate): string {\n const month = date.month as MonthNumber;\n const values: Readonly<Record<PatternToken, string>> = {\n EEEE: weekdayNameOf(isoWeekdayOf(date), 'wide'),\n MMMM: monthNameOf(month, 'wide'),\n MMM: monthNameOf(month, 'abbreviated'),\n MM: twoDigits(date.month),\n dd: twoDigits(date.day),\n d: String(date.day),\n y: String(date.year),\n };\n return pattern.replace(PATTERN_TOKEN, (token) => values[token as PatternToken]);\n}\n\n/**\n * Writes a date in Malagasy.\n *\n * @param date - `YYYY-MM-DD` text, `{ year, month, day }`, or a `Date` (read in its local\n * calendar fields).\n * @param style - `long` (default), `full`, `medium`, `short` (CLDR) or `numeric` (`dd/MM/y`).\n * @returns The formatted date.\n * @throws {@link MdgError} `INVALID_FORMAT` for text that is not a real `YYYY-MM-DD` date,\n * `OUT_OF_RANGE` for impossible fields or years outside 1–9999, `INVALID_TYPE` for other\n * input or an unknown style.\n *\n * @example\n * ```ts\n * formatDate('2026-11-23'); // '23 Novambra 2026'\n * formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'\n * formatDate({ year: 1960, month: 6, day: 26 }, 'numeric'); // '26/06/1960'\n * ```\n */\nexport function formatDate(\n date: string | CalendarDate | Date,\n style: DateStyle = DEFAULT_STYLE,\n): string {\n const pattern = STYLE_PATTERNS.get(style);\n if (pattern === undefined) {\n throw new MdgError(\n 'INVALID_TYPE',\n `Style is one of: ${[...STYLE_PATTERNS.keys()].join(', ')}.`,\n );\n }\n return render(pattern, toCalendarDate(date));\n}\n"]}
1
+ {"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/calendar.ts","../src/names.ts","../src/format.ts"],"names":[],"mappings":";;;AAKO,IAAM,WAAA,GAAc;AAAA,EACzB,EAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,Q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B,EAAA,MAAM,MAAA,GAAiD;AAAA,IACrD,IAAA,EAAM,aAAA,CAAc,YAAA,CAAa,IAAI,GAAG,MAAM,CAAA;AAAA,IAC9C,IAAA,EAAM,WAAA,CAAY,KAAA,EAAO,MAAM,CAAA;AAAA,IAC/B,GAAA,EAAK,WAAA,CAAY,KAAA,EAAO,aAAa,CAAA;AAAA,IACrC,EAAA,EAAI,SAAA,CAAU,IAAA,CAAK,KAAK,CAAA;AAAA,IACxB,EAAA,EAAI,SAAA,CAAU,IAAA,CAAK,GAAG,CAAA;AAAA,IACtB,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA;AAAA,IAClB,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA,GACrB;AACA,EAAA,OAAO,QAAQ,OAAA,CAAQ,aAAA,EAAe,CAAC,KAAA,KAAU,MAAA,CAAO,KAAqB,CAAC,CAAA;AAChF;AAoBO,SAAS,UAAA,CACd,IAAA,EACA,KAAA,GAAmB,aAAA,EACX;AACR,EAAA,MAAM,OAAA,GAAU,cAAA,CAAe,GAAA,CAAI,KAAK,CAAA;AACxC,EAAA,IAAI,YAAY,MAAA,EAAW;AACzB,IAAA,MAAM,IAAI,QAAA;AAAA,MACR,cAAA;AAAA,MACA,CAAA,iBAAA,EAAoB,CAAC,GAAG,cAAA,CAAe,MAAM,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,OAAA,EAAS,cAAA,CAAe,IAAI,CAAC,CAAA;AAC7C","file":"index.cjs","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/date/data.yaml, spec 0.7.0.\n\n/** @internal Index = month number; index 0 is unused. */\nexport const MONTH_NAMES = [\n '',\n 'Janoary',\n 'Febroary',\n 'Martsa',\n 'Aprily',\n 'Mey',\n 'Jona',\n 'Jolay',\n 'Aogositra',\n 'Septambra',\n 'Oktobra',\n 'Novambra',\n 'Desambra',\n] as const;\n\n/** @internal Index = month number. */\nexport const MONTH_ABBREVIATIONS = [\n '',\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'Mey',\n 'Jon',\n 'Jol',\n 'Aog',\n 'Sep',\n 'Okt',\n 'Nov',\n 'Des',\n] as const;\n\n/** @internal Index = ISO weekday (Monday 1); index 0 is unused. */\nexport const WEEKDAY_NAMES = [\n '',\n 'Alatsinainy',\n 'Talata',\n 'Alarobia',\n 'Alakamisy',\n 'Zoma',\n 'Asabotsy',\n 'Alahady',\n] as const;\n\n/** @internal Index = ISO weekday. */\nexport const WEEKDAY_ABBREVIATIONS = [\n '',\n 'Alats',\n 'Tal',\n 'Alar',\n 'Alak',\n 'Zom',\n 'Asab',\n 'Alah',\n] as const;\n\n/** Date style for {@link formatDate}; `long` is the default. */\nexport type DateStyle = 'long' | 'full' | 'medium' | 'short' | 'numeric';\n\n/** @internal Style → CLDR pattern; the first entry is the default. */\nexport const STYLE_PATTERNS: ReadonlyMap<DateStyle, string> = new Map<DateStyle, string>([\n ['long', 'd MMMM y'],\n ['full', 'EEEE d MMMM y'],\n ['medium', 'y MMM d'],\n ['short', 'y-MM-dd'],\n ['numeric', 'dd/MM/y'],\n]);\n\n/** @internal */\nexport const DEFAULT_STYLE = 'long' as const;\n\n/** @internal */\nexport const MIN_YEAR = 1 as const;\n\n/** @internal */\nexport const MAX_YEAR = 9999 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.7.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MAX_YEAR, MIN_YEAR, WEEKDAY_NAMES } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * A calendar date: year 1–9999, month 1–12, day of the month.\n *\n * @example\n * ```ts\n * const independenceDay: CalendarDate = { year: 1960, month: 6, day: 26 };\n * ```\n */\nexport interface CalendarDate {\n /** Year, 1 to 9999. */\n readonly year: number;\n /** Month, 1 (Janoary) to 12 (Desambra). */\n readonly month: number;\n /** Day of the month, 1 to 31. */\n readonly day: number;\n}\n\n/** @internal ISO month number. */\nexport type MonthNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;\n/** @internal ISO weekday: Monday 1 … Sunday 7. */\nexport type IsoWeekday = 1 | 2 | 3 | 4 | 5 | 6 | 7;\n\nconst ISO_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DAYS_PER_WEEK = WEEKDAY_NAMES.length - 1;\n// JavaScript numbers Sunday 0; ISO 8601 numbers it 7.\nconst JAVASCRIPT_SUNDAY = 0;\n\n// A UTC date at midnight, so the calendar checks never depend on the local time zone.\nfunction utcDate({ year, month, day }: CalendarDate): Date {\n const date = new Date(0);\n date.setUTCFullYear(year, month - 1, day);\n return date;\n}\n\nfunction isRealDate(date: CalendarDate): boolean {\n const probe = utcDate(date);\n return (\n probe.getUTCFullYear() === date.year &&\n probe.getUTCMonth() === date.month - 1 &&\n probe.getUTCDate() === date.day\n );\n}\n\nfunction checked(\n date: CalendarDate,\n impossibleDateCode: 'INVALID_FORMAT' | 'OUT_OF_RANGE',\n): CalendarDate {\n if (date.year < MIN_YEAR || date.year > MAX_YEAR) {\n throw new MdgError('OUT_OF_RANGE', `Years go from ${String(MIN_YEAR)} to ${String(MAX_YEAR)}.`);\n }\n if (!isRealDate(date)) throw new MdgError(impossibleDateCode, 'This day does not exist.');\n return date;\n}\n\nfunction fromText(text: string): CalendarDate {\n const match = ISO_DATE.exec(text);\n if (match === null) throw new MdgError('INVALID_FORMAT', 'Expected a date as YYYY-MM-DD.');\n const [, year, month, day] = match;\n return checked({ year: Number(year), month: Number(month), day: Number(day) }, 'INVALID_FORMAT');\n}\n\nfunction fromFields(fields: object): CalendarDate {\n const { year, month, day } = fields as Partial<Record<keyof CalendarDate, unknown>>;\n if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) {\n throw new MdgError('INVALID_TYPE', 'Expected whole numbers for year, month and day.');\n }\n return checked({ year, month, day } as CalendarDate, 'OUT_OF_RANGE');\n}\n\nfunction fromDate(date: Date): CalendarDate {\n if (Number.isNaN(date.getTime())) throw new MdgError('INVALID_FORMAT', 'Invalid Date.');\n const fields = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };\n return checked(fields, 'OUT_OF_RANGE');\n}\n\n/**\n * @internal Reads any accepted date input at the public boundary.\n *\n * @param input - `YYYY-MM-DD` text, calendar fields or a `Date`.\n * @returns The validated calendar date.\n */\nexport function toCalendarDate(input: unknown): CalendarDate {\n if (typeof input === 'string') return fromText(input);\n if (input instanceof Date) return fromDate(input);\n if (typeof input === 'object' && input !== null) return fromFields(input);\n throw new MdgError('INVALID_TYPE', 'Expected YYYY-MM-DD text, { year, month, day } or a Date.');\n}\n\n/**\n * @internal ISO weekday of a valid calendar date.\n *\n * @param date - A date already checked by {@link toCalendarDate}.\n * @returns Monday 1 … Sunday 7.\n */\nexport function isoWeekdayOf(date: CalendarDate): IsoWeekday {\n const weekday = utcDate(date).getUTCDay();\n return (weekday === JAVASCRIPT_SUNDAY ? DAYS_PER_WEEK : weekday) as IsoWeekday;\n}\n","import {\n MONTH_ABBREVIATIONS,\n MONTH_NAMES,\n WEEKDAY_ABBREVIATIONS,\n WEEKDAY_NAMES,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport type { IsoWeekday, MonthNumber } from './calendar.ts';\n\n/**\n * Name width: `wide` (`Novambra`, default) or `abbreviated` (`Nov`).\n *\n * @example\n * ```ts\n * const width: NameWidth = 'abbreviated';\n * ```\n */\nexport type NameWidth = 'wide' | 'abbreviated';\n\nconst NAME_WIDTHS: ReadonlySet<unknown> = new Set<NameWidth>(['wide', 'abbreviated']);\n\nfunction checkedNumber(value: unknown, last: number, what: string): number {\n if (typeof value !== 'number' || !Number.isInteger(value)) {\n throw new MdgError('INVALID_TYPE', `Expected a whole ${what} number.`);\n }\n if (value < 1 || value > last) {\n throw new MdgError('OUT_OF_RANGE', `${what} numbers go from 1 to ${String(last)}.`);\n }\n return value;\n}\n\nfunction checkedWidth(width: unknown): NameWidth {\n if (!NAME_WIDTHS.has(width)) throw new MdgError('INVALID_TYPE', 'Width is wide or abbreviated.');\n return width as NameWidth;\n}\n\n/**\n * @internal Month name for a valid month number.\n *\n * @param month - Month 1–12.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy month name.\n */\nexport function monthNameOf(month: MonthNumber, width: NameWidth): string {\n return width === 'wide' ? MONTH_NAMES[month] : MONTH_ABBREVIATIONS[month];\n}\n\n/**\n * @internal Weekday name for a valid ISO weekday.\n *\n * @param weekday - Monday 1 … Sunday 7.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy weekday name.\n */\nexport function weekdayNameOf(weekday: IsoWeekday, width: NameWidth): string {\n return width === 'wide' ? WEEKDAY_NAMES[weekday] : WEEKDAY_ABBREVIATIONS[weekday];\n}\n\n/**\n * The Malagasy name of a month.\n *\n * @param month - Month number, 1 (Janoary) to 12 (Desambra).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The month name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getMonthName(6); // 'Jona'\n * getMonthName(11, 'abbreviated'); // 'Nov'\n * ```\n */\nexport function getMonthName(month: number, width: NameWidth = 'wide'): string {\n const checkedMonth = checkedNumber(month, MONTH_NAMES.length - 1, 'Month');\n return monthNameOf(checkedMonth as MonthNumber, checkedWidth(width));\n}\n\n/**\n * The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).\n *\n * @param isoWeekday - 1 (Alatsinainy) to 7 (Alahady).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The weekday name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getWeekdayName(1); // 'Alatsinainy'\n * getWeekdayName(7, 'abbreviated'); // 'Alah'\n * ```\n */\nexport function getWeekdayName(isoWeekday: number, width: NameWidth = 'wide'): string {\n const checkedWeekday = checkedNumber(isoWeekday, WEEKDAY_NAMES.length - 1, 'Weekday');\n return weekdayNameOf(checkedWeekday as IsoWeekday, checkedWidth(width));\n}\n","import { DEFAULT_STYLE, STYLE_PATTERNS, type DateStyle } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { isoWeekdayOf, toCalendarDate, type CalendarDate, type MonthNumber } from './calendar.ts';\nimport { monthNameOf, weekdayNameOf } from './names.ts';\n\ntype PatternToken = 'EEEE' | 'MMMM' | 'MMM' | 'MM' | 'dd' | 'd' | 'y';\n\n// CLDR pattern letters used by the spec styles; longest first so `MMMM` wins over `MM`.\nconst PATTERN_TOKEN = /EEEE|MMMM|MMM|MM|dd|d|y/g;\nconst TWO_DIGITS = 2;\n\nfunction twoDigits(value: number): string {\n return String(value).padStart(TWO_DIGITS, '0');\n}\n\nfunction render(pattern: string, date: CalendarDate): string {\n const month = date.month as MonthNumber;\n const values: Readonly<Record<PatternToken, string>> = {\n EEEE: weekdayNameOf(isoWeekdayOf(date), 'wide'),\n MMMM: monthNameOf(month, 'wide'),\n MMM: monthNameOf(month, 'abbreviated'),\n MM: twoDigits(date.month),\n dd: twoDigits(date.day),\n d: String(date.day),\n y: String(date.year),\n };\n return pattern.replace(PATTERN_TOKEN, (token) => values[token as PatternToken]);\n}\n\n/**\n * Writes a date in Malagasy.\n *\n * @param date - `YYYY-MM-DD` text, `{ year, month, day }`, or a `Date` (read in its local\n * calendar fields).\n * @param style - `long` (default), `full`, `medium`, `short` (CLDR) or `numeric` (`dd/MM/y`).\n * @returns The formatted date.\n * @throws {@link MdgError} `INVALID_FORMAT` for text that is not a real `YYYY-MM-DD` date,\n * `OUT_OF_RANGE` for impossible fields or years outside 1–9999, `INVALID_TYPE` for other\n * input or an unknown style.\n *\n * @example\n * ```ts\n * formatDate('2026-11-23'); // '23 Novambra 2026'\n * formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'\n * formatDate({ year: 1960, month: 6, day: 26 }, 'numeric'); // '26/06/1960'\n * ```\n */\nexport function formatDate(\n date: string | CalendarDate | Date,\n style: DateStyle = DEFAULT_STYLE,\n): string {\n const pattern = STYLE_PATTERNS.get(style);\n if (pattern === undefined) {\n throw new MdgError(\n 'INVALID_TYPE',\n `Style is one of: ${[...STYLE_PATTERNS.keys()].join(', ')}.`,\n );\n }\n return render(pattern, toCalendarDate(date));\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -81,7 +81,7 @@ declare function getMonthName(month: number, width?: NameWidth): string;
81
81
  declare function getWeekdayName(isoWeekday: number, width?: NameWidth): string;
82
82
 
83
83
  /** Version of the shared spec this code was generated from. */
84
- declare const SPEC_VERSION = "0.6.0";
84
+ declare const SPEC_VERSION = "0.7.0";
85
85
  /**
86
86
  * Error code shared by every mdg-utils language port.
87
87
  *
package/dist/index.d.ts CHANGED
@@ -81,7 +81,7 @@ declare function getMonthName(month: number, width?: NameWidth): string;
81
81
  declare function getWeekdayName(isoWeekday: number, width?: NameWidth): string;
82
82
 
83
83
  /** Version of the shared spec this code was generated from. */
84
- declare const SPEC_VERSION = "0.6.0";
84
+ declare const SPEC_VERSION = "0.7.0";
85
85
  /**
86
86
  * Error code shared by every mdg-utils language port.
87
87
  *
package/dist/index.js CHANGED
@@ -61,7 +61,7 @@ var MIN_YEAR = 1;
61
61
  var MAX_YEAR = 9999;
62
62
 
63
63
  // src/generated/errors.ts
64
- var SPEC_VERSION = "0.6.0";
64
+ var SPEC_VERSION = "0.7.0";
65
65
  var MdgError = class extends Error {
66
66
  /** Always `'MdgError'`. */
67
67
  name = "MdgError";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/calendar.ts","../src/names.ts","../src/format.ts"],"names":[],"mappings":";AAKO,IAAM,WAAA,GAAc;AAAA,EACzB,EAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EAC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AACnB,EAAA,MAAM,MAAA,GAAiD;AAAA,IACrD,IAAA,EAAM,aAAA,CAAc,YAAA,CAAa,IAAI,GAAG,MAAM,CAAA;AAAA,IAC9C,IAAA,EAAM,WAAA,CAAY,KAAA,EAAO,MAAM,CAAA;AAAA,IAC/B,GAAA,EAAK,WAAA,CAAY,KAAA,EAAO,aAAa,CAAA;AAAA,IACrC,EAAA,EAAI,SAAA,CAAU,IAAA,CAAK,KAAK,CAAA;AAAA,IACxB,EAAA,EAAI,SAAA,CAAU,IAAA,CAAK,GAAG,CAAA;AAAA,IACtB,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA;AAAA,IAClB,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA,GACrB;AACA,EAAA,OAAO,QAAQ,OAAA,CAAQ,aAAA,EAAe,CAAC,KAAA,KAAU,MAAA,CAAO,KAAqB,CAAC,CAAA;AAChF;AAoBO,SAAS,UAAA,CACd,IAAA,EACA,KAAA,GAAmB,aAAA,EACX;AACR,EAAA,MAAM,OAAA,GAAU,cAAA,CAAe,GAAA,CAAI,KAAK,CAAA;AACxC,EAAA,IAAI,YAAY,MAAA,EAAW;AACzB,IAAA,MAAM,IAAI,QAAA;AAAA,MACR,cAAA;AAAA,MACA,CAAA,iBAAA,EAAoB,CAAC,GAAG,cAAA,CAAe,MAAM,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,OAAA,EAAS,cAAA,CAAe,IAAI,CAAC,CAAA;AAC7C","file":"index.js","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/date/data.yaml, spec 0.6.0.\n\n/** @internal Index = month number; index 0 is unused. */\nexport const MONTH_NAMES = [\n '',\n 'Janoary',\n 'Febroary',\n 'Martsa',\n 'Aprily',\n 'Mey',\n 'Jona',\n 'Jolay',\n 'Aogositra',\n 'Septambra',\n 'Oktobra',\n 'Novambra',\n 'Desambra',\n] as const;\n\n/** @internal Index = month number. */\nexport const MONTH_ABBREVIATIONS = [\n '',\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'Mey',\n 'Jon',\n 'Jol',\n 'Aog',\n 'Sep',\n 'Okt',\n 'Nov',\n 'Des',\n] as const;\n\n/** @internal Index = ISO weekday (Monday 1); index 0 is unused. */\nexport const WEEKDAY_NAMES = [\n '',\n 'Alatsinainy',\n 'Talata',\n 'Alarobia',\n 'Alakamisy',\n 'Zoma',\n 'Asabotsy',\n 'Alahady',\n] as const;\n\n/** @internal Index = ISO weekday. */\nexport const WEEKDAY_ABBREVIATIONS = [\n '',\n 'Alats',\n 'Tal',\n 'Alar',\n 'Alak',\n 'Zom',\n 'Asab',\n 'Alah',\n] as const;\n\n/** Date style for {@link formatDate}; `long` is the default. */\nexport type DateStyle = 'long' | 'full' | 'medium' | 'short' | 'numeric';\n\n/** @internal Style → CLDR pattern; the first entry is the default. */\nexport const STYLE_PATTERNS: ReadonlyMap<DateStyle, string> = new Map<DateStyle, string>([\n ['long', 'd MMMM y'],\n ['full', 'EEEE d MMMM y'],\n ['medium', 'y MMM d'],\n ['short', 'y-MM-dd'],\n ['numeric', 'dd/MM/y'],\n]);\n\n/** @internal */\nexport const DEFAULT_STYLE = 'long' as const;\n\n/** @internal */\nexport const MIN_YEAR = 1 as const;\n\n/** @internal */\nexport const MAX_YEAR = 9999 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.6.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MAX_YEAR, MIN_YEAR, WEEKDAY_NAMES } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * A calendar date: year 1–9999, month 1–12, day of the month.\n *\n * @example\n * ```ts\n * const independenceDay: CalendarDate = { year: 1960, month: 6, day: 26 };\n * ```\n */\nexport interface CalendarDate {\n /** Year, 1 to 9999. */\n readonly year: number;\n /** Month, 1 (Janoary) to 12 (Desambra). */\n readonly month: number;\n /** Day of the month, 1 to 31. */\n readonly day: number;\n}\n\n/** @internal ISO month number. */\nexport type MonthNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;\n/** @internal ISO weekday: Monday 1 … Sunday 7. */\nexport type IsoWeekday = 1 | 2 | 3 | 4 | 5 | 6 | 7;\n\nconst ISO_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DAYS_PER_WEEK = WEEKDAY_NAMES.length - 1;\n// JavaScript numbers Sunday 0; ISO 8601 numbers it 7.\nconst JAVASCRIPT_SUNDAY = 0;\n\n// A UTC date at midnight, so the calendar checks never depend on the local time zone.\nfunction utcDate({ year, month, day }: CalendarDate): Date {\n const date = new Date(0);\n date.setUTCFullYear(year, month - 1, day);\n return date;\n}\n\nfunction isRealDate(date: CalendarDate): boolean {\n const probe = utcDate(date);\n return (\n probe.getUTCFullYear() === date.year &&\n probe.getUTCMonth() === date.month - 1 &&\n probe.getUTCDate() === date.day\n );\n}\n\nfunction checked(\n date: CalendarDate,\n impossibleDateCode: 'INVALID_FORMAT' | 'OUT_OF_RANGE',\n): CalendarDate {\n if (date.year < MIN_YEAR || date.year > MAX_YEAR) {\n throw new MdgError('OUT_OF_RANGE', `Years go from ${String(MIN_YEAR)} to ${String(MAX_YEAR)}.`);\n }\n if (!isRealDate(date)) throw new MdgError(impossibleDateCode, 'This day does not exist.');\n return date;\n}\n\nfunction fromText(text: string): CalendarDate {\n const match = ISO_DATE.exec(text);\n if (match === null) throw new MdgError('INVALID_FORMAT', 'Expected a date as YYYY-MM-DD.');\n const [, year, month, day] = match;\n return checked({ year: Number(year), month: Number(month), day: Number(day) }, 'INVALID_FORMAT');\n}\n\nfunction fromFields(fields: object): CalendarDate {\n const { year, month, day } = fields as Partial<Record<keyof CalendarDate, unknown>>;\n if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) {\n throw new MdgError('INVALID_TYPE', 'Expected whole numbers for year, month and day.');\n }\n return checked({ year, month, day } as CalendarDate, 'OUT_OF_RANGE');\n}\n\nfunction fromDate(date: Date): CalendarDate {\n if (Number.isNaN(date.getTime())) throw new MdgError('INVALID_FORMAT', 'Invalid Date.');\n const fields = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };\n return checked(fields, 'OUT_OF_RANGE');\n}\n\n/**\n * @internal Reads any accepted date input at the public boundary.\n *\n * @param input - `YYYY-MM-DD` text, calendar fields or a `Date`.\n * @returns The validated calendar date.\n */\nexport function toCalendarDate(input: unknown): CalendarDate {\n if (typeof input === 'string') return fromText(input);\n if (input instanceof Date) return fromDate(input);\n if (typeof input === 'object' && input !== null) return fromFields(input);\n throw new MdgError('INVALID_TYPE', 'Expected YYYY-MM-DD text, { year, month, day } or a Date.');\n}\n\n/**\n * @internal ISO weekday of a valid calendar date.\n *\n * @param date - A date already checked by {@link toCalendarDate}.\n * @returns Monday 1 … Sunday 7.\n */\nexport function isoWeekdayOf(date: CalendarDate): IsoWeekday {\n const weekday = utcDate(date).getUTCDay();\n return (weekday === JAVASCRIPT_SUNDAY ? DAYS_PER_WEEK : weekday) as IsoWeekday;\n}\n","import {\n MONTH_ABBREVIATIONS,\n MONTH_NAMES,\n WEEKDAY_ABBREVIATIONS,\n WEEKDAY_NAMES,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport type { IsoWeekday, MonthNumber } from './calendar.ts';\n\n/**\n * Name width: `wide` (`Novambra`, default) or `abbreviated` (`Nov`).\n *\n * @example\n * ```ts\n * const width: NameWidth = 'abbreviated';\n * ```\n */\nexport type NameWidth = 'wide' | 'abbreviated';\n\nconst NAME_WIDTHS: ReadonlySet<unknown> = new Set<NameWidth>(['wide', 'abbreviated']);\n\nfunction checkedNumber(value: unknown, last: number, what: string): number {\n if (typeof value !== 'number' || !Number.isInteger(value)) {\n throw new MdgError('INVALID_TYPE', `Expected a whole ${what} number.`);\n }\n if (value < 1 || value > last) {\n throw new MdgError('OUT_OF_RANGE', `${what} numbers go from 1 to ${String(last)}.`);\n }\n return value;\n}\n\nfunction checkedWidth(width: unknown): NameWidth {\n if (!NAME_WIDTHS.has(width)) throw new MdgError('INVALID_TYPE', 'Width is wide or abbreviated.');\n return width as NameWidth;\n}\n\n/**\n * @internal Month name for a valid month number.\n *\n * @param month - Month 1–12.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy month name.\n */\nexport function monthNameOf(month: MonthNumber, width: NameWidth): string {\n return width === 'wide' ? MONTH_NAMES[month] : MONTH_ABBREVIATIONS[month];\n}\n\n/**\n * @internal Weekday name for a valid ISO weekday.\n *\n * @param weekday - Monday 1 … Sunday 7.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy weekday name.\n */\nexport function weekdayNameOf(weekday: IsoWeekday, width: NameWidth): string {\n return width === 'wide' ? WEEKDAY_NAMES[weekday] : WEEKDAY_ABBREVIATIONS[weekday];\n}\n\n/**\n * The Malagasy name of a month.\n *\n * @param month - Month number, 1 (Janoary) to 12 (Desambra).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The month name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getMonthName(6); // 'Jona'\n * getMonthName(11, 'abbreviated'); // 'Nov'\n * ```\n */\nexport function getMonthName(month: number, width: NameWidth = 'wide'): string {\n const checkedMonth = checkedNumber(month, MONTH_NAMES.length - 1, 'Month');\n return monthNameOf(checkedMonth as MonthNumber, checkedWidth(width));\n}\n\n/**\n * The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).\n *\n * @param isoWeekday - 1 (Alatsinainy) to 7 (Alahady).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The weekday name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getWeekdayName(1); // 'Alatsinainy'\n * getWeekdayName(7, 'abbreviated'); // 'Alah'\n * ```\n */\nexport function getWeekdayName(isoWeekday: number, width: NameWidth = 'wide'): string {\n const checkedWeekday = checkedNumber(isoWeekday, WEEKDAY_NAMES.length - 1, 'Weekday');\n return weekdayNameOf(checkedWeekday as IsoWeekday, checkedWidth(width));\n}\n","import { DEFAULT_STYLE, STYLE_PATTERNS, type DateStyle } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { isoWeekdayOf, toCalendarDate, type CalendarDate, type MonthNumber } from './calendar.ts';\nimport { monthNameOf, weekdayNameOf } from './names.ts';\n\ntype PatternToken = 'EEEE' | 'MMMM' | 'MMM' | 'MM' | 'dd' | 'd' | 'y';\n\n// CLDR pattern letters used by the spec styles; longest first so `MMMM` wins over `MM`.\nconst PATTERN_TOKEN = /EEEE|MMMM|MMM|MM|dd|d|y/g;\nconst TWO_DIGITS = 2;\n\nfunction twoDigits(value: number): string {\n return String(value).padStart(TWO_DIGITS, '0');\n}\n\nfunction render(pattern: string, date: CalendarDate): string {\n const month = date.month as MonthNumber;\n const values: Readonly<Record<PatternToken, string>> = {\n EEEE: weekdayNameOf(isoWeekdayOf(date), 'wide'),\n MMMM: monthNameOf(month, 'wide'),\n MMM: monthNameOf(month, 'abbreviated'),\n MM: twoDigits(date.month),\n dd: twoDigits(date.day),\n d: String(date.day),\n y: String(date.year),\n };\n return pattern.replace(PATTERN_TOKEN, (token) => values[token as PatternToken]);\n}\n\n/**\n * Writes a date in Malagasy.\n *\n * @param date - `YYYY-MM-DD` text, `{ year, month, day }`, or a `Date` (read in its local\n * calendar fields).\n * @param style - `long` (default), `full`, `medium`, `short` (CLDR) or `numeric` (`dd/MM/y`).\n * @returns The formatted date.\n * @throws {@link MdgError} `INVALID_FORMAT` for text that is not a real `YYYY-MM-DD` date,\n * `OUT_OF_RANGE` for impossible fields or years outside 1–9999, `INVALID_TYPE` for other\n * input or an unknown style.\n *\n * @example\n * ```ts\n * formatDate('2026-11-23'); // '23 Novambra 2026'\n * formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'\n * formatDate({ year: 1960, month: 6, day: 26 }, 'numeric'); // '26/06/1960'\n * ```\n */\nexport function formatDate(\n date: string | CalendarDate | Date,\n style: DateStyle = DEFAULT_STYLE,\n): string {\n const pattern = STYLE_PATTERNS.get(style);\n if (pattern === undefined) {\n throw new MdgError(\n 'INVALID_TYPE',\n `Style is one of: ${[...STYLE_PATTERNS.keys()].join(', ')}.`,\n );\n }\n return render(pattern, toCalendarDate(date));\n}\n"]}
1
+ {"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/calendar.ts","../src/names.ts","../src/format.ts"],"names":[],"mappings":";AAKO,IAAM,WAAA,GAAc;AAAA,EACzB,EAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,mBAAA,GAAsB;AAAA,EACjC,EAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,aAAA,GAAgB;AAAA,EAC3B,EAAA;AAAA,EACA,aAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,qBAAA,GAAwB;AAAA,EACnC,EAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AAMO,IAAM,cAAA,uBAAqD,GA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AAA;AAAA,MACR,cAAA;AAAA,MACA,CAAA,iBAAA,EAAoB,CAAC,GAAG,cAAA,CAAe,MAAM,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,OAAA,EAAS,cAAA,CAAe,IAAI,CAAC,CAAA;AAC7C","file":"index.js","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/date/data.yaml, spec 0.7.0.\n\n/** @internal Index = month number; index 0 is unused. */\nexport const MONTH_NAMES = [\n '',\n 'Janoary',\n 'Febroary',\n 'Martsa',\n 'Aprily',\n 'Mey',\n 'Jona',\n 'Jolay',\n 'Aogositra',\n 'Septambra',\n 'Oktobra',\n 'Novambra',\n 'Desambra',\n] as const;\n\n/** @internal Index = month number. */\nexport const MONTH_ABBREVIATIONS = [\n '',\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'Mey',\n 'Jon',\n 'Jol',\n 'Aog',\n 'Sep',\n 'Okt',\n 'Nov',\n 'Des',\n] as const;\n\n/** @internal Index = ISO weekday (Monday 1); index 0 is unused. */\nexport const WEEKDAY_NAMES = [\n '',\n 'Alatsinainy',\n 'Talata',\n 'Alarobia',\n 'Alakamisy',\n 'Zoma',\n 'Asabotsy',\n 'Alahady',\n] as const;\n\n/** @internal Index = ISO weekday. */\nexport const WEEKDAY_ABBREVIATIONS = [\n '',\n 'Alats',\n 'Tal',\n 'Alar',\n 'Alak',\n 'Zom',\n 'Asab',\n 'Alah',\n] as const;\n\n/** Date style for {@link formatDate}; `long` is the default. */\nexport type DateStyle = 'long' | 'full' | 'medium' | 'short' | 'numeric';\n\n/** @internal Style → CLDR pattern; the first entry is the default. */\nexport const STYLE_PATTERNS: ReadonlyMap<DateStyle, string> = new Map<DateStyle, string>([\n ['long', 'd MMMM y'],\n ['full', 'EEEE d MMMM y'],\n ['medium', 'y MMM d'],\n ['short', 'y-MM-dd'],\n ['numeric', 'dd/MM/y'],\n]);\n\n/** @internal */\nexport const DEFAULT_STYLE = 'long' as const;\n\n/** @internal */\nexport const MIN_YEAR = 1 as const;\n\n/** @internal */\nexport const MAX_YEAR = 9999 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.7.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MAX_YEAR, MIN_YEAR, WEEKDAY_NAMES } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * A calendar date: year 1–9999, month 1–12, day of the month.\n *\n * @example\n * ```ts\n * const independenceDay: CalendarDate = { year: 1960, month: 6, day: 26 };\n * ```\n */\nexport interface CalendarDate {\n /** Year, 1 to 9999. */\n readonly year: number;\n /** Month, 1 (Janoary) to 12 (Desambra). */\n readonly month: number;\n /** Day of the month, 1 to 31. */\n readonly day: number;\n}\n\n/** @internal ISO month number. */\nexport type MonthNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;\n/** @internal ISO weekday: Monday 1 … Sunday 7. */\nexport type IsoWeekday = 1 | 2 | 3 | 4 | 5 | 6 | 7;\n\nconst ISO_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DAYS_PER_WEEK = WEEKDAY_NAMES.length - 1;\n// JavaScript numbers Sunday 0; ISO 8601 numbers it 7.\nconst JAVASCRIPT_SUNDAY = 0;\n\n// A UTC date at midnight, so the calendar checks never depend on the local time zone.\nfunction utcDate({ year, month, day }: CalendarDate): Date {\n const date = new Date(0);\n date.setUTCFullYear(year, month - 1, day);\n return date;\n}\n\nfunction isRealDate(date: CalendarDate): boolean {\n const probe = utcDate(date);\n return (\n probe.getUTCFullYear() === date.year &&\n probe.getUTCMonth() === date.month - 1 &&\n probe.getUTCDate() === date.day\n );\n}\n\nfunction checked(\n date: CalendarDate,\n impossibleDateCode: 'INVALID_FORMAT' | 'OUT_OF_RANGE',\n): CalendarDate {\n if (date.year < MIN_YEAR || date.year > MAX_YEAR) {\n throw new MdgError('OUT_OF_RANGE', `Years go from ${String(MIN_YEAR)} to ${String(MAX_YEAR)}.`);\n }\n if (!isRealDate(date)) throw new MdgError(impossibleDateCode, 'This day does not exist.');\n return date;\n}\n\nfunction fromText(text: string): CalendarDate {\n const match = ISO_DATE.exec(text);\n if (match === null) throw new MdgError('INVALID_FORMAT', 'Expected a date as YYYY-MM-DD.');\n const [, year, month, day] = match;\n return checked({ year: Number(year), month: Number(month), day: Number(day) }, 'INVALID_FORMAT');\n}\n\nfunction fromFields(fields: object): CalendarDate {\n const { year, month, day } = fields as Partial<Record<keyof CalendarDate, unknown>>;\n if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) {\n throw new MdgError('INVALID_TYPE', 'Expected whole numbers for year, month and day.');\n }\n return checked({ year, month, day } as CalendarDate, 'OUT_OF_RANGE');\n}\n\nfunction fromDate(date: Date): CalendarDate {\n if (Number.isNaN(date.getTime())) throw new MdgError('INVALID_FORMAT', 'Invalid Date.');\n const fields = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };\n return checked(fields, 'OUT_OF_RANGE');\n}\n\n/**\n * @internal Reads any accepted date input at the public boundary.\n *\n * @param input - `YYYY-MM-DD` text, calendar fields or a `Date`.\n * @returns The validated calendar date.\n */\nexport function toCalendarDate(input: unknown): CalendarDate {\n if (typeof input === 'string') return fromText(input);\n if (input instanceof Date) return fromDate(input);\n if (typeof input === 'object' && input !== null) return fromFields(input);\n throw new MdgError('INVALID_TYPE', 'Expected YYYY-MM-DD text, { year, month, day } or a Date.');\n}\n\n/**\n * @internal ISO weekday of a valid calendar date.\n *\n * @param date - A date already checked by {@link toCalendarDate}.\n * @returns Monday 1 … Sunday 7.\n */\nexport function isoWeekdayOf(date: CalendarDate): IsoWeekday {\n const weekday = utcDate(date).getUTCDay();\n return (weekday === JAVASCRIPT_SUNDAY ? DAYS_PER_WEEK : weekday) as IsoWeekday;\n}\n","import {\n MONTH_ABBREVIATIONS,\n MONTH_NAMES,\n WEEKDAY_ABBREVIATIONS,\n WEEKDAY_NAMES,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport type { IsoWeekday, MonthNumber } from './calendar.ts';\n\n/**\n * Name width: `wide` (`Novambra`, default) or `abbreviated` (`Nov`).\n *\n * @example\n * ```ts\n * const width: NameWidth = 'abbreviated';\n * ```\n */\nexport type NameWidth = 'wide' | 'abbreviated';\n\nconst NAME_WIDTHS: ReadonlySet<unknown> = new Set<NameWidth>(['wide', 'abbreviated']);\n\nfunction checkedNumber(value: unknown, last: number, what: string): number {\n if (typeof value !== 'number' || !Number.isInteger(value)) {\n throw new MdgError('INVALID_TYPE', `Expected a whole ${what} number.`);\n }\n if (value < 1 || value > last) {\n throw new MdgError('OUT_OF_RANGE', `${what} numbers go from 1 to ${String(last)}.`);\n }\n return value;\n}\n\nfunction checkedWidth(width: unknown): NameWidth {\n if (!NAME_WIDTHS.has(width)) throw new MdgError('INVALID_TYPE', 'Width is wide or abbreviated.');\n return width as NameWidth;\n}\n\n/**\n * @internal Month name for a valid month number.\n *\n * @param month - Month 1–12.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy month name.\n */\nexport function monthNameOf(month: MonthNumber, width: NameWidth): string {\n return width === 'wide' ? MONTH_NAMES[month] : MONTH_ABBREVIATIONS[month];\n}\n\n/**\n * @internal Weekday name for a valid ISO weekday.\n *\n * @param weekday - Monday 1 … Sunday 7.\n * @param width - `wide` or `abbreviated`.\n * @returns The Malagasy weekday name.\n */\nexport function weekdayNameOf(weekday: IsoWeekday, width: NameWidth): string {\n return width === 'wide' ? WEEKDAY_NAMES[weekday] : WEEKDAY_ABBREVIATIONS[weekday];\n}\n\n/**\n * The Malagasy name of a month.\n *\n * @param month - Month number, 1 (Janoary) to 12 (Desambra).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The month name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getMonthName(6); // 'Jona'\n * getMonthName(11, 'abbreviated'); // 'Nov'\n * ```\n */\nexport function getMonthName(month: number, width: NameWidth = 'wide'): string {\n const checkedMonth = checkedNumber(month, MONTH_NAMES.length - 1, 'Month');\n return monthNameOf(checkedMonth as MonthNumber, checkedWidth(width));\n}\n\n/**\n * The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).\n *\n * @param isoWeekday - 1 (Alatsinainy) to 7 (Alahady).\n * @param width - `wide` (default) or `abbreviated`.\n * @returns The weekday name.\n * @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an\n * unknown width.\n *\n * @example\n * ```ts\n * getWeekdayName(1); // 'Alatsinainy'\n * getWeekdayName(7, 'abbreviated'); // 'Alah'\n * ```\n */\nexport function getWeekdayName(isoWeekday: number, width: NameWidth = 'wide'): string {\n const checkedWeekday = checkedNumber(isoWeekday, WEEKDAY_NAMES.length - 1, 'Weekday');\n return weekdayNameOf(checkedWeekday as IsoWeekday, checkedWidth(width));\n}\n","import { DEFAULT_STYLE, STYLE_PATTERNS, type DateStyle } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { isoWeekdayOf, toCalendarDate, type CalendarDate, type MonthNumber } from './calendar.ts';\nimport { monthNameOf, weekdayNameOf } from './names.ts';\n\ntype PatternToken = 'EEEE' | 'MMMM' | 'MMM' | 'MM' | 'dd' | 'd' | 'y';\n\n// CLDR pattern letters used by the spec styles; longest first so `MMMM` wins over `MM`.\nconst PATTERN_TOKEN = /EEEE|MMMM|MMM|MM|dd|d|y/g;\nconst TWO_DIGITS = 2;\n\nfunction twoDigits(value: number): string {\n return String(value).padStart(TWO_DIGITS, '0');\n}\n\nfunction render(pattern: string, date: CalendarDate): string {\n const month = date.month as MonthNumber;\n const values: Readonly<Record<PatternToken, string>> = {\n EEEE: weekdayNameOf(isoWeekdayOf(date), 'wide'),\n MMMM: monthNameOf(month, 'wide'),\n MMM: monthNameOf(month, 'abbreviated'),\n MM: twoDigits(date.month),\n dd: twoDigits(date.day),\n d: String(date.day),\n y: String(date.year),\n };\n return pattern.replace(PATTERN_TOKEN, (token) => values[token as PatternToken]);\n}\n\n/**\n * Writes a date in Malagasy.\n *\n * @param date - `YYYY-MM-DD` text, `{ year, month, day }`, or a `Date` (read in its local\n * calendar fields).\n * @param style - `long` (default), `full`, `medium`, `short` (CLDR) or `numeric` (`dd/MM/y`).\n * @returns The formatted date.\n * @throws {@link MdgError} `INVALID_FORMAT` for text that is not a real `YYYY-MM-DD` date,\n * `OUT_OF_RANGE` for impossible fields or years outside 1–9999, `INVALID_TYPE` for other\n * input or an unknown style.\n *\n * @example\n * ```ts\n * formatDate('2026-11-23'); // '23 Novambra 2026'\n * formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'\n * formatDate({ year: 1960, month: 6, day: 26 }, 'numeric'); // '26/06/1960'\n * ```\n */\nexport function formatDate(\n date: string | CalendarDate | Date,\n style: DateStyle = DEFAULT_STYLE,\n): string {\n const pattern = STYLE_PATTERNS.get(style);\n if (pattern === undefined) {\n throw new MdgError(\n 'INVALID_TYPE',\n `Style is one of: ${[...STYLE_PATTERNS.keys()].join(', ')}.`,\n );\n }\n return render(pattern, toCalendarDate(date));\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgascar/date",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Malagasy dates: 'Alatsinainy 23 Novambra 2026', month and weekday names, from CLDR.",
5
5
  "license": "MIT",
6
6
  "author": "Mdgascar contributors",