Skip to content

Commit 7077f77

Browse files
committed
docs: fix autoPlural and Stringifiable
1 parent 628fa7e commit 7077f77

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

docs.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,13 +1932,13 @@ debouncedFunction.debouncer.on("change", (timeout, type) => {
19321932
Signature:
19331933
```ts
19341934
autoPlural(
1935-
term: string,
1935+
term: Stringifiable,
19361936
num: number | Array | NodeList | { length: number } | { count: number } | { size: number },
19371937
pluralType?: "auto" | "-s" | "-ies"
19381938
): string
19391939
```
19401940

1941-
Pluralizes a string if the given number is not 1.
1941+
Pluralizes a [Stringifiable value](#stringifiable) if the given number is not 1.
19421942
If an array or NodeList or object with either a `length`, `count` or `size` property is passed, the amount of contained items will be used.
19431943
Iterables will not work until converted to an array (with `Array.from()` or `[...iterable]`).
19441944

@@ -1960,6 +1960,10 @@ autoPlural("red apple", 2); // "red apples"
19601960
autoPlural("category", 1); // "category"
19611961
autoPlural("category", 2); // "categories"
19621962

1963+
// Stringifiable objects are also accepted:
1964+
autoPlural({ toString: () => "category" }, 2); // "categories"
1965+
autoPlural(new Map<unknown, unknown>(), 2); // "[object Map]s"
1966+
19631967
// The passed `num` object just needs to have a numeric length, count or size property:
19641968
autoPlural("element", document.querySelectorAll("html")); // "element"
19651969
autoPlural("element", document.querySelectorAll("*")); // "elements"
@@ -2993,7 +2997,7 @@ They don't alter the runtime behavior of the code, but they can be used to make
29932997
### Stringifiable
29942998
This type describes any value that either is a string itself or can be converted to a string.
29952999
To be considered stringifiable, the object needs to have a `toString()` method that returns a string.
2996-
Most primitives have this method, but something like undefined or null does not (they can only be used in the `String()` constructor or string interpolation).
3000+
Most primitives have this method, but something like undefined or null does not.
29973001
Having this method allows not just explicit conversion by using `.toString()`, but also implicit conversion by passing it into the `String()` constructor or interpolating it in a template literal string.
29983002

29993003
<details><summary><b>Example - click to view</b></summary>
@@ -3018,8 +3022,10 @@ logSomething(42); // "Log: 42"
30183022
logSomething(true); // "Log: true"
30193023
logSomething(Symbol(1)); // "Log: Symbol(1)"
30203024
logSomething(fooObject); // "Log: hello world"
3025+
logSomething(barObject); // "Log: [object Object]"
3026+
logSomething(new Map()); // "Log: [object Map]"
30213027

3022-
logSomething(barObject); // Type error
3028+
logSomething(undefined); // Type error
30233029
```
30243030
</details>
30253031

0 commit comments

Comments
 (0)