* Creates a memoized indent getter to avoid recomputing indent.repeat(depth).
( indent: string | undefined, )
| 78 | * Creates a memoized indent getter to avoid recomputing indent.repeat(depth). |
| 79 | */ |
| 80 | function createIndentCache( |
| 81 | indent: string | undefined, |
| 82 | ): (depth: number) => string { |
| 83 | if (indent === undefined) return () => ""; |
| 84 | const cache: string[] = [""]; |
| 85 | return (depth: number): string => (cache[depth] ??= indent.repeat(depth)); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Serializes an XML element and its children to a string. |