1 |
|
2 |
|
3 |
|
4 | export declare const EVENTS: readonly ["xmldecl", "text", "processinginstruction", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "cdata", "error", "end", "ready"];
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export declare type XMLDeclHandler = (decl: XMLDecl) => void;
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export declare type TextHandler = (text: string) => void;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export declare type PIHandler = (data: {
|
25 | target: string;
|
26 | body: string;
|
27 | }) => void;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export declare type DoctypeHandler = (doctype: string) => void;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export declare type CommentHandler = (comment: string) => void;
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | export declare type OpenTagStartHandler<O> = (tag: StartTagForOptions<O>) => void;
|
47 | export declare type AttributeEventForOptions<O extends SaxesOptions> = O extends {
|
48 | xmlns: true;
|
49 | } ? SaxesAttributeNSIncomplete : O extends {
|
50 | xmlns?: false | undefined;
|
51 | } ? SaxesAttributePlain : SaxesAttribute;
|
52 |
|
53 |
|
54 |
|
55 | export declare type AttributeHandler<O> = (attribute: AttributeEventForOptions<O>) => void;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | export declare type OpenTagHandler<O> = (tag: TagForOptions<O>) => void;
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export declare type CloseTagHandler<O> = (tag: TagForOptions<O>) => void;
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | export declare type CDataHandler = (cdata: string) => void;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | export declare type EndHandler = () => void;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export declare type ReadyHandler = () => void;
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | export declare type ErrorHandler = (err: Error) => void;
|
93 | export declare type EventName = (typeof EVENTS)[number];
|
94 | export declare type EventNameToHandler<O, N extends EventName> = {
|
95 | "xmldecl": XMLDeclHandler;
|
96 | "text": TextHandler;
|
97 | "processinginstruction": PIHandler;
|
98 | "doctype": DoctypeHandler;
|
99 | "comment": CommentHandler;
|
100 | "opentagstart": OpenTagStartHandler<O>;
|
101 | "attribute": AttributeHandler<O>;
|
102 | "opentag": OpenTagHandler<O>;
|
103 | "closetag": CloseTagHandler<O>;
|
104 | "cdata": CDataHandler;
|
105 | "error": ErrorHandler;
|
106 | "end": EndHandler;
|
107 | "ready": ReadyHandler;
|
108 | }[N];
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | export interface SaxesAttributeNS {
|
114 | |
115 |
|
116 |
|
117 |
|
118 | name: string;
|
119 | |
120 |
|
121 |
|
122 |
|
123 | prefix: string;
|
124 | |
125 |
|
126 |
|
127 |
|
128 | local: string;
|
129 |
|
130 | uri: string;
|
131 |
|
132 | value: string;
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | export declare type SaxesAttributeNSIncomplete = Exclude<SaxesAttributeNS, "uri">;
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | export interface SaxesAttributePlain {
|
145 | |
146 |
|
147 |
|
148 | name: string;
|
149 |
|
150 | value: string;
|
151 | }
|
152 |
|
153 |
|
154 |
|
155 | export declare type SaxesAttribute = SaxesAttributeNS | SaxesAttributePlain;
|
156 |
|
157 |
|
158 |
|
159 | export interface SaxesTag {
|
160 | |
161 |
|
162 |
|
163 |
|
164 | name: string;
|
165 | |
166 |
|
167 |
|
168 |
|
169 | attributes: Record<string, SaxesAttributeNS> | Record<string, string>;
|
170 | |
171 |
|
172 |
|
173 | ns?: Record<string, string>;
|
174 | |
175 |
|
176 |
|
177 |
|
178 | prefix?: string;
|
179 | |
180 |
|
181 |
|
182 |
|
183 | local?: string;
|
184 | |
185 |
|
186 |
|
187 | uri?: string;
|
188 |
|
189 | isSelfClosing: boolean;
|
190 | }
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | export declare type SaxesStartTag = Pick<SaxesTag, "name" | "attributes" | "ns">;
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | export declare type SaxesStartTagPlain = Pick<SaxesStartTag, "name" | "attributes">;
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | export declare type SaxesStartTagNS = Required<SaxesStartTag>;
|
206 |
|
207 |
|
208 |
|
209 |
|
210 | export declare type SaxesTagNS = Required<SaxesTag> & {
|
211 | attributes: Record<string, SaxesAttributeNS>;
|
212 | };
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | export declare type SaxesTagPlain = Pick<SaxesTag, "name" | "attributes" | "isSelfClosing"> & {
|
218 | attributes: Record<string, string>;
|
219 | };
|
220 |
|
221 |
|
222 |
|
223 | export interface XMLDecl {
|
224 |
|
225 | version?: string;
|
226 |
|
227 | encoding?: string;
|
228 |
|
229 | standalone?: string;
|
230 | }
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | export declare type ResolvePrefix = (prefix: string) => string | undefined;
|
239 | export interface CommonOptions {
|
240 |
|
241 | fragment?: boolean;
|
242 |
|
243 | position?: boolean;
|
244 | |
245 |
|
246 |
|
247 |
|
248 | fileName?: string;
|
249 | }
|
250 | export interface NSOptions {
|
251 |
|
252 | xmlns?: boolean;
|
253 | |
254 |
|
255 |
|
256 |
|
257 |
|
258 | additionalNamespaces?: Record<string, string>;
|
259 | |
260 |
|
261 |
|
262 |
|
263 | resolvePrefix?: ResolvePrefix;
|
264 | }
|
265 | export interface NSOptionsWithoutNamespaces extends NSOptions {
|
266 | xmlns?: false;
|
267 | additionalNamespaces?: undefined;
|
268 | resolvePrefix?: undefined;
|
269 | }
|
270 | export interface NSOptionsWithNamespaces extends NSOptions {
|
271 | xmlns: true;
|
272 | }
|
273 | export interface XMLVersionOptions {
|
274 | |
275 |
|
276 |
|
277 |
|
278 | defaultXMLVersion?: "1.0" | "1.1";
|
279 | |
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 | forceXMLVersion?: boolean;
|
286 | }
|
287 | export interface NoForcedXMLVersion extends XMLVersionOptions {
|
288 | forceXMLVersion?: false;
|
289 | }
|
290 | export interface ForcedXMLVersion extends XMLVersionOptions {
|
291 | forceXMLVersion: true;
|
292 | defaultXMLVersion: Exclude<XMLVersionOptions["defaultXMLVersion"], undefined>;
|
293 | }
|
294 |
|
295 |
|
296 |
|
297 | export declare type SaxesOptions = CommonOptions & NSOptions & XMLVersionOptions;
|
298 | export declare type TagForOptions<O extends SaxesOptions> = O extends {
|
299 | xmlns: true;
|
300 | } ? SaxesTagNS : O extends {
|
301 | xmlns?: false | undefined;
|
302 | } ? SaxesTagPlain : SaxesTag;
|
303 | export declare type StartTagForOptions<O extends SaxesOptions> = O extends {
|
304 | xmlns: true;
|
305 | } ? SaxesStartTagNS : O extends {
|
306 | xmlns?: false | undefined;
|
307 | } ? SaxesStartTagPlain : SaxesStartTag;
|
308 | export declare class SaxesParser<O extends SaxesOptions = {}> {
|
309 | private readonly fragmentOpt;
|
310 | private readonly xmlnsOpt;
|
311 | private readonly trackPosition;
|
312 | private readonly fileName?;
|
313 | private readonly nameStartCheck;
|
314 | private readonly nameCheck;
|
315 | private readonly isName;
|
316 | private readonly ns;
|
317 | private openWakaBang;
|
318 | private text;
|
319 | private name;
|
320 | private piTarget;
|
321 | private entity;
|
322 | private q;
|
323 | private tags;
|
324 | private tag;
|
325 | private topNS;
|
326 | private chunk;
|
327 | private chunkPosition;
|
328 | private i;
|
329 | private prevI;
|
330 | private carriedFromPrevious?;
|
331 | private forbiddenState;
|
332 | private attribList;
|
333 | private state;
|
334 | private reportedTextBeforeRoot;
|
335 | private reportedTextAfterRoot;
|
336 | private closedRoot;
|
337 | private sawRoot;
|
338 | private xmlDeclPossible;
|
339 | private xmlDeclExpects;
|
340 | private entityReturnState?;
|
341 | private processAttribs;
|
342 | private positionAtNewLine;
|
343 | private doctype;
|
344 | private getCode;
|
345 | private isChar;
|
346 | private pushAttrib;
|
347 | private _closed;
|
348 | private currentXMLVersion;
|
349 | private readonly stateTable;
|
350 | private xmldeclHandler?;
|
351 | private textHandler?;
|
352 | private piHandler?;
|
353 | private doctypeHandler?;
|
354 | private commentHandler?;
|
355 | private openTagStartHandler?;
|
356 | private openTagHandler?;
|
357 | private closeTagHandler?;
|
358 | private cdataHandler?;
|
359 | private errorHandler?;
|
360 | private endHandler?;
|
361 | private readyHandler?;
|
362 | private attributeHandler?;
|
363 | |
364 |
|
365 |
|
366 |
|
367 | get closed(): boolean;
|
368 | readonly opt: SaxesOptions;
|
369 | |
370 |
|
371 |
|
372 | xmlDecl: XMLDecl;
|
373 | |
374 |
|
375 |
|
376 |
|
377 | line: number;
|
378 | |
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 | column: number;
|
389 | |
390 |
|
391 |
|
392 | ENTITIES: Record<string, string>;
|
393 | |
394 |
|
395 |
|
396 | constructor(opt?: O);
|
397 | _init(): void;
|
398 | /**
|
399 | * The stream position the parser is currently looking at. This field is
|
400 | * zero-based.
|
401 | *
|
402 | * This field is not based on counting Unicode characters but is to be
|
403 | * interpreted as a plain index into a JavaScript string.
|
404 | */
|
405 | get position(): number;
|
406 | /**
|
407 | * The column number of the next character to be read by the parser. *
|
408 | * This field is zero-based. (The first column in a line is 0.)
|
409 | *
|
410 | * This field reports the index at which the next character would be in the
|
411 | * line if the line were represented as a JavaScript string. Note that this
|
412 | * *can* be different to a count based on the number of *Unicode characters*
|
413 | * due to how JavaScript handles astral plane characters.
|
414 | *
|
415 | * See [[column]] for a number that corresponds to a count of Unicode
|
416 | * characters.
|
417 | */
|
418 | get columnIndex(): number;
|
419 | /**
|
420 | * Set an event listener on an event. The parser supports one handler per
|
421 | * event type. If you try to set an event handler over an existing handler,
|
422 | * the old handler is silently overwritten.
|
423 | *
|
424 | * @param name The event to listen to.
|
425 | *
|
426 | * @param handler The handler to set.
|
427 | */
|
428 | on<N extends EventName>(name: N, handler: EventNameToHandler<O, N>): void;
|
429 | /**
|
430 | * Unset an event handler.
|
431 | *
|
432 | * @parma name The event to stop listening to.
|
433 | */
|
434 | off(name: EventName): void;
|
435 | /**
|
436 | * Make an error object. The error object will have a message that contains
|
437 | * the ``fileName`` option passed at the creation of the parser. If position
|
438 | * tracking was turned on, it will also have line and column number
|
439 | * information.
|
440 | *
|
441 | * @param message The message describing the error to report.
|
442 | *
|
443 | * @returns An error object with a properly formatted message.
|
444 | */
|
445 | makeError(message: string): Error;
|
446 | /**
|
447 | * Report a parsing error. This method is made public so that client code may
|
448 | * check for issues that are outside the scope of this project and can report
|
449 | * errors.
|
450 | *
|
451 | * @param message The error to report.
|
452 | *
|
453 | * @returns this
|
454 | */
|
455 | fail(message: string): this;
|
456 | /**
|
457 | * Write a XML data to the parser.
|
458 | *
|
459 | * @param chunk The XML data to write.
|
460 | *
|
461 | * @returns this
|
462 | */
|
463 | write(chunk: string | object | null): this;
|
464 | /**
|
465 | * Close the current stream. Perform final well-formedness checks and reset
|
466 | * the parser tstate.
|
467 | *
|
468 | * @returns this
|
469 | */
|
470 | close(): this;
|
471 | /**
|
472 | * Get a single code point out of the current chunk. This updates the current
|
473 | * position if we do position tracking.
|
474 | *
|
475 | * This is the algorithm to use for XML 1.0.
|
476 | *
|
477 | * @returns The character read.
|
478 | */
|
479 | private getCode10;
|
480 | /**
|
481 | * Get a single code point out of the current chunk. This updates the current
|
482 | * position if we do position tracking.
|
483 | *
|
484 | * This is the algorithm to use for XML 1.1.
|
485 | *
|
486 | * @returns {number} The character read.
|
487 | */
|
488 | private getCode11;
|
489 | |
490 |
|
491 |
|
492 |
|
493 | private getCodeNorm;
|
494 | private unget;
|
495 | |
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | private captureTo;
|
507 | |
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 | private captureToChar;
|
517 | |
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 | private captureNameChars;
|
526 | |
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 | private skipSpaces;
|
534 | private setXMLVersion;
|
535 | private sBegin;
|
536 | private sBeginWhitespace;
|
537 | private sDoctype;
|
538 | private sDoctypeQuote;
|
539 | private sDTD;
|
540 | private sDTDQuoted;
|
541 | private sDTDOpenWaka;
|
542 | private sDTDOpenWakaBang;
|
543 | private sDTDComment;
|
544 | private sDTDCommentEnding;
|
545 | private sDTDCommentEnded;
|
546 | private sDTDPI;
|
547 | private sDTDPIEnding;
|
548 | private sText;
|
549 | private sEntity;
|
550 | private sOpenWaka;
|
551 | private sOpenWakaBang;
|
552 | private sComment;
|
553 | private sCommentEnding;
|
554 | private sCommentEnded;
|
555 | private sCData;
|
556 | private sCDataEnding;
|
557 | private sCDataEnding2;
|
558 | private sPIFirstChar;
|
559 | private sPIRest;
|
560 | private sPIBody;
|
561 | private sPIEnding;
|
562 | private sXMLDeclNameStart;
|
563 | private sXMLDeclName;
|
564 | private sXMLDeclEq;
|
565 | private sXMLDeclValueStart;
|
566 | private sXMLDeclValue;
|
567 | private sXMLDeclSeparator;
|
568 | private sXMLDeclEnding;
|
569 | private sOpenTag;
|
570 | private sOpenTagSlash;
|
571 | private sAttrib;
|
572 | private sAttribName;
|
573 | private sAttribNameSawWhite;
|
574 | private sAttribValue;
|
575 | private sAttribValueQuoted;
|
576 | private sAttribValueClosed;
|
577 | private sAttribValueUnquoted;
|
578 | private sCloseTag;
|
579 | private sCloseTagSawWhite;
|
580 | private handleTextInRoot;
|
581 | private handleTextOutsideRoot;
|
582 | private pushAttribNS;
|
583 | private pushAttribPlain;
|
584 | |
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 | private end;
|
591 | |
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 | resolve(prefix: string): string | undefined;
|
599 | |
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 | private qname;
|
607 | private processAttribsNS;
|
608 | private processAttribsPlain;
|
609 | |
610 |
|
611 |
|
612 |
|
613 |
|
614 | private openTag;
|
615 | |
616 |
|
617 |
|
618 |
|
619 |
|
620 | private openSelfClosingTag;
|
621 | |
622 |
|
623 |
|
624 |
|
625 |
|
626 | private closeTag;
|
627 | |
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 | private parseEntity;
|
635 | }
|