Skip to content

Commit eb3a275

Browse files
committed
Merge pull request DefinitelyTyped#7801 from ccurrens/xml2js
Add v2.0 options and defaults to xml2js
2 parents c593dca + 7304e07 commit eb3a275

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

xml2js/xml2js-tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ var outString = builder.buildObject({
1717
});
1818

1919
var parser = new xml2js.Parser();
20+
21+
var v1Defaults = xml2js.defaults['0.1'];
22+
v1Defaults.async = true;
23+
24+
var v2Defaults = xml2js.defaults['0.2'];
25+
v2Defaults.async = false;
26+
v2Defaults.chunkSize = 20000;

xml2js/xml2js.d.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Type definitions for node-xml2js
22
// Project: https://github.com/Leonidas-from-XIV/node-xml2js
3-
// Definitions by: Michel Salib <https://github.com/michelsalib>, Jason McNeil <https://github.com/jasonrm>
3+
// Definitions by: Michel Salib <https://github.com/michelsalib>, Jason McNeil <https://github.com/jasonrm>, Christopher Currens <https://github.com/ccurrens>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

66
declare module 'xml2js' {
@@ -11,6 +11,11 @@ declare module 'xml2js' {
1111
function parseString(xml: string, callback: (err: any, result: any) => void): void;
1212
function parseString(xml: string, options: Options, callback: (err: any, result: any) => void): void;
1313

14+
var defaults: {
15+
'0.1': Options;
16+
'0.2': OptionsV2;
17+
}
18+
1419
class Builder {
1520
constructor(options?: BuilderOptions);
1621
buildObject(rootObj: any): string;
@@ -50,7 +55,8 @@ declare module 'xml2js' {
5055
interface Options {
5156
async?: boolean;
5257
attrkey?: string;
53-
attrNameProcessors?: (name: string) => string;
58+
attrNameProcessors?: [(name: string) => string];
59+
attrValueProcessors?: [(name: string) => string];
5460
charkey?: string;
5561
charsAsChildren?: boolean;
5662
childkey?: string;
@@ -67,7 +73,27 @@ declare module 'xml2js' {
6773
tagNameProcessors?: [(name: string) => string];
6874
trim?: boolean;
6975
validator?: Function;
76+
valueProcessors?: [(name: string) => string];
7077
xmlns?: boolean;
7178
}
79+
80+
interface OptionsV2 extends Options {
81+
preserveChildrenOrder?: boolean;
82+
rootName?: string;
83+
xmldec?: {
84+
version: string;
85+
encoding?: string;
86+
standalone?: boolean;
87+
};
88+
doctype?: any;
89+
renderOpts?: {
90+
pretty?: boolean;
91+
indent?: string;
92+
newline?: string;
93+
};
94+
headless?: boolean;
95+
chunkSize?: number;
96+
cdata?: boolean;
97+
}
7298
}
7399
}

0 commit comments

Comments
 (0)