xml2customjs
Version:
Library to custom convert an XML into a Javascript object or JSON
36 lines (35 loc) • 2.3 kB
TypeScript
import { AnyObject, XmlToJsOptionalOptions } from './interfaces';
/**
* This function converts an XML into a JS object according to
* a given set of options
* @param xml string
* @param options XmlToJsOptionalOptions
* Options:
* - arrayFields: array containing the names of the XML tags that are supposed to be arrays (example ['propertyKey'])
* - objectFields: array containing the names of the XML tags that are supposed to be objects (example ['propertyKey']),
* This is useful in the case of XML tags that may have properties. Read the documentation for more detail on this feature.
* - fieldNameFormat: option to format all property keys. By default, this will be set to "none".
* Options are: "camel" for camelcase format, "snake" for snakecase and "none" for no formatting.
* - fieldNameMapping: this object will be used to change the name of the property keys. The keys of this
* object need to be the exact name (in the original format) of the XML tag, and the value will be the name used
* to replace the property key during the convertion
* @returns object
*/
export declare function convertXmlToJs(xml: string, options?: XmlToJsOptionalOptions): AnyObject;
/**
* This function converts an XML into a JSON according to
* a given set of options
* @param xml string
* @param options XmlToJsOptionalOptions
* Options:
* - arrayFields: array containing the names of the XML tags that are supposed to be arrays (example ['propertyKey'])
* - objectFields: array containing the names of the XML tags that are supposed to be objects (example ['propertyKey']),
* This is useful in the case of XML tags that may have properties. Read the documentation for more detail on this feature.
* - fieldNameFormat: option to format all property keys. By default, this will be set to "none".
* Options are: "camel" for camelcase format, "snake" for snakecase and "none" for no formatting.
* - fieldNameMapping: this object will be used to change the name of the property keys. The keys of this
* object need to be the exact name (in the original format) of the XML tag, and the value will be the name used
* to replace the property key during the convertion
* @returns JSON string
*/
export declare function convertXmlToJson(xml: string, options?: XmlToJsOptionalOptions): string;