diff --git a/xml2js/xml2js-tests.ts b/xml2js/xml2js-tests.ts index 3e3fbb661c..f2d9dc41e9 100644 --- a/xml2js/xml2js-tests.ts +++ b/xml2js/xml2js-tests.ts @@ -5,3 +5,13 @@ import xml2js = require('xml2js'); xml2js.parseString("Hello xml2js!", (err: any, result: any) => { }); xml2js.parseString("Hello xml2js!", {trim: true}, (err: any, result: any) => { }); + +var builder = new xml2js.Builder({ + renderOpts: { + pretty: false + } +}); + +var outString = builder.buildObject({ + 'hello': 'xml2js!' +}); diff --git a/xml2js/xml2js.d.ts b/xml2js/xml2js.d.ts index 30aa64a876..f734e4ba03 100644 --- a/xml2js/xml2js.d.ts +++ b/xml2js/xml2js.d.ts @@ -1,6 +1,6 @@ // Type definitions for node-xml2js // Project: https://github.com/Leonidas-from-XIV/node-xml2js -// Definitions by: Michel Salib +// Definitions by: Michel Salib , Jason McNeil // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module 'xml2js' { @@ -8,29 +8,58 @@ declare module 'xml2js' { export = xml2js; module xml2js { - function parseString(xml:string, callback: (err: any, result:any) => void): void; - function parseString(xml:string, options: Options, callback: (err: any, result:any) => void): void; + function parseString(xml: string, callback: (err: any, result: any) => void): void; + function parseString(xml: string, options: Options, callback: (err: any, result: any) => void): void; - interface Options { - attrkey?: string; - charkey?: string; - explicitCharkey?: boolean; - trim?: boolean; - normalizeTags?: boolean; - normalize?: boolean; - explicitRoot?: boolean; - emptyTag?: any; - explicitArray?: boolean; - ignoreAttrs?: boolean; - mergeAttrs?: boolean; - validator?: Function; - xmlns?: boolean; - explicitChildren?: boolean; - charsAsChildren?: boolean; - async?: boolean; - strict?: boolean; - attrNameProcessors?: (name: string) => string; - tagNameProcessors?: (name: string) => string; - } + class Builder { + constructor(options?: BuilderOptions); + buildObject(rootObj: any): string; + } + + interface RenderOptions { + indent?: string; + newline?: string; + pretty?: boolean; + } + + interface XMLDeclarationOptions { + encoding?: string; + standalone?: boolean; + version?: string; + } + + interface BuilderOptions { + doctype?: any; + headless?: boolean; + indent?: string; + newline?: string; + pretty?: boolean; + renderOpts?: RenderOptions; + rootName?: string; + xmldec?: XMLDeclarationOptions; + } + + interface Options { + async?: boolean; + attrkey?: string; + attrNameProcessors?: (name: string) => string; + charkey?: string; + charsAsChildren?: boolean; + childkey?: string; + emptyTag?: any; + explicitArray?: boolean; + explicitCharkey?: boolean; + explicitChildren?: boolean; + explicitRoot?: boolean; + ignoreAttrs?: boolean; + mergeAttrs?: boolean; + normalize?: boolean; + normalizeTags?: boolean; + strict?: boolean; + tagNameProcessors?: (name: string) => string; + trim?: boolean; + validator?: Function; + xmlns?: boolean; + } } }