33 *
44 * @typedef Options
55 * Configuration (optional).
6- * @property {boolean } [includeImageAlt=true]
6+ * @property {boolean | null | undefined } [includeImageAlt=true]
77 * Whether to use `alt` for `image`s.
88 */
99
1010/**
1111 * Get the text content of a node or list of nodes.
12+ *
1213 * Prefers the node’s plain-text fields, otherwise serializes its children,
1314 * and if the given value is an array, serialize the nodes in it.
1415 *
1516 * @param {unknown } value
16- * @param {Options } [options]
17+ * Thing to serialize, typically `Node`.
18+ * @param {Options | null | undefined } [options]
19+ * Configuration (optional).
1720 * @returns {string }
21+ * Serialized `value`.
1822 */
19- export function toString ( value , options = { } ) {
20- const { includeImageAlt = true } = options
21- return one ( value , includeImageAlt )
23+ export function toString ( value , options ) {
24+ const includeImageAlt = ( options || { } ) . includeImageAlt
25+ return one (
26+ value ,
27+ typeof includeImageAlt === 'boolean' ? includeImageAlt : true
28+ )
2229}
2330
2431/**
32+ * One node or several nodes.
33+ *
2534 * @param {unknown } value
35+ * Thing to serialize.
2636 * @param {boolean } includeImageAlt
37+ * Include image `alt`s.
2738 * @returns {string }
39+ * Serialized node.
2840 */
2941function one ( value , includeImageAlt ) {
3042 return (
@@ -38,9 +50,14 @@ function one(value, includeImageAlt) {
3850}
3951
4052/**
53+ * Serialize a list of nodes.
54+ *
4155 * @param {Array<unknown> } values
56+ * Thing to serialize.
4257 * @param {boolean } includeImageAlt
58+ * Include image `alt`s.
4359 * @returns {string }
60+ * Serialized nodes.
4461 */
4562function all ( values , includeImageAlt ) {
4663 /** @type {Array<string> } */
@@ -55,8 +72,12 @@ function all(values, includeImageAlt) {
5572}
5673
5774/**
75+ * Check if `value` looks like a node.
76+ *
5877 * @param {unknown } value
78+ * Thing.
5979 * @returns {value is Node }
80+ * Whether `value` is a node.
6081 */
6182function node ( value ) {
6283 return Boolean ( value && typeof value === 'object' )
0 commit comments