@heroiclands/package-build 22.8.0 → 22.9.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.
@@ -36,22 +36,87 @@ export function canonicalYear(year: number, epoch?: number): number;
36
36
  */
37
37
  export function dateSortKey(year: number, month: number | null, day: number | null): number;
38
38
  /**
39
- * The bounds a package states for a month, or `null` where it states none.
39
+ * One month of a calendar, as the note declares it.
40
40
  *
41
- * Separate from the check that reads it so a caller can ask what a package
42
- * declares without phrasing a finding about it.
41
+ * @typedef {object} CalendarMonth
42
+ * @property {string} name - What the month is called.
43
+ * @property {string} [abbreviation] - A short form, where the note gives one.
44
+ * @property {number} days - How many days it holds.
45
+ */
46
+ /**
47
+ * The months a calendar keeps, or `null` where it declares none.
43
48
  *
44
- * @param {{months?: number|null, monthDays?: number|null}} [calendar] - The
45
- * resolved `calendar:` block.
46
- * @returns {{months: number|null, monthDays: number|null}} What it declares.
49
+ * Separate from the check that reads it so a caller can ask what a calendar
50
+ * divides its year into without phrasing a finding about it. An empty list
51
+ * reads as no list: a calendar that declares nothing and one that declares
52
+ * nothing in a pair of brackets divide the year identically.
53
+ *
54
+ * @param {{months?: readonly CalendarMonth[]|null}} [calendar] - The calendar
55
+ * the date is written in, as its note declares it.
56
+ * @returns {{months: readonly CalendarMonth[]|null}} What it divides the year
57
+ * into.
47
58
  */
48
59
  export function calendarStructure(calendar?: {
49
- months?: number | null;
50
- monthDays?: number | null;
60
+ months?: readonly CalendarMonth[] | null;
51
61
  }): {
52
- months: number | null;
53
- monthDays: number | null;
62
+ months: readonly CalendarMonth[] | null;
54
63
  };
64
+ /**
65
+ * How long one month of a calendar is, or `null` where the calendar is silent.
66
+ *
67
+ * @param {{months?: readonly CalendarMonth[]|null}} [calendar] - The calendar.
68
+ * @param {number} month - The month, numbered from 1.
69
+ * @returns {number|null} Its length in days, or `null`.
70
+ */
71
+ export function daysInMonth(calendar?: {
72
+ months?: readonly CalendarMonth[] | null;
73
+ }, month: number): number | null;
74
+ /**
75
+ * How many days the months add up to.
76
+ *
77
+ * The number a calendar's list claims the year is. Whether that is the year the
78
+ * world keeps is a question about the world, and is asked elsewhere.
79
+ *
80
+ * @param {readonly CalendarMonth[]} months - The ordered month list.
81
+ * @returns {number} The sum of their day counts.
82
+ */
83
+ export function daysInYear(months: readonly CalendarMonth[]): number;
84
+ /**
85
+ * The day of the year each month opens on, in order, numbered from 1.
86
+ *
87
+ * The sum read as a sequence rather than as a total. Two lists holding the same
88
+ * numbers in a different order sum alike and open their months on different
89
+ * days, which is the error a total cannot see.
90
+ *
91
+ * @param {readonly CalendarMonth[]} months - The ordered month list.
92
+ * @returns {number[]} One entry per month: the day of the year it begins on.
93
+ */
94
+ export function monthStarts(months: readonly CalendarMonth[]): number[];
95
+ /**
96
+ * Which day of the year a written month and day land on, numbered from 1.
97
+ *
98
+ * @param {readonly CalendarMonth[]} months - The ordered month list.
99
+ * @param {number} month - The month, numbered from 1.
100
+ * @param {number} day - The day within it, numbered from 1.
101
+ * @returns {number} The day of the year.
102
+ */
103
+ export function dayOfYear(months: readonly CalendarMonth[], month: number, day: number): number;
104
+ /**
105
+ * How far into its cycle a moon is on a given day.
106
+ *
107
+ * **Floored, not truncated.** JavaScript's `%` takes the dividend's sign, so a
108
+ * day seven before the epoch yields `-7` where the phase is 23 — a value that
109
+ * is right on one side of the epoch and wrong on the other, which is invisible
110
+ * in any list that does not span it.
111
+ *
112
+ * @param {number} dayNumber - The day, on whatever continuous day count the
113
+ * caller keeps.
114
+ * @param {number} epochDay - The day of that same count on which the moon was
115
+ * new.
116
+ * @param {number} cycle - The cycle's length in days.
117
+ * @returns {number} Days into the cycle, `0` to `cycle - 1`.
118
+ */
119
+ export function lunarPhase(dayNumber: number, epochDay: number, cycle: number): number;
55
120
  /**
56
121
  * **The axis every date normalises onto, and the one function that puts a
57
122
  * reckoning on it.**
@@ -93,14 +158,23 @@ export function calendarStructure(calendar?: {
93
158
  * and off by one on the other, which is invisible in any list that does not
94
159
  * span it.
95
160
  *
96
- * ## The month structure is the package's, and an absent bound checks nothing
161
+ * ## The month structure is the calendar's, and an absent list bounds nothing
97
162
  *
98
- * An era moves where year 1 sits; it does not divide the year differently. So
99
- * the subdivision is declared once for the package, in `calendar.months` and
100
- * `calendar.monthDays`, and a package that declares neither is bounded below
101
- * and not above — a toolchain that invented twelve Gregorian months would
102
- * refuse `667/2/30`, which is an ordinary date in a year of twelve thirty-day
103
- * months.
163
+ * An era moves where year 1 sits; it does not divide the year differently. The
164
+ * division belongs to the calendar, which is a note declaring an **ordered
165
+ * list** of months, each with a name and a day count. Position in the list is
166
+ * position in the year, so a five-day month sits wherever its people put it and
167
+ * needs no rule of its own.
168
+ *
169
+ * A date is bounded by the calendar it is written in, and a calendar whose list
170
+ * nobody has written down bounds nothing — a toolchain that invented twelve
171
+ * Gregorian months would refuse `667/2/30`, an ordinary date in a year of
172
+ * twelve thirty-day months.
173
+ *
174
+ * ## The lunar phase takes a floored modulo, not JavaScript's
175
+ *
176
+ * `%` takes the dividend's sign, so a day before the epoch yields `-7` where
177
+ * the phase is 23. {@link lunarPhase} is the one place that is written.
104
178
  *
105
179
  * @module
106
180
  */
