MCPcopy Create free account
hub / github.com/ethanniser/the-beth-stack / contentsToString

Function contentsToString

packages/beth-stack/src/jsx/utils.ts:269–301  ·  view source on GitHub ↗
(
  contents: Children[],
  escape?: boolean,
)

Source from the content-addressed store, hash-verified

267}
268
269export function contentsToString(
270 contents: Children[],
271 escape?: boolean,
272): string {
273 const length = contents.length;
274
275 if (length === 0) {
276 return "";
277 }
278
279 let result = "";
280 let content;
281 let index = 0;
282
283 for (; index < length; index++) {
284 content = contents[index];
285
286 // Ignores non 0 falsy values
287 if (!content && content !== 0) {
288 continue;
289 }
290
291 if (Array.isArray(content)) {
292 result += contentsToString(content, escape);
293 } else if (escape === true) {
294 result += Bun.escapeHTML(content);
295 } else {
296 result += content;
297 }
298 }
299
300 return result;
301}
302
303export function deepFlatten<T>(arr: (T | T[])[]): T[] {
304 return arr.reduce<T[]>((acc, val) => {

Callers 1

createElementFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected