UNPKG

3.54 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// Claas Ahlrichs <https://github.com/claasahl>
8// Grzegorz Redlicki <https://github.com/redlickigrzegorz>
9// Ryan Ling <https://github.com/72636c>
10// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
11// Minimum TypeScript Version: 3.5
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(
19 str: convertableToString,
20 options: ParserOptions,
21 callback: (err: Error, result: any) => void,
22): void;
23export function parseStringPromise(str: convertableToString, options?: ParserOptions): Promise<any>;
24
25export const defaults: {
26 '0.1': Options;
27 '0.2': OptionsV2;
28};
29
30export interface XmlDeclarationAttributes {
31 version: string;
32 encoding?: string | undefined;
33 standalone?: boolean | undefined;
34}
35
36export interface RenderOptions {
37 pretty?: boolean | undefined;
38 indent?: string | undefined;
39 newline?: string | undefined;
40}
41
42export class Builder {
43 constructor(options?: BuilderOptions);
44 buildObject(rootObj: any): string;
45}
46
47export class Parser extends EventEmitter {
48 constructor(options?: ParserOptions);
49 parseString(str: convertableToString, cb?: Function): void;
50 parseStringPromise(str: convertableToString): Promise<any>;
51 reset(): void;
52}
53
54export interface ParserOptions {
55 attrkey?: string | undefined;
56 charkey?: string | undefined;
57 explicitCharkey?: boolean | undefined;
58 trim?: boolean | undefined;
59 normalizeTags?: boolean | undefined;
60 normalize?: boolean | undefined;
61 explicitRoot?: boolean | undefined;
62 emptyTag?: any;
63 explicitArray?: boolean | undefined;
64 ignoreAttrs?: boolean | undefined;
65 mergeAttrs?: boolean | undefined;
66 validator?: Function | undefined;
67 xmlns?: boolean | undefined;
68 explicitChildren?: boolean | undefined;
69 childkey?: string | undefined;
70 preserveChildrenOrder?: boolean | undefined;
71 charsAsChildren?: boolean | undefined;
72 includeWhiteChars?: boolean | undefined;
73 async?: boolean | undefined;
74 strict?: boolean | undefined;
75 attrNameProcessors?: Array<(name: string) => any> | undefined;
76 attrValueProcessors?: Array<(value: string, name: string) => any> | undefined;
77 tagNameProcessors?: Array<(name: string) => any> | undefined;
78 valueProcessors?: Array<(value: string, name: string) => any> | undefined;
79 chunkSize?: number | undefined;
80}
81
82export interface BuilderOptions {
83 attrkey?: string | undefined;
84 charkey?: string | undefined;
85 rootName?: string | undefined;
86 renderOpts?: RenderOptions | undefined;
87 xmldec?: XmlDeclarationAttributes | undefined;
88 doctype?: any;
89 headless?: boolean | undefined;
90 allowSurrogateChars?: boolean | undefined;
91 cdata?: boolean | undefined;
92}
93
94export type Options = Omit<ParserOptions, "preserveChildrenOrder" | "chunkSize">;
95export type OptionsV2 = ParserOptions & BuilderOptions;
96
97export interface convertableToString {
98 toString(): string;
99}
100
101export { processors };