@mdgascar/date 0.9.0 → 0.11.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 +18 -3
- package/dist/index.cjs +267 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +186 -46
- package/dist/index.d.ts +186 -46
- package/dist/index.js +261 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.d.cts
CHANGED
|
@@ -38,59 +38,36 @@ type DateStyle = 'long' | 'full' | 'medium' | 'short' | 'numeric';
|
|
|
38
38
|
*/
|
|
39
39
|
declare function formatDate(date: string | CalendarDate | Date, style?: DateStyle): string;
|
|
40
40
|
|
|
41
|
+
/** Version of the shared spec this code was generated from. */
|
|
42
|
+
declare const SPEC_VERSION = "0.10.0";
|
|
41
43
|
/**
|
|
42
|
-
*
|
|
44
|
+
* Error code shared by every mdg-utils language port.
|
|
43
45
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).
|
|
47
|
+
* - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.
|
|
48
|
+
* - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).
|
|
49
|
+
* - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to an operator.
|
|
50
|
+
* - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.
|
|
51
|
+
* - `AMBIGUOUS`: The text reads as more than one value, so none is chosen.
|
|
48
52
|
*/
|
|
49
|
-
type
|
|
53
|
+
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS' | 'AMBIGUOUS';
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @param month - Month number, 1 (Janoary) to 12 (Desambra).
|
|
54
|
-
* @param width - `wide` (default) or `abbreviated`.
|
|
55
|
-
* @returns The month name.
|
|
56
|
-
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an
|
|
57
|
-
* unknown width.
|
|
55
|
+
* Outcome of a `safeParse…` function: the value, or the error that would have been thrown.
|
|
58
56
|
*
|
|
59
57
|
* @example
|
|
60
58
|
* ```ts
|
|
61
|
-
*
|
|
62
|
-
*
|
|
59
|
+
* const result = safeParsePhone(input);
|
|
60
|
+
* if (result.success) console.log(result.data);
|
|
61
|
+
* else console.log(result.error.code);
|
|
63
62
|
* ```
|
|
64
63
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an
|
|
73
|
-
* unknown width.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* weekdayName(1); // 'Alatsinainy'
|
|
78
|
-
* weekdayName(7, 'abbreviated'); // 'Alah'
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
declare function weekdayName(isoWeekday: number, width?: NameWidth): string;
|
|
82
|
-
|
|
83
|
-
/** Version of the shared spec this code was generated from. */
|
|
84
|
-
declare const SPEC_VERSION = "0.8.0";
|
|
85
|
-
/**
|
|
86
|
-
* Error code shared by every mdg-utils language port.
|
|
87
|
-
*
|
|
88
|
-
* - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).
|
|
89
|
-
* - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.
|
|
90
|
-
* - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).
|
|
91
|
-
* - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.
|
|
92
|
-
*/
|
|
93
|
-
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';
|
|
64
|
+
type SafeParseResult<T> = {
|
|
65
|
+
readonly success: true;
|
|
66
|
+
readonly data: T;
|
|
67
|
+
} | {
|
|
68
|
+
readonly success: false;
|
|
69
|
+
readonly error: MdgError;
|
|
70
|
+
};
|
|
94
71
|
/**
|
|
95
72
|
* Error thrown by mdg-utils functions. Check `code`, which is the same in every language.
|
|
96
73
|
*
|
|
@@ -129,5 +106,168 @@ declare class MdgError extends Error {
|
|
|
129
106
|
static [Symbol.hasInstance](value: unknown): boolean;
|
|
130
107
|
}
|
|
131
108
|
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Reads a Malagasy date without throwing.
|
|
111
|
+
*
|
|
112
|
+
* @param text - A date as {@link formatDate} writes it, in any style, any case and spacing.
|
|
113
|
+
* @param style - Optional: read only this style.
|
|
114
|
+
* @returns `{ success: true, data }` with the calendar date, or `{ success: false, error }`.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const result = safeParseDate('23 Novambra 2026');
|
|
119
|
+
* if (result.success) result.data; // { year: 2026, month: 11, day: 23 }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
declare function safeParseDate(text: unknown, style?: DateStyle): SafeParseResult<CalendarDate>;
|
|
123
|
+
/**
|
|
124
|
+
* Reads a Malagasy date back into calendar fields: the inverse of {@link formatDate}.
|
|
125
|
+
*
|
|
126
|
+
* @param text - A date in any style {@link formatDate} writes: `23 Novambra 2026`,
|
|
127
|
+
* `Alatsinainy 23 Novambra 2026`, `2026 Nov 23`, `2026-11-23` or `23/11/2026`. Case and
|
|
128
|
+
* spacing do not matter; day and month may have one digit.
|
|
129
|
+
* @param style - Optional: read only this style.
|
|
130
|
+
* @returns The calendar date.
|
|
131
|
+
* @throws {@link MdgError} `INVALID_TYPE` for non-strings or an unknown style,
|
|
132
|
+
* `INVALID_FORMAT` for text in no style, a day that does not exist or a wrong weekday,
|
|
133
|
+
* `OUT_OF_RANGE` for a year outside 1–9999, `AMBIGUOUS` when two styles read different dates
|
|
134
|
+
* (only for years up to 31, such as `5 Mey 12`; pass the style).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* parseDate('23 Novambra 2026'); // { year: 2026, month: 11, day: 23 }
|
|
139
|
+
* parseDate('23/11/2026'); // { year: 2026, month: 11, day: 23 }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function parseDate(text: string, style?: DateStyle): CalendarDate;
|
|
143
|
+
/**
|
|
144
|
+
* Reads a Malagasy date, or gives `undefined` instead of throwing.
|
|
145
|
+
*
|
|
146
|
+
* @param text - A date in any style {@link formatDate} writes.
|
|
147
|
+
* @param style - Optional: read only this style.
|
|
148
|
+
* @returns The calendar date, or `undefined` when {@link parseDate} would throw.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* tryParseDate('23/11/2026'); // { year: 2026, month: 11, day: 23 }
|
|
153
|
+
* tryParseDate('30/02/2026'); // undefined
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function tryParseDate(text: unknown, style?: DateStyle): CalendarDate | undefined;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A time of day: hour 0–23 and minute 0–59.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const time: ClockTime = { hour: 14, minute: 30 };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
interface ClockTime {
|
|
167
|
+
/** Hour, 0 to 23. */
|
|
168
|
+
readonly hour: number;
|
|
169
|
+
/** Minute, 0 to 59. */
|
|
170
|
+
readonly minute: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Says a time of day in Malagasy: `amin'ny`, the hour on a 12-hour clock, the minutes, then
|
|
174
|
+
* the part of the day.
|
|
175
|
+
*
|
|
176
|
+
* @param time - `HH:MM` text, `{ hour, minute }`, or a `Date` (read in its local time).
|
|
177
|
+
* @returns The time in words.
|
|
178
|
+
* @throws {@link MdgError} `INVALID_FORMAT` for text that is not `HH:MM`, `OUT_OF_RANGE` for an
|
|
179
|
+
* hour outside 0–23 or a minute outside 0–59, `INVALID_TYPE` for other input.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* spellTime('14:30'); // "amin'ny roa sy sasany tolakandro"
|
|
184
|
+
* spellTime('07:15'); // "amin'ny fito sy fahefany maraina"
|
|
185
|
+
* spellTime('17:45'); // "amin'ny enina latsaka fahefany hariva"
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function spellTime(time: string | ClockTime | Date): string;
|
|
189
|
+
/**
|
|
190
|
+
* Reads a time said in Malagasy without throwing.
|
|
191
|
+
*
|
|
192
|
+
* @param text - A time as {@link spellTime} says it.
|
|
193
|
+
* @returns `{ success: true, data }` with the time, or `{ success: false, error }`.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const result = safeParseTime("amin'ny roa sy sasany tolakandro");
|
|
198
|
+
* if (result.success) result.data; // { hour: 14, minute: 30 }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function safeParseTime(text: unknown): SafeParseResult<ClockTime>;
|
|
202
|
+
/**
|
|
203
|
+
* Reads a time said in Malagasy back into hour and minute: the inverse of {@link spellTime}.
|
|
204
|
+
*
|
|
205
|
+
* @param text - A time as {@link spellTime} says it, in any case and spacing, with or without
|
|
206
|
+
* `amin'ny`.
|
|
207
|
+
* @returns The time.
|
|
208
|
+
* @throws {@link MdgError} `INVALID_TYPE` for non-strings, `INVALID_FORMAT` for anything else.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* parseTime("amin'ny roa sy sasany tolakandro"); // { hour: 14, minute: 30 }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function parseTime(text: string): ClockTime;
|
|
216
|
+
/**
|
|
217
|
+
* Reads a time said in Malagasy, or gives `undefined` instead of throwing.
|
|
218
|
+
*
|
|
219
|
+
* @param text - A time as {@link spellTime} says it.
|
|
220
|
+
* @returns The time, or `undefined` when {@link parseTime} would throw.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* tryParseTime("amin'ny fito maraina"); // { hour: 7, minute: 0 }
|
|
225
|
+
* tryParseTime('seven'); // undefined
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function tryParseTime(text: unknown): ClockTime | undefined;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Name width: `wide` (`Novambra`, default) or `abbreviated` (`Nov`).
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const width: NameWidth = 'abbreviated';
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
type NameWidth = 'wide' | 'abbreviated';
|
|
239
|
+
/**
|
|
240
|
+
* The Malagasy name of a month.
|
|
241
|
+
*
|
|
242
|
+
* @param month - Month number, 1 (Janoary) to 12 (Desambra).
|
|
243
|
+
* @param width - `wide` (default) or `abbreviated`.
|
|
244
|
+
* @returns The month name.
|
|
245
|
+
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an
|
|
246
|
+
* unknown width.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* monthName(6); // 'Jona'
|
|
251
|
+
* monthName(11, 'abbreviated'); // 'Nov'
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
declare function monthName(month: number, width?: NameWidth): string;
|
|
255
|
+
/**
|
|
256
|
+
* The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).
|
|
257
|
+
*
|
|
258
|
+
* @param isoWeekday - 1 (Alatsinainy) to 7 (Alahady).
|
|
259
|
+
* @param width - `wide` (default) or `abbreviated`.
|
|
260
|
+
* @returns The weekday name.
|
|
261
|
+
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an
|
|
262
|
+
* unknown width.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* weekdayName(1); // 'Alatsinainy'
|
|
267
|
+
* weekdayName(7, 'abbreviated'); // 'Alah'
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
declare function weekdayName(isoWeekday: number, width?: NameWidth): string;
|
|
271
|
+
|
|
272
|
+
export { MdgError, SPEC_VERSION, formatDate, monthName, parseDate, parseTime, safeParseDate, safeParseTime, spellTime, tryParseDate, tryParseTime, weekdayName };
|
|
273
|
+
export type { CalendarDate, ClockTime, DateStyle, ErrorCode, NameWidth, SafeParseResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -38,59 +38,36 @@ type DateStyle = 'long' | 'full' | 'medium' | 'short' | 'numeric';
|
|
|
38
38
|
*/
|
|
39
39
|
declare function formatDate(date: string | CalendarDate | Date, style?: DateStyle): string;
|
|
40
40
|
|
|
41
|
+
/** Version of the shared spec this code was generated from. */
|
|
42
|
+
declare const SPEC_VERSION = "0.10.0";
|
|
41
43
|
/**
|
|
42
|
-
*
|
|
44
|
+
* Error code shared by every mdg-utils language port.
|
|
43
45
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).
|
|
47
|
+
* - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.
|
|
48
|
+
* - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).
|
|
49
|
+
* - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to an operator.
|
|
50
|
+
* - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.
|
|
51
|
+
* - `AMBIGUOUS`: The text reads as more than one value, so none is chosen.
|
|
48
52
|
*/
|
|
49
|
-
type
|
|
53
|
+
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS' | 'AMBIGUOUS';
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @param month - Month number, 1 (Janoary) to 12 (Desambra).
|
|
54
|
-
* @param width - `wide` (default) or `abbreviated`.
|
|
55
|
-
* @returns The month name.
|
|
56
|
-
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an
|
|
57
|
-
* unknown width.
|
|
55
|
+
* Outcome of a `safeParse…` function: the value, or the error that would have been thrown.
|
|
58
56
|
*
|
|
59
57
|
* @example
|
|
60
58
|
* ```ts
|
|
61
|
-
*
|
|
62
|
-
*
|
|
59
|
+
* const result = safeParsePhone(input);
|
|
60
|
+
* if (result.success) console.log(result.data);
|
|
61
|
+
* else console.log(result.error.code);
|
|
63
62
|
* ```
|
|
64
63
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an
|
|
73
|
-
* unknown width.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* weekdayName(1); // 'Alatsinainy'
|
|
78
|
-
* weekdayName(7, 'abbreviated'); // 'Alah'
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
declare function weekdayName(isoWeekday: number, width?: NameWidth): string;
|
|
82
|
-
|
|
83
|
-
/** Version of the shared spec this code was generated from. */
|
|
84
|
-
declare const SPEC_VERSION = "0.8.0";
|
|
85
|
-
/**
|
|
86
|
-
* Error code shared by every mdg-utils language port.
|
|
87
|
-
*
|
|
88
|
-
* - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).
|
|
89
|
-
* - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.
|
|
90
|
-
* - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).
|
|
91
|
-
* - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.
|
|
92
|
-
*/
|
|
93
|
-
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';
|
|
64
|
+
type SafeParseResult<T> = {
|
|
65
|
+
readonly success: true;
|
|
66
|
+
readonly data: T;
|
|
67
|
+
} | {
|
|
68
|
+
readonly success: false;
|
|
69
|
+
readonly error: MdgError;
|
|
70
|
+
};
|
|
94
71
|
/**
|
|
95
72
|
* Error thrown by mdg-utils functions. Check `code`, which is the same in every language.
|
|
96
73
|
*
|
|
@@ -129,5 +106,168 @@ declare class MdgError extends Error {
|
|
|
129
106
|
static [Symbol.hasInstance](value: unknown): boolean;
|
|
130
107
|
}
|
|
131
108
|
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Reads a Malagasy date without throwing.
|
|
111
|
+
*
|
|
112
|
+
* @param text - A date as {@link formatDate} writes it, in any style, any case and spacing.
|
|
113
|
+
* @param style - Optional: read only this style.
|
|
114
|
+
* @returns `{ success: true, data }` with the calendar date, or `{ success: false, error }`.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const result = safeParseDate('23 Novambra 2026');
|
|
119
|
+
* if (result.success) result.data; // { year: 2026, month: 11, day: 23 }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
declare function safeParseDate(text: unknown, style?: DateStyle): SafeParseResult<CalendarDate>;
|
|
123
|
+
/**
|
|
124
|
+
* Reads a Malagasy date back into calendar fields: the inverse of {@link formatDate}.
|
|
125
|
+
*
|
|
126
|
+
* @param text - A date in any style {@link formatDate} writes: `23 Novambra 2026`,
|
|
127
|
+
* `Alatsinainy 23 Novambra 2026`, `2026 Nov 23`, `2026-11-23` or `23/11/2026`. Case and
|
|
128
|
+
* spacing do not matter; day and month may have one digit.
|
|
129
|
+
* @param style - Optional: read only this style.
|
|
130
|
+
* @returns The calendar date.
|
|
131
|
+
* @throws {@link MdgError} `INVALID_TYPE` for non-strings or an unknown style,
|
|
132
|
+
* `INVALID_FORMAT` for text in no style, a day that does not exist or a wrong weekday,
|
|
133
|
+
* `OUT_OF_RANGE` for a year outside 1–9999, `AMBIGUOUS` when two styles read different dates
|
|
134
|
+
* (only for years up to 31, such as `5 Mey 12`; pass the style).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* parseDate('23 Novambra 2026'); // { year: 2026, month: 11, day: 23 }
|
|
139
|
+
* parseDate('23/11/2026'); // { year: 2026, month: 11, day: 23 }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function parseDate(text: string, style?: DateStyle): CalendarDate;
|
|
143
|
+
/**
|
|
144
|
+
* Reads a Malagasy date, or gives `undefined` instead of throwing.
|
|
145
|
+
*
|
|
146
|
+
* @param text - A date in any style {@link formatDate} writes.
|
|
147
|
+
* @param style - Optional: read only this style.
|
|
148
|
+
* @returns The calendar date, or `undefined` when {@link parseDate} would throw.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* tryParseDate('23/11/2026'); // { year: 2026, month: 11, day: 23 }
|
|
153
|
+
* tryParseDate('30/02/2026'); // undefined
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function tryParseDate(text: unknown, style?: DateStyle): CalendarDate | undefined;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A time of day: hour 0–23 and minute 0–59.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const time: ClockTime = { hour: 14, minute: 30 };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
interface ClockTime {
|
|
167
|
+
/** Hour, 0 to 23. */
|
|
168
|
+
readonly hour: number;
|
|
169
|
+
/** Minute, 0 to 59. */
|
|
170
|
+
readonly minute: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Says a time of day in Malagasy: `amin'ny`, the hour on a 12-hour clock, the minutes, then
|
|
174
|
+
* the part of the day.
|
|
175
|
+
*
|
|
176
|
+
* @param time - `HH:MM` text, `{ hour, minute }`, or a `Date` (read in its local time).
|
|
177
|
+
* @returns The time in words.
|
|
178
|
+
* @throws {@link MdgError} `INVALID_FORMAT` for text that is not `HH:MM`, `OUT_OF_RANGE` for an
|
|
179
|
+
* hour outside 0–23 or a minute outside 0–59, `INVALID_TYPE` for other input.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* spellTime('14:30'); // "amin'ny roa sy sasany tolakandro"
|
|
184
|
+
* spellTime('07:15'); // "amin'ny fito sy fahefany maraina"
|
|
185
|
+
* spellTime('17:45'); // "amin'ny enina latsaka fahefany hariva"
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function spellTime(time: string | ClockTime | Date): string;
|
|
189
|
+
/**
|
|
190
|
+
* Reads a time said in Malagasy without throwing.
|
|
191
|
+
*
|
|
192
|
+
* @param text - A time as {@link spellTime} says it.
|
|
193
|
+
* @returns `{ success: true, data }` with the time, or `{ success: false, error }`.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const result = safeParseTime("amin'ny roa sy sasany tolakandro");
|
|
198
|
+
* if (result.success) result.data; // { hour: 14, minute: 30 }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function safeParseTime(text: unknown): SafeParseResult<ClockTime>;
|
|
202
|
+
/**
|
|
203
|
+
* Reads a time said in Malagasy back into hour and minute: the inverse of {@link spellTime}.
|
|
204
|
+
*
|
|
205
|
+
* @param text - A time as {@link spellTime} says it, in any case and spacing, with or without
|
|
206
|
+
* `amin'ny`.
|
|
207
|
+
* @returns The time.
|
|
208
|
+
* @throws {@link MdgError} `INVALID_TYPE` for non-strings, `INVALID_FORMAT` for anything else.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* parseTime("amin'ny roa sy sasany tolakandro"); // { hour: 14, minute: 30 }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function parseTime(text: string): ClockTime;
|
|
216
|
+
/**
|
|
217
|
+
* Reads a time said in Malagasy, or gives `undefined` instead of throwing.
|
|
218
|
+
*
|
|
219
|
+
* @param text - A time as {@link spellTime} says it.
|
|
220
|
+
* @returns The time, or `undefined` when {@link parseTime} would throw.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* tryParseTime("amin'ny fito maraina"); // { hour: 7, minute: 0 }
|
|
225
|
+
* tryParseTime('seven'); // undefined
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function tryParseTime(text: unknown): ClockTime | undefined;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Name width: `wide` (`Novambra`, default) or `abbreviated` (`Nov`).
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const width: NameWidth = 'abbreviated';
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
type NameWidth = 'wide' | 'abbreviated';
|
|
239
|
+
/**
|
|
240
|
+
* The Malagasy name of a month.
|
|
241
|
+
*
|
|
242
|
+
* @param month - Month number, 1 (Janoary) to 12 (Desambra).
|
|
243
|
+
* @param width - `wide` (default) or `abbreviated`.
|
|
244
|
+
* @returns The month name.
|
|
245
|
+
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–12, `INVALID_TYPE` for non-integers or an
|
|
246
|
+
* unknown width.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* monthName(6); // 'Jona'
|
|
251
|
+
* monthName(11, 'abbreviated'); // 'Nov'
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
declare function monthName(month: number, width?: NameWidth): string;
|
|
255
|
+
/**
|
|
256
|
+
* The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).
|
|
257
|
+
*
|
|
258
|
+
* @param isoWeekday - 1 (Alatsinainy) to 7 (Alahady).
|
|
259
|
+
* @param width - `wide` (default) or `abbreviated`.
|
|
260
|
+
* @returns The weekday name.
|
|
261
|
+
* @throws {@link MdgError} `OUT_OF_RANGE` outside 1–7, `INVALID_TYPE` for non-integers or an
|
|
262
|
+
* unknown width.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* weekdayName(1); // 'Alatsinainy'
|
|
267
|
+
* weekdayName(7, 'abbreviated'); // 'Alah'
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
declare function weekdayName(isoWeekday: number, width?: NameWidth): string;
|
|
271
|
+
|
|
272
|
+
export { MdgError, SPEC_VERSION, formatDate, monthName, parseDate, parseTime, safeParseDate, safeParseTime, spellTime, tryParseDate, tryParseTime, weekdayName };
|
|
273
|
+
export type { CalendarDate, ClockTime, DateStyle, ErrorCode, NameWidth, SafeParseResult };
|