xml-sax-ts 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -46
- package/dist/index.cjs +273 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -28
- package/dist/index.d.ts +67 -28
- package/dist/index.js +263 -119
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -37,15 +37,8 @@ interface ParserOptions {
|
|
|
37
37
|
allowDoctype?: boolean;
|
|
38
38
|
coalesceText?: boolean;
|
|
39
39
|
trackPosition?: boolean;
|
|
40
|
-
onOpenTag?: (tag: OpenTag) => void;
|
|
41
|
-
onCloseTag?: (tag: CloseTag) => void;
|
|
42
|
-
onText?: (text: string) => void;
|
|
43
|
-
onCdata?: (text: string) => void;
|
|
44
|
-
onComment?: (text: string) => void;
|
|
45
|
-
onProcessingInstruction?: (pi: ProcessingInstruction) => void;
|
|
46
|
-
onDoctype?: (doctype: Doctype) => void;
|
|
47
|
-
onError?: (error: Error) => void;
|
|
48
40
|
}
|
|
41
|
+
type XmlChunkIterable = Iterable<string> | AsyncIterable<string>;
|
|
49
42
|
type XmlChild = XmlNode | string;
|
|
50
43
|
interface XmlNode {
|
|
51
44
|
name: string;
|
|
@@ -80,24 +73,61 @@ interface XmlInputObject {
|
|
|
80
73
|
interface ObjectToXmlOptions extends XmlBuilderOptions, SerializeOptions {
|
|
81
74
|
}
|
|
82
75
|
|
|
76
|
+
type XmlTokenKind = "open-tag" | "close-tag" | "text" | "cdata" | "comment" | "processing-instruction" | "doctype" | "end";
|
|
77
|
+
declare abstract class XmlToken {
|
|
78
|
+
readonly kind: XmlTokenKind;
|
|
79
|
+
readonly position: XmlPosition | undefined;
|
|
80
|
+
protected constructor(kind: XmlTokenKind, position?: XmlPosition);
|
|
81
|
+
}
|
|
82
|
+
declare class OpenTagToken extends XmlToken {
|
|
83
|
+
readonly tag: OpenTag;
|
|
84
|
+
readonly depth: number;
|
|
85
|
+
readonly path: readonly string[];
|
|
86
|
+
constructor(tag: OpenTag, depth: number, path: readonly string[], position?: XmlPosition);
|
|
87
|
+
}
|
|
88
|
+
declare class CloseTagToken extends XmlToken {
|
|
89
|
+
readonly tag: CloseTag;
|
|
90
|
+
readonly depth: number;
|
|
91
|
+
readonly path: readonly string[];
|
|
92
|
+
constructor(tag: CloseTag, depth: number, path: readonly string[], position?: XmlPosition);
|
|
93
|
+
}
|
|
94
|
+
declare class TextToken extends XmlToken {
|
|
95
|
+
readonly text: string;
|
|
96
|
+
constructor(text: string, position?: XmlPosition);
|
|
97
|
+
}
|
|
98
|
+
declare class CdataToken extends XmlToken {
|
|
99
|
+
readonly text: string;
|
|
100
|
+
constructor(text: string, position?: XmlPosition);
|
|
101
|
+
}
|
|
102
|
+
declare class CommentToken extends XmlToken {
|
|
103
|
+
readonly text: string;
|
|
104
|
+
constructor(text: string, position?: XmlPosition);
|
|
105
|
+
}
|
|
106
|
+
declare class ProcessingInstructionToken extends XmlToken {
|
|
107
|
+
readonly processingInstruction: ProcessingInstruction;
|
|
108
|
+
constructor(processingInstruction: ProcessingInstruction, position?: XmlPosition);
|
|
109
|
+
}
|
|
110
|
+
declare class DoctypeToken extends XmlToken {
|
|
111
|
+
readonly doctype: Doctype;
|
|
112
|
+
constructor(doctype: Doctype, position?: XmlPosition);
|
|
113
|
+
}
|
|
114
|
+
declare class EndToken extends XmlToken {
|
|
115
|
+
constructor(position?: XmlPosition);
|
|
116
|
+
}
|
|
117
|
+
type XmlAnyToken = OpenTagToken | CloseTagToken | TextToken | CdataToken | CommentToken | ProcessingInstructionToken | DoctypeToken | EndToken;
|
|
118
|
+
|
|
83
119
|
declare class XmlSaxParser {
|
|
84
120
|
private readonly xmlns;
|
|
85
121
|
private readonly includeNamespaceAttributes;
|
|
86
122
|
private readonly allowDoctype;
|
|
87
123
|
private readonly coalesceText;
|
|
88
124
|
private readonly trackPosition;
|
|
89
|
-
private readonly onOpenTag;
|
|
90
|
-
private readonly onCloseTag;
|
|
91
|
-
private readonly onText;
|
|
92
|
-
private readonly onCdata;
|
|
93
|
-
private readonly onComment;
|
|
94
|
-
private readonly onProcessingInstruction;
|
|
95
|
-
private readonly onDoctype;
|
|
96
|
-
private readonly onError;
|
|
97
125
|
private buffer;
|
|
98
126
|
private offset;
|
|
99
127
|
private line;
|
|
100
128
|
private column;
|
|
129
|
+
private readonly pathStack;
|
|
130
|
+
private readonly tokenQueue;
|
|
101
131
|
private elementStack;
|
|
102
132
|
private nsStack;
|
|
103
133
|
private closed;
|
|
@@ -105,8 +135,11 @@ declare class XmlSaxParser {
|
|
|
105
135
|
private readonly pendingTextParts;
|
|
106
136
|
private readonly _rawAttrs;
|
|
107
137
|
constructor(options?: ParserOptions);
|
|
108
|
-
feed(chunk: string):
|
|
109
|
-
close():
|
|
138
|
+
feed(chunk: string): XmlAnyToken[];
|
|
139
|
+
close(): XmlAnyToken[];
|
|
140
|
+
drainTokens(): XmlAnyToken[];
|
|
141
|
+
[Symbol.iterator](): IterableIterator<XmlAnyToken>;
|
|
142
|
+
iterateChunks(chunks: Iterable<string> | AsyncIterable<string>): AsyncGenerator<XmlAnyToken>;
|
|
110
143
|
private _parseBuffer;
|
|
111
144
|
private _parseMarkupFrom;
|
|
112
145
|
private _handleStartTagRange;
|
|
@@ -127,7 +160,11 @@ declare class XmlSaxParser {
|
|
|
127
160
|
private _advanceSpan;
|
|
128
161
|
private _flushPendingCR;
|
|
129
162
|
private _error;
|
|
163
|
+
private _position;
|
|
164
|
+
private _pushToken;
|
|
130
165
|
}
|
|
166
|
+
declare function tokenizeXml(xml: string, options?: ParserOptions): XmlAnyToken[];
|
|
167
|
+
declare function tokenizeXmlAsync(chunks: Iterable<string> | AsyncIterable<string>, options?: ParserOptions): AsyncGenerator<XmlAnyToken>;
|
|
131
168
|
|
|
132
169
|
declare class XmlSaxError extends Error {
|
|
133
170
|
readonly offset: number;
|
|
@@ -139,15 +176,16 @@ declare class XmlSaxError extends Error {
|
|
|
139
176
|
declare class TreeBuilder {
|
|
140
177
|
private stack;
|
|
141
178
|
private root;
|
|
142
|
-
onOpenTag
|
|
179
|
+
onOpenTag(tag: {
|
|
143
180
|
name: string;
|
|
144
181
|
attributes: Record<string, {
|
|
145
182
|
value: string;
|
|
146
183
|
} | string>;
|
|
147
|
-
})
|
|
148
|
-
onText
|
|
149
|
-
onCdata
|
|
150
|
-
onCloseTag
|
|
184
|
+
}): void;
|
|
185
|
+
onText(text: string): void;
|
|
186
|
+
onCdata(text: string): void;
|
|
187
|
+
onCloseTag(): void;
|
|
188
|
+
consume(token: OpenTagToken | TextToken | CdataToken | CloseTagToken): void;
|
|
151
189
|
getRoot(): XmlNode;
|
|
152
190
|
}
|
|
153
191
|
declare function parseXmlString(xml: string, options?: ParserOptions): XmlNode;
|
|
@@ -170,12 +208,13 @@ declare class ObjectBuilder {
|
|
|
170
208
|
private root;
|
|
171
209
|
private rootName;
|
|
172
210
|
constructor(options?: ObjectBuilderOptions);
|
|
173
|
-
onOpenTag
|
|
174
|
-
onText
|
|
175
|
-
onCdata
|
|
176
|
-
onCloseTag
|
|
211
|
+
onOpenTag(tag: OpenTag): void;
|
|
212
|
+
onText(text: string): void;
|
|
213
|
+
onCdata(text: string): void;
|
|
214
|
+
onCloseTag(): void;
|
|
215
|
+
consume(token: OpenTagToken | TextToken | CdataToken | CloseTagToken): void;
|
|
177
216
|
getResult(): XmlObjectValue;
|
|
178
217
|
getRootName(): string;
|
|
179
218
|
}
|
|
180
219
|
|
|
181
|
-
export { type ArrayElementSelector, type CloseTag, type Doctype, ObjectBuilder, type ObjectBuilderOptions, type ObjectToXmlOptions, type OpenTag, type ParserOptions, type ProcessingInstruction, type SerializeOptions, TreeBuilder, type XmlAttribute, type XmlBuilderOptions, type XmlChild, type XmlInputObject, type XmlInputValue, type XmlNode, type XmlObjectMap, type XmlObjectValue, type XmlPosition, XmlSaxError, XmlSaxParser, buildObject, buildXmlNode, objectToXml, parseXmlString, resolveName, serializeXml, stripNamespace };
|
|
220
|
+
export { type ArrayElementSelector, CdataToken, type CloseTag, CloseTagToken, CommentToken, type Doctype, DoctypeToken, EndToken, ObjectBuilder, type ObjectBuilderOptions, type ObjectToXmlOptions, type OpenTag, OpenTagToken, type ParserOptions, type ProcessingInstruction, ProcessingInstructionToken, type SerializeOptions, TextToken, TreeBuilder, type XmlAnyToken, type XmlAttribute, type XmlBuilderOptions, type XmlChild, type XmlChunkIterable, type XmlInputObject, type XmlInputValue, type XmlNode, type XmlObjectMap, type XmlObjectValue, type XmlPosition, XmlSaxError, XmlSaxParser, XmlToken, type XmlTokenKind, buildObject, buildXmlNode, objectToXml, parseXmlString, resolveName, serializeXml, stripNamespace, tokenizeXml, tokenizeXmlAsync };
|