Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 46 additions & 35 deletions types/xml/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,56 @@

/// <reference types="node" />

interface Option {
/**
* String used for tab, defaults to no tabs (compressed)
*/
indent?: string;
/**
* Return the result as a `stream` (default false)
*/
stream?: boolean;
/**
* Add default xml declaration (default false)
*/
declaration?: boolean | {
encoding?: string;
standalone?: string;
};
}
declare namespace xml {
interface Option {
/**
* String used for tab, defaults to no tabs (compressed)
*/
indent?: string;
/**
* Return the result as a `stream` (default false)
*/
stream?: boolean;
/**
* Add default xml declaration (default false)
*/
declaration?:
| boolean
| {
encoding?: string;
standalone?: string;
};
}

interface XmlAttrs {
[attr: string]: XmlAtom;
}
interface XmlDescArray {
[index: number]: { _attr: XmlAttrs } | XmlObject;
}
interface ElementObject {
push(xmlObject: XmlObject): void;
close(xmlObject?: XmlObject): void;
}
interface XmlAttrs {
[attr: string]: XmlAtom;
}
interface XmlDescArray {
[index: number]: { _attr: XmlAttrs } | XmlObject;
}
interface ElementObject {
push(xmlObject: XmlObject): void;
close(xmlObject?: XmlObject): void;
}

type XmlAtom = string | number | boolean | null;
type XmlDesc = { _attr: XmlAttrs } | { _cdata: string } | { _attr: XmlAttrs, _cdata: string } | XmlAtom | XmlAtom[] | XmlDescArray;
type XmlObject = { [tag: string]: ElementObject | XmlDesc } | XmlDesc;
type XmlAtom = string | number | boolean | null;
type XmlDesc =
| { _attr: XmlAttrs }
| { _cdata: string }
| { _attr: XmlAttrs; _cdata: string }
| XmlAtom
| XmlAtom[]
| XmlDescArray;
type XmlObject = { [tag: string]: ElementObject | XmlDesc } | XmlDesc;

declare namespace xml {
function element(...xmlObjects: XmlObject[]): ElementObject;
function Element(...xmlObjects: XmlObject[]): ElementObject;
function element(...xmlObjects: XmlObject[]): ElementObject;
function Element(...xmlObjects: XmlObject[]): ElementObject;
}

declare function xml(xmlObject: XmlObject | XmlObject[], options: { stream: true, indent?: string }): NodeJS.ReadableStream;
declare function xml(xmlObject?: XmlObject | XmlObject[], options?: boolean | string | Option): string;
declare function xml(
xmlObject: xml.XmlObject | xml.XmlObject[],
options: { stream: true; indent?: string },
): NodeJS.ReadableStream;
declare function xml(xmlObject?: xml.XmlObject | xml.XmlObject[], options?: boolean | string | xml.Option): string;

export = xml;