Add Builder support/options to xml2js

This commit is contained in:
Jason R. McNeil
2014-08-10 08:07:35 -07:00
parent c773444c76
commit e74fdd30be
2 changed files with 63 additions and 24 deletions
+10
View File
@@ -5,3 +5,13 @@ import xml2js = require('xml2js');
xml2js.parseString("<root>Hello xml2js!</root>", (err: any, result: any) => { });
xml2js.parseString("<root>Hello xml2js!</root>", {trim: true}, (err: any, result: any) => { });
var builder = new xml2js.Builder({
renderOpts: {
pretty: false
}
});
var outString = builder.buildObject({
'hello': 'xml2js!'
});
+53 -24
View File
@@ -1,6 +1,6 @@
// Type definitions for node-xml2js
// Project: https://github.com/Leonidas-from-XIV/node-xml2js
// Definitions by: Michel Salib <https://github.com/michelsalib>
// Definitions by: Michel Salib <https://github.com/michelsalib>, Jason McNeil <https://github.com/jasonrm>
// 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;
}
}
}