Skip to content

Commit a4b9f79

Browse files
committed
Complete TS typings. Closes 204
1 parent 824f394 commit a4b9f79

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

typings/index.d.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ declare namespace xmlbuilder {
144144
attEscape?: (v: string) => string;
145145
}
146146

147-
class XMLWriter {
147+
interface XMLWriter {
148148
/**
149149
* Writes the indentation string for the given level.
150150
*
@@ -351,6 +351,8 @@ declare namespace xmlbuilder {
351351
user?: any;
352352
/** The current state of the writer */
353353
state?: WriterState;
354+
/** Writer function overrides */
355+
writer?: XMLWriter;
354356
}
355357

356358
enum WriterState {
@@ -399,10 +401,10 @@ declare namespace xmlbuilder {
399401
* If the default writer is not set, the built-in XMLStringWriter
400402
* will be used instead.
401403
*/
402-
writer?: XMLWriter;
404+
writer?: XMLWriter | WriterOptions;
403405
}
404406

405-
type OnDataCallback = (chunk: string) => void;
407+
type OnDataCallback = (chunk: string, level: number) => void;
406408
type OnEndCallback = () => void;
407409

408410
/**
@@ -412,7 +414,8 @@ declare namespace xmlbuilder {
412414
* @param options - create options
413415
* @param onData - the function to be called when a new chunk of XML is
414416
* output. The string containing the XML chunk is passed to `onData` as
415-
* its single argument.
417+
* its first argument and the current depth of the tree is passed as its
418+
* second argument.
416419
* @param onEnd - the function to be called when the XML document is
417420
* completed with `end`. `onEnd` does not receive any arguments.
418421
*/
@@ -435,12 +438,6 @@ declare namespace xmlbuilder {
435438
*/
436439
function streamWriter(stream: Writable, options?: WriterOptions): XMLWriter
437440

438-
/** Defines the type of an XML node. */
439-
const nodeType: NodeType;
440-
441-
/** Defines the state of an XML writer. */
442-
const writerState: WriterState;
443-
444441
enum NodeType {
445442
/** An element node */
446443
Element = 1,
@@ -475,8 +472,9 @@ declare namespace xmlbuilder {
475472
/** An element declaration node inside Doctype */
476473
ElementDeclaration = 204
477474
}
478-
479-
type nodeType = NodeType;
475+
476+
export import nodeType = NodeType;
477+
export import writerState = WriterState;
480478

481479
interface XMLToStringOptions {
482480
/** Pretty print the XML tree */
@@ -757,8 +755,8 @@ declare namespace xmlbuilder {
757755
*
758756
* @returns the root element node
759757
*/
760-
declaration(version?: string, encoding?: string, standalone?: boolean): XMLElement;
761-
dec(version?: string, encoding?: string, standalone?: boolean): XMLElement;
758+
declaration(version?: string | { version?: string, encoding?: string, standalone?: boolean }, encoding?: string, standalone?: boolean): XMLElement;
759+
dec(version?: string | { version?: string, encoding?: string, standalone?: boolean }, encoding?: string, standalone?: boolean): XMLElement;
762760

763761
/**
764762
* Creates the document type definition.
@@ -770,8 +768,8 @@ declare namespace xmlbuilder {
770768
*
771769
* @returns the DOCTYPE node
772770
*/
773-
doctype(pubID?: string, sysID?: string): XMLDocType;
774-
dtd(pubID?: string, sysID?: string): XMLDocType;
771+
doctype(pubID?: string | { pubID?: string, sysID?: string }, sysID?: string): XMLDocType;
772+
dtd(pubID?: string | { pubID?: string, sysID?: string }, sysID?: string): XMLDocType;
775773

776774
/**
777775
* Takes the root node of the given XML document and appends it
@@ -1333,21 +1331,22 @@ declare namespace xmlbuilder {
13331331
*
13341332
* @returns the document builder object
13351333
*/
1336-
declaration(version: string, encoding: string, standalone: boolean): XMLDocumentCB;
1337-
dec(version: string, encoding: string, standalone: boolean): XMLDocumentCB;
1334+
declaration(version?: string, encoding?: string, standalone?: boolean): XMLDocumentCB;
1335+
dec(version?: string, encoding?: string, standalone?: boolean): XMLDocumentCB;
13381336

13391337
/**
13401338
* Creates the document type definition.
13411339
*
13421340
* _Alias:_ `dtd`
13431341
*
1342+
* @param root - the name of the root node
13441343
* @param pubID - public identifier of the DTD
13451344
* @param sysID - system identifier of the DTD
13461345
*
13471346
* @returns the document builder object
13481347
*/
1349-
doctype(pubID: string, sysID: string): XMLDocumentCB;
1350-
dtd(pubID: string, sysID: string): XMLDocumentCB;
1348+
doctype(root: string, pubID?: string, sysID?: string): XMLDocumentCB;
1349+
dtd(root: string, pubID?: string, sysID?: string): XMLDocumentCB;
13511350

13521351
/**
13531352
* Creates an element type declaration.
@@ -1380,6 +1379,7 @@ declare namespace xmlbuilder {
13801379
*/
13811380
attList(elementName: string, attributeName: string, attributeType: string, defaultValueType?: string, defaultValue?: any): XMLDocumentCB;
13821381
att(elementName: string, attributeName: string, attributeType: string, defaultValueType?: string, defaultValue?: any): XMLDocumentCB;
1382+
a(elementName: string, attributeName: string, attributeType: string, defaultValueType?: string, defaultValue?: any): XMLDocumentCB;
13831383

13841384
/**
13851385
* Creates a general entity declaration
@@ -1391,8 +1391,8 @@ declare namespace xmlbuilder {
13911391
*
13921392
* @returns the document builder object
13931393
*/
1394-
entity(name: string, value: { pubID?: string, sysID?: string, nData?: string }): XMLDocumentCB;
1395-
ent(name: string, value: { pubID?: string, sysID?: string, nData?: string }): XMLDocumentCB;
1394+
entity(name: string, value: string | { pubID?: string, sysID?: string, nData?: string }): XMLDocumentCB;
1395+
ent(name: string, value: string | { pubID?: string, sysID?: string, nData?: string }): XMLDocumentCB;
13961396

13971397
/**
13981398
* Creates a parameter entity declaration
@@ -1404,8 +1404,8 @@ declare namespace xmlbuilder {
14041404
*
14051405
* @returns the document builder object
14061406
*/
1407-
pEntity(name: string, value: { pubID?: string, sysID?: string }): XMLDocumentCB;
1408-
pent(name: string, value: { pubID?: string, sysID?: string }): XMLDocumentCB;
1407+
pEntity(name: string, value: string | { pubID?: string, sysID?: string }): XMLDocumentCB;
1408+
pent(name: string, value: string | { pubID?: string, sysID?: string }): XMLDocumentCB;
14091409

14101410
/**
14111411
* Creates a notation declaration

0 commit comments

Comments
 (0)