@@ -113,3 +187,20 @@ export function calendarStructure(calendar?: {
113
187
  * @type {number}
114
188
  */
115
189
  export const CANONICAL_EPOCH: number;
190
+ /**
191
+ * One month of a calendar, as the note declares it.
192
+ */
193
+ export type CalendarMonth = {
194
+ /**
195
+ * - What the month is called.
196
+ */
197
+ name: string;
198
+ /**
199
+ * - A short form, where the note gives one.
200
+ */
201
+ abbreviation?: string | undefined;
202
+ /**
203
+ * - How many days it holds.
204
+ */
205
+ days: number;
206
+ };
@@ -31,6 +31,7 @@ export * as siteMaps from "./site-maps.mjs";
31
31
  export * as systems from "./systems.mjs";
32
32
  export * as calendars from "./calendars.mjs";
33
33
  export * as noteDates from "./note-dates.mjs";
34
+ export * as calendarNotes from "./calendar-notes.mjs";
34
35
  export * as contentSlug from "./content-slug.mjs";
35
36
  export * as contentAddress from "./content-address.mjs";
36
37
  export * as subtypeRegistry from "./subtype-registry.mjs";
@@ -14,9 +14,10 @@
14
14
  * @param {unknown} value - The authored value. A number is what YAML hands
15
15
  * back for a bare year, so it is accepted and stringified.
16
16
  * @param {object} [options]
17
- * @param {{months?: number|null, monthDays?: number|null}} [options.calendar]
18
- * The resolved `calendar:` block, whose `months` and `monthDays` bound a
19
- * written month and day. An absent bound is not applied.
17
+ * @param {{months?: readonly object[]|null}} [options.calendar] - The calendar
18
+ * the value is written in, as its note declares it. Its ordered month list
19
+ * bounds a written month and a written day, the day against the length of
20
+ * the month it names. A calendar that declares no list bounds nothing.
20
21
  * @param {string} [options.field] - The key that carried it, named in every
21
22
  * message. Omitted, a message names the value alone.
22
23
  * @param {boolean} [options.allowUnknown=true] - Whether `"unknown"` is a
@@ -31,8 +32,7 @@
31
32
  */
32
33
  export function parseNoteDate(value: unknown, options?: {
33
34
  calendar?: {
34
- months?: number | null;
35
- monthDays?: number | null;
35
+ months?: readonly object[] | null;
36
36
  } | undefined;
37
37
  field?: string | undefined;
38
38
  allowUnknown?: boolean | undefined;
@@ -52,7 +52,7 @@ export const UNKNOWN_DATE: string;
52
52
  /**
53
53
  * What a date's trailing token may look like.
54
54
  *
55
- * An affiliation's address followed by `.<era shortcode>`. The `{0,3}`
55
+ * A calendar note's address followed by `.<era shortcode>`. The `{0,3}`
56
56
  * repetition is the four address forms exactly — bare `shortcode`,
57
57
  * `type-shortcode`, `system-type-shortcode` and
58
58
  * `package-system-type-shortcode` — so the hyphen separates an address's