@@ -3,37 +3,46 @@ import { pluralize } from './pluralize';
33/**
44 * Formats a number with a unit, automatically pluralizing the unit based on the count.
55 *
6- * If the `count` is exactly 1, the singular `unit` is used. Otherwise, it either uses
7- * the provided `plural` form or calls `pluralize(unit)` to generate one.
6+ * If the `<property>count` is exactly 1, the singular `<property>unit` is used.
7+ * Otherwise, it either uses the provided `<property>plural` form or calls
8+ * <code><reference>pluralize</reference>(<property>unit</property>)</code>
9+ * to generate one.
810 *
9- * @param count Number of units, as a number or numeric string.
10- * @param unit Label for the singular unit (e.g., "apple").
11- * @param plural Optional plural label. If not provided, the unit is pluralized automatically.
12- * @returns A formatted string in the form `x unit(s)`.
11+ * ## Usage
1312 *
14- * @example
13+ * ```ts
1514 * quantify(1, "apple"); // "1 apple"
15+ * ```
1616 *
17- * @example
17+ * ```ts
1818 * quantify(3, "apple"); // "3 apples"
19+ * ```
1920 *
20- * @example
21- * quantify("2", "box"); // "2 boxes"
21+ * ```ts
22+ * quantify("02", "box"); // "02 boxes"
23+ * ```
2224 *
23- * @example
25+ * ```ts
2426 * quantify(1, "child", "children"); // "1 child"
27+ * ```
2528 *
26- * @example
29+ * ```ts
2730 * quantify(2, "child", "children"); // "2 children"
31+ * ```
2832 *
29- * @example
33+ * ```ts
3034 * quantify(5, "CPU"); // "5 CPUs"
35+ * ```
36+ *
37+ * @param count Number of units, as a number or numeric string.
38+ * @param unit Label for the singular unit (e.g., "apple").
39+ * @param plural Optional plural label. If not provided, the unit is pluralized automatically.
40+ * @returns A formatted string in the form `x unit(s)`.
3141 */
32- export function quantify ( count : number | string , unit : string , plural ?: string ) {
42+ export function quantify ( count : number | string , unit : string , plural ?: string ) {
3343 const value = typeof count == 'number' ? count : Number ( count ) ;
3444
3545 const label = value === 1 ? unit : plural === undefined ? pluralize ( unit ) : plural ;
3646
3747 return `${ count } ${ label } `
38-
39- }
48+ }
0 commit comments