UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

31 lines (30 loc) 1.04 kB
import { type Data } from "./data.js"; import type { AnyCaller } from "./function.js"; /** * Escape a string for safe inclusion in XML text content or attribute values. * * @param value The raw string value. * @returns The escaped XML-safe string. * * @example * escapeXML(`Tom & "Jerry"`) */ export declare function escapeXML(value: string): string; /** * Build an XML string from a data object. * * - Only data objects can be converted directly because XML requires named root and child elements. * - `undefined` values are omitted from the output. * - Nested data objects become nested XML elements. * * @param data The data object to serialize. * @param caller The calling function for error context. * @returns The serialized XML string. * * @throws {RequiredError} If a key is not a valid XML element name. * @throws {RequiredError} If a value cannot be converted to XML. * * @example * getXML({ user: { name: "Alice", age: 30 } }) */ export declare function getXML(data: Data, caller?: AnyCaller): string;