jsxText

tcmts.core.canonicalize.jsxText · #gr7ij3o7 · term · runs anywhere

Text between JSX tags as React sees it: each line trimmed, blank lines dropped, lines joined with a space. So reformatting markup hashes the same, and whitespace React keeps (a <b/>) still counts.

export function jsxText(raw: string): string {
  const lines = raw.split(/\r\n|\n|\r/);
  if (lines.length === 1) return raw;
  return lines
    .map((l, i) => (i === 0 ? l.trimEnd() : i === lines.length - 1 ? l.trimStart() : l.trim()))
    .filter((l) => l !== "")
    .join(" ");
}

used by