MCPcopy Create free account
hub / github.com/denoland/std / stringify

Function stringify

xml/stringify.ts:43–64  ·  view source on GitHub ↗
(
  node: XmlDocument | XmlElement,
  options?: StringifyOptions,
)

Source from the content-addressed store, hash-verified

41 * @returns The serialized XML string.
42 */
43export function stringify(
44 node: XmlDocument | XmlElement,
45 options?: StringifyOptions,
46): string {
47 const { indent, declaration = true } = options ?? {};
48
49 // Check if it's a document (has 'root' property) or an element
50 if ("root" in node) {
51 let result = "";
52 if (declaration && node.declaration) {
53 result += serializeDeclaration(node.declaration);
54 if (indent !== undefined) {
55 result += "\n";
56 }
57 }
58 result += serializeElement(node.root, indent, 0);
59 return result;
60 }
61
62 // It's an element
63 return serializeElement(node, indent, 0);
64}
65
66/** Serializes an XML declaration to a string. */
67function serializeDeclaration(decl: XmlDeclaration): string {

Callers 1

stringify_test.tsFile · 0.90

Calls 2

serializeDeclarationFunction · 0.85
serializeElementFunction · 0.85

Tested by

no test coverage detected