saykit 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
@@ -31,7 +31,7 @@ const say = new Say({
31
31
  say.activate('en');
32
32
 
33
33
  say`Hello, ${name}!`;
34
- say.plural(count, { one: '1 item', other: '# items' });
34
+ say.plural(count, { one: '1 item', other: `${count} items` });
35
35
  ```
36
36
 
37
37
  ## Documentation
@@ -11,18 +11,25 @@ type Awaitable<T> = T | PromiseLike<T>;
11
11
  type Named<T> = {
12
12
  [name: string]: T;
13
13
  };
14
- interface NumeralOptions extends Omit<Partial<Record<Intl.LDMLPluralRule, string>>, 'other'> {
15
- other: string;
16
- [digit: number]: string;
14
+ /**
15
+ * Branches of a choice, keyed by CLDR category or by exact number.
16
+ *
17
+ * `Branch` is what a case may be written as. It is text everywhere the message
18
+ * is text, and widens in JSX, where a case that shows the number has to be a
19
+ * fragment — a string attribute has nowhere to put a value.
20
+ */
21
+ interface NumeralOptions<Branch = string> extends Omit<Partial<Record<Intl.LDMLPluralRule, Branch>>, 'other'> {
22
+ other: Branch;
23
+ [digit: number]: Branch;
17
24
  /**
18
25
  * Subtracted from the value before `#` is formatted, so "You and 2 others"
19
26
  * can select on a total of three. Reserved — it never names a branch.
20
27
  */
21
28
  offset?: number;
22
29
  }
23
- interface SelectOptions {
24
- other: string;
25
- [match: string | number]: string;
30
+ interface SelectOptions<Branch = string> {
31
+ other: Branch;
32
+ [match: string | number]: Branch;
26
33
  }
27
34
  /**
28
35
  * Formatting for a `{arg, number}` placeholder.
@@ -188,11 +195,12 @@ declare class Say<Locale extends string = string, Loader extends Say.Loader<Loca
188
195
  * ```ts
189
196
  * say.plural(count, {
190
197
  * one: 'You have 1 item',
191
- * other: 'You have # items',
198
+ * other: `You have ${count} items`,
192
199
  * })
193
200
  * ```
194
201
  *
195
- * The `#` symbol inside options is replaced with the numeric value.
202
+ * Interpolating the selector into a branch extracts as ICU's `#`, the number
203
+ * the message branched on. A `#` you write yourself is text.
196
204
  * @param _ Number to determine the plural form of
197
205
  * @param options Pluralisation rules keyed by CLDR categories or specific numbers
198
206
  * @returns The plural form of the number
@@ -201,15 +209,17 @@ declare class Say<Locale extends string = string, Loader extends Say.Loader<Loca
201
209
  plural(_: number | Named<number>, options: Disallow<NumeralOptions, 'id' | 'context'>): string;
202
210
  /**
203
211
  * Define an ordinal message (e.g. "1st", "2nd", "3rd").
204
- * The `#` symbol inside options is replaced with the numeric value.
212
+ *
213
+ * Interpolating the selector into a branch extracts as ICU's `#`, the number
214
+ * the message branched on. A `#` you write yourself is text.
205
215
  *
206
216
  * @example
207
217
  * ```ts
208
218
  * say.ordinal(position, {
209
- * 1: '#st',
210
- * 2: '#nd',
211
- * 3: '#rd',
212
- * other: '#th',
219
+ * 1: `${position}st`,
220
+ * 2: `${position}nd`,
221
+ * 3: `${position}rd`,
222
+ * other: `${position}th`,
213
223
  * })
214
224
  * ```
215
225
  *
package/dist/runtime.mjs CHANGED
@@ -203,11 +203,12 @@ var Say = class Say {
203
203
  * ```ts
204
204
  * say.plural(count, {
205
205
  * one: 'You have 1 item',
206
- * other: 'You have # items',
206
+ * other: `You have ${count} items`,
207
207
  * })
208
208
  * ```
209
209
  *
210
- * The `#` symbol inside options is replaced with the numeric value.
210
+ * Interpolating the selector into a branch extracts as ICU's `#`, the number
211
+ * the message branched on. A `#` you write yourself is text.
211
212
  * @param _ Number to determine the plural form of
212
213
  * @param options Pluralisation rules keyed by CLDR categories or specific numbers
213
214
  * @returns The plural form of the number
@@ -218,15 +219,17 @@ var Say = class Say {
218
219
  }
219
220
  /**
220
221
  * Define an ordinal message (e.g. "1st", "2nd", "3rd").
221
- * The `#` symbol inside options is replaced with the numeric value.
222
+ *
223
+ * Interpolating the selector into a branch extracts as ICU's `#`, the number
224
+ * the message branched on. A `#` you write yourself is text.
222
225
  *
223
226
  * @example
224
227
  * ```ts
225
228
  * say.ordinal(position, {
226
- * 1: '#st',
227
- * 2: '#nd',
228
- * 3: '#rd',
229
- * other: '#th',
229
+ * 1: `${position}st`,
230
+ * 2: `${position}nd`,
231
+ * 3: `${position}rd`,
232
+ * other: `${position}th`,
230
233
  * })
231
234
  * ```
232
235
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saykit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Type-safe i18n library with compile-time macro transforms",
5
5
  "keywords": [
6
6
  "i18n",