saykit 0.6.1 → 0.7.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/dist/runtime.d.mts +74 -2
- package/dist/runtime.mjs +56 -0
- package/package.json +1 -1
package/dist/runtime.d.mts
CHANGED
|
@@ -14,11 +14,33 @@ type Named<T> = {
|
|
|
14
14
|
interface NumeralOptions extends Omit<Partial<Record<Intl.LDMLPluralRule, string>>, 'other'> {
|
|
15
15
|
other: string;
|
|
16
16
|
[digit: number]: string;
|
|
17
|
+
/**
|
|
18
|
+
* Subtracted from the value before `#` is formatted, so "You and 2 others"
|
|
19
|
+
* can select on a total of three. Reserved — it never names a branch.
|
|
20
|
+
*/
|
|
21
|
+
offset?: number;
|
|
17
22
|
}
|
|
18
23
|
interface SelectOptions {
|
|
19
24
|
other: string;
|
|
20
25
|
[match: string | number]: string;
|
|
21
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Formatting for a `{arg, number}` placeholder.
|
|
29
|
+
*
|
|
30
|
+
* `currency` is not offered: MF1 has nowhere to write the currency code, so
|
|
31
|
+
* `{price, number, currency}` formats as a literal `{$price}` rather than an
|
|
32
|
+
* amount. A literal pattern such as `#,##0.00` is accepted for the cases the
|
|
33
|
+
* named styles do not cover.
|
|
34
|
+
*/
|
|
35
|
+
interface NumberOptions {
|
|
36
|
+
style?: 'integer' | 'percent' | (string & {});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Formatting for a `{arg, date}` or `{arg, time}` placeholder.
|
|
40
|
+
*/
|
|
41
|
+
interface DateTimeOptions {
|
|
42
|
+
style?: 'short' | 'medium' | 'long' | 'full';
|
|
43
|
+
}
|
|
22
44
|
//#endregion
|
|
23
45
|
//#region src/runtime.d.ts
|
|
24
46
|
declare namespace Say {
|
|
@@ -214,7 +236,57 @@ declare class Say<Locale extends string = string, Loader extends Say.Loader<Loca
|
|
|
214
236
|
* @returns The select form of the value
|
|
215
237
|
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
216
238
|
*/
|
|
217
|
-
select(_: string | Named<string>, options: Disallow<SelectOptions, 'id' | 'context'>): string;
|
|
239
|
+
select(_: string | number | Named<string | number>, options: Disallow<SelectOptions, 'id' | 'context'>): string;
|
|
240
|
+
/**
|
|
241
|
+
* Format a number the way the active locale writes one, with its own grouping
|
|
242
|
+
* separators and decimal mark.
|
|
243
|
+
*
|
|
244
|
+
* Unlike `plural`, `ordinal`, and `select`, this is a fragment rather than a
|
|
245
|
+
* whole message, and is normally written inside one.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* say`You have ${say.number(items.length)} items`
|
|
250
|
+
* say`Battery at ${say.number(level, { style: 'percent' })}`
|
|
251
|
+
* say`Total: ${say.number({ cartTotal: getTotal() }, { style: '#,##0.00' })}`
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @param _ Number to format
|
|
255
|
+
* @param options Formatting style, either a named style or a literal number pattern
|
|
256
|
+
* @returns The formatted number
|
|
257
|
+
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
258
|
+
*/
|
|
259
|
+
number(_: number | Named<number>, options?: Disallow<NumberOptions, 'id' | 'context'>): string;
|
|
260
|
+
/**
|
|
261
|
+
* Format the date portion of a value the way the active locale writes one.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* say`Published ${say.date(post.publishedAt)}`
|
|
266
|
+
* say`Published ${say.date(post.publishedAt, { style: 'full' })}`
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* @param _ Date to format
|
|
270
|
+
* @param options Formatting style
|
|
271
|
+
* @returns The formatted date
|
|
272
|
+
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
273
|
+
*/
|
|
274
|
+
date(_: Date | number | Named<Date | number>, options?: Disallow<DateTimeOptions, 'id' | 'context'>): string;
|
|
275
|
+
/**
|
|
276
|
+
* Format the time portion of a value the way the active locale writes one.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* say`Doors open at ${say.time(opensAt)}`
|
|
281
|
+
* say`Doors open at ${say.time(opensAt, { style: 'short' })}`
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @param _ Date to format
|
|
285
|
+
* @param options Formatting style
|
|
286
|
+
* @returns The formatted time
|
|
287
|
+
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
288
|
+
*/
|
|
289
|
+
time(_: Date | number | Named<Date | number>, options?: Disallow<DateTimeOptions, 'id' | 'context'>): string;
|
|
218
290
|
}
|
|
219
291
|
//#endregion
|
|
220
|
-
export { Awaitable, Disallow, Named, NumeralOptions, ReadonlySay, Say, SelectOptions, Tuple };
|
|
292
|
+
export { Awaitable, DateTimeOptions, Disallow, Named, NumberOptions, NumeralOptions, ReadonlySay, Say, SelectOptions, Tuple };
|
package/dist/runtime.mjs
CHANGED
|
@@ -258,6 +258,62 @@ var Say = class Say {
|
|
|
258
258
|
select(_, options) {
|
|
259
259
|
throw new Error("'Say#select' is a macro and must be used with the relevant saykit plugin");
|
|
260
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Format a number the way the active locale writes one, with its own grouping
|
|
263
|
+
* separators and decimal mark.
|
|
264
|
+
*
|
|
265
|
+
* Unlike `plural`, `ordinal`, and `select`, this is a fragment rather than a
|
|
266
|
+
* whole message, and is normally written inside one.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* say`You have ${say.number(items.length)} items`
|
|
271
|
+
* say`Battery at ${say.number(level, { style: 'percent' })}`
|
|
272
|
+
* say`Total: ${say.number({ cartTotal: getTotal() }, { style: '#,##0.00' })}`
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @param _ Number to format
|
|
276
|
+
* @param options Formatting style, either a named style or a literal number pattern
|
|
277
|
+
* @returns The formatted number
|
|
278
|
+
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
279
|
+
*/
|
|
280
|
+
number(_, options) {
|
|
281
|
+
throw new Error("'Say#number' is a macro and must be used with the relevant saykit plugin");
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Format the date portion of a value the way the active locale writes one.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* say`Published ${say.date(post.publishedAt)}`
|
|
289
|
+
* say`Published ${say.date(post.publishedAt, { style: 'full' })}`
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* @param _ Date to format
|
|
293
|
+
* @param options Formatting style
|
|
294
|
+
* @returns The formatted date
|
|
295
|
+
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
296
|
+
*/
|
|
297
|
+
date(_, options) {
|
|
298
|
+
throw new Error("'Say#date' is a macro and must be used with the relevant saykit plugin");
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Format the time portion of a value the way the active locale writes one.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* say`Doors open at ${say.time(opensAt)}`
|
|
306
|
+
* say`Doors open at ${say.time(opensAt, { style: 'short' })}`
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* @param _ Date to format
|
|
310
|
+
* @param options Formatting style
|
|
311
|
+
* @returns The formatted time
|
|
312
|
+
* @remark This is a macro and must be used with the relevant saykit plugin
|
|
313
|
+
*/
|
|
314
|
+
time(_, options) {
|
|
315
|
+
throw new Error("'Say#time' is a macro and must be used with the relevant saykit plugin");
|
|
316
|
+
}
|
|
261
317
|
};
|
|
262
318
|
function _call(locale, messages, descriptor) {
|
|
263
319
|
const message = messages[descriptor.id];
|