@structium/xml
Version:
Serialize and deserialize XML
28 lines (24 loc) • 1.19 kB
TypeScript
import { X2jOptions, validationOptions } from 'fast-xml-parser';
type CommonObj = Record<string, unknown> | Record<string, unknown>[] | unknown[];
type DeserializeOptions = X2jOptions & {
validation: validationOptions;
};
/**
* Parses an XML content string into a JavaScript object.
*
* @template Res - The expected return type of the parsed object.
* @param {string} input - The XML content string to be parsed.
* @param {object} [options] - Options to pass to the XML parser.
* @returns {Promise<Res>} - A promise that resolves to the parsed XML as an object.
* @throws {Error} If there is an error parsing the XML content.
*/
declare const deserialize: <Res extends CommonObj = CommonObj>(input: string, options?: DeserializeOptions) => Promise<Res>;
/**
* Converts a JavaScript object into an XML string.
*
* @template I - The type of the object to be converted.
* @param {I} input - The object to be converted.
* @returns {Promise<string>} - A promise that resolves to the XML string.
*/
declare const serialize: <I extends CommonObj = CommonObj>(input: I) => Promise<string>;
export { deserialize, serialize };