UNPKG

3.1 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;
33 standalone?: boolean;
34}
35
36export interface RenderOptions {
37 pretty?: boolean;
38 indent?: string;
39 newline?: string;
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;
56 charkey?: string;
57 explicitCharkey?: boolean;
58 trim?: boolean;
59 normalizeTags?: boolean;
60 normalize?: boolean;
61 explicitRoot?: boolean;
62 emptyTag?: any;
63 explicitArray?: boolean;
64 ignoreAttrs?: boolean;
65 mergeAttrs?: boolean;
66 validator?: Function;
67 xmlns?: boolean;
68 explicitChildren?: boolean;
69 childkey?: string;
70 preserveChildrenOrder?: boolean;
71 charsAsChildren?: boolean;
72 includeWhiteChars?: boolean;
73 async?: boolean;
74 strict?: boolean;
75 attrNameProcessors?: Array<(name: string) => any>;
76 attrValueProcessors?: Array<(value: string, name: string) => any>;
77 tagNameProcessors?: Array<(name: string) => any>;
78 valueProcessors?: Array<(value: string, name: string) => any>;
79 chunkSize?: number;
80}
81
82export interface BuilderOptions {
83 attrkey?: string;
84 charkey?: string;
85 rootName?: string;
86 renderOpts?: RenderOptions;
87 xmldec?: XmlDeclarationAttributes;
88 doctype?: any;
89 headless?: boolean;
90 allowSurrogateChars?: boolean;
91 cdata?: boolean;
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 };