UNPKG

2.81 kBTypeScriptView Raw
1// Type definitions for node-xml2js 0.4
2// Project: https://github.com/Leonidas-from-XIV/node-xml2js
3// Definitions by: Michel Salib <https://github.com/michelsalib>
4// Jason McNeil <https://github.com/jasonrm>
5// Christopher Currens <https://github.com/ccurrens>
6// Edward Hinkle <https://github.com/edwardhinkle>
7// Behind The Math <https://github.com/BehindTheMath>
8// Claas Ahlrichs <https://github.com/claasahl>
9// Grzegorz Redlicki <https://github.com/redlickigrzegorz>
10// Ryan Ling <https://github.com/72636c>
11// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
12
13/// <reference types="node"/>
14import { EventEmitter } from 'events';
15import * as processors from './lib/processors';
16
17export function parseString(str: convertableToString, callback: (err: Error, result: any) => void): void;
18export function parseString(str: convertableToString, options: OptionsV2, callback: (err: Error, result: any) => void): void;
19export function parseStringPromise(str: convertableToString, options?: OptionsV2): Promise<any>;
20
21export const defaults: {
22 '0.1': Options;
23 '0.2': OptionsV2;
24};
25
26export class Builder {
27 constructor(options?: OptionsV2);
28 buildObject(rootObj: any): string;
29}
30
31export class Parser extends EventEmitter {
32 constructor(options?: OptionsV2);
33 parseString(str: convertableToString, cb?: Function): void;
34 parseStringPromise(str: convertableToString): Promise<any>;
35 reset(): void;
36}
37
38export interface Options {
39 async?: boolean;
40 attrkey?: string;
41 attrNameProcessors?: Array<(name: string) => any>;
42 attrValueProcessors?: Array<(value: string, name: string) => any>;
43 charkey?: string;
44 charsAsChildren?: boolean;
45 childkey?: string;
46 emptyTag?: any;
47 explicitArray?: boolean;
48 explicitCharkey?: boolean;
49 explicitChildren?: boolean;
50 explicitRoot?: boolean;
51 ignoreAttrs?: boolean;
52 includeWhiteChars?: boolean;
53 mergeAttrs?: boolean;
54 normalize?: boolean;
55 normalizeTags?: boolean;
56 strict?: boolean;
57 tagNameProcessors?: Array<(name: string) => any>;
58 trim?: boolean;
59 validator?: Function;
60 valueProcessors?: Array<(value: string, name: string) => any>;
61 xmlns?: boolean;
62}
63
64export interface OptionsV2 extends Options {
65 preserveChildrenOrder?: boolean;
66 rootName?: string;
67 xmldec?: {
68 version: string;
69 encoding?: string;
70 standalone?: boolean;
71 };
72 doctype?: any;
73 renderOpts?: {
74 pretty?: boolean;
75 indent?: string;
76 newline?: string;
77 };
78 headless?: boolean;
79 chunkSize?: number;
80 cdata?: boolean;
81}
82
83export interface convertableToString {
84 toString(): string;
85}
86
87export { processors };