Add node modules and compiled JavaScript from main
This commit is contained in:
parent
8bccaeaf7c
commit
4181bfdf50
7465 changed files with 1775003 additions and 2 deletions
323
node_modules/saxes/README.md
generated
vendored
Normal file
323
node_modules/saxes/README.md
generated
vendored
Normal file
|
@ -0,0 +1,323 @@
|
|||
# saxes
|
||||
|
||||
A sax-style non-validating parser for XML.
|
||||
|
||||
Saxes is a fork of [sax](https://github.com/isaacs/sax-js) 1.2.4. All mentions
|
||||
of sax in this project's documentation are references to sax 1.2.4.
|
||||
|
||||
Designed with [node](http://nodejs.org/) in mind, but should work fine in the
|
||||
browser or other CommonJS implementations.
|
||||
|
||||
Saxes does not support Node versions older than 10.
|
||||
|
||||
## Notable Differences from Sax.
|
||||
|
||||
* Saxes aims to be much stricter than sax with regards to XML
|
||||
well-formedness. Sax, even in its so-called "strict mode", is not strict. It
|
||||
silently accepts structures that are not well-formed XML. Projects that need
|
||||
better compliance with well-formedness constraints cannot use sax as-is.
|
||||
|
||||
Consequently, saxes does not support HTML, or pseudo-XML, or bad XML. Saxes
|
||||
will report well-formedness errors in all these cases but it won't try to
|
||||
extract data from malformed documents like sax does.
|
||||
|
||||
* Saxes is much much faster than sax, mostly because of a substantial redesign
|
||||
of the internal parsing logic. The speed improvement is not merely due to
|
||||
removing features that were supported by sax. That helped a bit, but saxes
|
||||
adds some expensive checks in its aim for conformance with the XML
|
||||
specification. Redesigning the parsing logic is what accounts for most of the
|
||||
performance improvement.
|
||||
|
||||
* Saxes does not aim to support antiquated platforms. We will not pollute the
|
||||
source or the default build with support for antiquated platforms. If you want
|
||||
support for IE 11, you are welcome to produce a PR that adds a *new build*
|
||||
transpiled to ES5.
|
||||
|
||||
* Saxes handles errors differently from sax: it provides a default onerror
|
||||
handler which throws. You can replace it with your own handler if you want. If
|
||||
your handler does nothing, there is no `resume` method to call.
|
||||
|
||||
* There's no `Stream` API. A revamped API may be introduced later. (It is still
|
||||
a "streaming parser" in the general sense that you write a character stream to
|
||||
it.)
|
||||
|
||||
* Saxes does not have facilities for limiting the size the data chunks passed to
|
||||
event handlers. See the FAQ entry for more details.
|
||||
|
||||
## Conformance
|
||||
|
||||
Saxes supports:
|
||||
|
||||
* [XML 1.0 fifth edition](https://www.w3.org/TR/2008/REC-xml-20081126/)
|
||||
* [XML 1.1 second edition](https://www.w3.org/TR/2006/REC-xml11-20060816/)
|
||||
* [Namespaces in XML 1.0 (Third Edition)](https://www.w3.org/TR/2009/REC-xml-names-20091208/).
|
||||
* [Namespaces in XML 1.1 (Second Edition)](https://www.w3.org/TR/2006/REC-xml-names11-20060816/).
|
||||
|
||||
## Limitations
|
||||
|
||||
This is a non-validating parser so it only verifies whether the document is
|
||||
well-formed. We do aim to raise errors for all malformed constructs
|
||||
encountered. However, this parser does not thorougly parse the contents of
|
||||
DTDs. So most malformedness errors caused by errors **in DTDs** cannot be
|
||||
reported.
|
||||
|
||||
## Regarding `<!DOCTYPE` and `<!ENTITY`
|
||||
|
||||
The parser will handle the basic XML entities in text nodes and attribute
|
||||
values: `& < > ' "`. It's possible to define additional
|
||||
entities in XML by putting them in the DTD. This parser doesn't do anything with
|
||||
that. If you want to listen to the `doctype` event, and then fetch the
|
||||
doctypes, and read the entities and add them to `parser.ENTITIES`, then be my
|
||||
guest.
|
||||
|
||||
## Documentation
|
||||
|
||||
The source code contains JSDOC comments. Use them. What follows is a brief
|
||||
summary of what is available. The final authority is the source code.
|
||||
|
||||
**PAY CLOSE ATTENTION TO WHAT IS PUBLIC AND WHAT IS PRIVATE.**
|
||||
|
||||
The move to TypeScript makes it so that everything is now formally private,
|
||||
protected, or public.
|
||||
|
||||
If you use anything not public, that's at your own peril.
|
||||
|
||||
If there's a mistake in the documentation, raise an issue. If you just assume,
|
||||
you may assume incorrectly.
|
||||
|
||||
## Summary Usage Information
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
var saxes = require("./lib/saxes"),
|
||||
parser = new saxes.SaxesParser();
|
||||
|
||||
parser.on("error", function (e) {
|
||||
// an error happened.
|
||||
});
|
||||
parser.on("text", function (t) {
|
||||
// got some text. t is the string of text.
|
||||
});
|
||||
parser.on("opentag", function (node) {
|
||||
// opened a tag. node has "name" and "attributes"
|
||||
});
|
||||
parser.on("end", function () {
|
||||
// parser stream is done, and ready to have more stuff written to it.
|
||||
});
|
||||
|
||||
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close();
|
||||
```
|
||||
|
||||
### Constructor Arguments
|
||||
|
||||
Settings supported:
|
||||
|
||||
* `xmlns` - Boolean. If `true`, then namespaces are supported. Default
|
||||
is `false`.
|
||||
|
||||
* `position` - Boolean. If `false`, then don't track line/col/position. Unset is
|
||||
treated as `true`. Default is unset. Currently, setting this to `false` only
|
||||
results in a cosmetic change: the errors reported do not contain position
|
||||
information. sax-js would literally turn off the position-computing logic if
|
||||
this flag was set to false. The notion was that it would optimize
|
||||
execution. In saxes at least it turns out that continually testing this flag
|
||||
causes a cost that offsets the benefits of turning off this logic.
|
||||
|
||||
* `fileName` - String. Set a file name for error reporting. This is useful only
|
||||
when tracking positions. You may leave it unset.
|
||||
|
||||
* `fragment` - Boolean. If `true`, parse the XML as an XML fragment. Default is
|
||||
`false`.
|
||||
|
||||
* `additionalNamespaces` - A plain object whose key, value pairs define
|
||||
namespaces known before parsing the XML file. It is not legal to pass
|
||||
bindings for the namespaces `"xml"` or `"xmlns"`.
|
||||
|
||||
* `defaultXMLVersion` - The default version of the XML specification to use if
|
||||
the document contains no XML declaration. If the document does contain an XML
|
||||
declaration, then this setting is ignored. Must be `"1.0"` or `"1.1"`. The
|
||||
default is `"1.0"`.
|
||||
|
||||
* `forceXMLVersion` - Boolean. A flag indicating whether to force the XML
|
||||
version used for parsing to the value of ``defaultXMLVersion``. When this flag
|
||||
is ``true``, ``defaultXMLVersion`` must be specified. If unspecified, the
|
||||
default value of this flag is ``false``.
|
||||
|
||||
Example: suppose you are parsing a document that has an XML declaration
|
||||
specifying XML version 1.1.
|
||||
|
||||
If you set ``defaultXMLVersion`` to ``"1.0"`` without setting
|
||||
``forceXMLVersion`` then the XML declaration will override the value of
|
||||
``defaultXMLVersion`` and the document will be parsed according to XML 1.1.
|
||||
|
||||
If you set ``defaultXMLVersion`` to ``"1.0"`` and set ``forceXMLVersion`` to
|
||||
``true``, then the XML declaration will be ignored and the document will be
|
||||
parsed according to XML 1.0.
|
||||
|
||||
### Methods
|
||||
|
||||
`write` - Write bytes onto the stream. You don't have to pass the whole document
|
||||
in one `write` call. You can read your source chunk by chunk and call `write`
|
||||
with each chunk.
|
||||
|
||||
`close` - Close the stream. Once closed, no more data may be written until it is
|
||||
done processing the buffer, which is signaled by the `end` event.
|
||||
|
||||
### Properties
|
||||
|
||||
The parser has the following properties:
|
||||
|
||||
`line`, `column`, `columnIndex`, `position` - Indications of the position in the
|
||||
XML document where the parser currently is looking. The `columnIndex` property
|
||||
counts columns as if indexing into a JavaScript string, whereas the `column`
|
||||
property counts Unicode characters.
|
||||
|
||||
`closed` - Boolean indicating whether or not the parser can be written to. If
|
||||
it's `true`, then wait for the `ready` event to write again.
|
||||
|
||||
`opt` - Any options passed into the constructor.
|
||||
|
||||
`xmlDecl` - The XML declaration for this document. It contains the fields
|
||||
`version`, `encoding` and `standalone`. They are all `undefined` before
|
||||
encountering the XML declaration. If they are undefined after the XML
|
||||
declaration, the corresponding value was not set by the declaration. There is no
|
||||
event associated with the XML declaration. In a well-formed document, the XML
|
||||
declaration may be preceded only by an optional BOM. So by the time any event
|
||||
generated by the parser happens, the declaration has been processed if present
|
||||
at all. Otherwise, you have a malformed document, and as stated above, you
|
||||
cannot rely on the parser data!
|
||||
|
||||
### Error Handling
|
||||
|
||||
The parser continues to parse even upon encountering errors, and does its best
|
||||
to continue reporting errors. You should heed all errors reported. After an
|
||||
error, however, saxes may interpret your document incorrectly. For instance
|
||||
``<foo a=bc="d"/>`` is invalid XML. Did you mean to have ``<foo a="bc=d"/>`` or
|
||||
``<foo a="b" c="d"/>`` or some other variation? For the sake of continuing to
|
||||
provide errors, saxes will continue parsing the document, but the structure it
|
||||
reports may be incorrect. It is only after the errors are fixed in the document
|
||||
that saxes can provide a reliable interpretation of the document.
|
||||
|
||||
That leaves you with two rules of thumb when using saxes:
|
||||
|
||||
* Pay attention to the errors that saxes report. The default `onerror` handler
|
||||
throws, so by default, you cannot miss errors.
|
||||
|
||||
* **ONCE AN ERROR HAS BEEN ENCOUNTERED, STOP RELYING ON THE EVENT HANDLERS OTHER
|
||||
THAN `onerror`.** As explained above, when saxes runs into a well-formedness
|
||||
problem, it makes a guess in order to continue reporting more errors. The guess
|
||||
may be wrong.
|
||||
|
||||
### Events
|
||||
|
||||
To listen to an event, override `on<eventname>`. The list of supported events
|
||||
are also in the exported `EVENTS` array.
|
||||
|
||||
See the JSDOC comments in the source code for a description of each supported
|
||||
event.
|
||||
|
||||
### Parsing XML Fragments
|
||||
|
||||
The XML specification does not define any method by which to parse XML
|
||||
fragments. However, there are usage scenarios in which it is desirable to parse
|
||||
fragments. In order to allow this, saxes provides three initialization options.
|
||||
|
||||
If you pass the option `fragment: true` to the parser constructor, the parser
|
||||
will expect an XML fragment. It essentially starts with a parsing state
|
||||
equivalent to the one it would be in if `parser.write("<foo">)` had been called
|
||||
right after initialization. In other words, it expects content which is
|
||||
acceptable inside an element. This also turns off well-formedness checks that
|
||||
are inappropriate when parsing a fragment.
|
||||
|
||||
The option `additionalNamespaces` allows you to define additional prefix-to-URI
|
||||
bindings known before parsing starts. You would use this over `resolvePrefix` if
|
||||
you have at the ready a series of namespaces bindings to use.
|
||||
|
||||
The option `resolvePrefix` allows you to pass a function which saxes will use if
|
||||
it is unable to resolve a namespace prefix by itself. You would use this over
|
||||
`additionalNamespaces` in a context where getting a complete list of defined
|
||||
namespaces is onerous.
|
||||
|
||||
Note that you can use `additionalNamespaces` and `resolvePrefix` together if you
|
||||
want. `additionalNamespaces` applies before `resolvePrefix`.
|
||||
|
||||
The options `additionalNamespaces` and `resolvePrefix` are really meant to be
|
||||
used for parsing fragments. However, saxes won't prevent you from using them
|
||||
with `fragment: false`. Note that if you do this, your document may parse
|
||||
without errors and yet be malformed because the document can refer to namespaces
|
||||
which are not defined *in* the document.
|
||||
|
||||
Of course, `additionalNamespaces` and `resolvePrefix` are used only if `xmlns`
|
||||
is `true`. If you are parsing a fragment that does not use namespaces, there's
|
||||
no point in setting these options.
|
||||
|
||||
### Performance Tips
|
||||
|
||||
* saxes works faster on files that use newlines (``\u000A``) as end of line
|
||||
markers than files that use other end of line markers (like ``\r`` or
|
||||
``\r\n``). The XML specification requires that conformant applications behave
|
||||
as if all characters that are to be treated as end of line characters are
|
||||
converted to ``\u000A`` prior to parsing. The optimal code path for saxes is a
|
||||
file in which all end of line characters are already ``\u000A``.
|
||||
|
||||
* Don't split Unicode strings you feed to saxes across surrogates. When you
|
||||
naively split a string in JavaScript, you run the risk of splitting a Unicode
|
||||
character into two surrogates. e.g. In the following example ``a`` and ``b``
|
||||
each contain half of a single Unicode character: ``const a = "\u{1F4A9}"[0];
|
||||
const b = "\u{1F4A9}"[1]`` If you feed such split surrogates to versions of
|
||||
saxes prior to 4, you'd get errors. Saxes version 4 and over are able to
|
||||
detect when a chunk of data ends with a surrogate and carry over the surrogate
|
||||
to the next chunk. However this operation entails slicing and concatenating
|
||||
strings. If you can feed your data in a way that does not split surrogates,
|
||||
you should do it. (Obviously, feeding all the data at once with a single write
|
||||
is fastest.)
|
||||
|
||||
* Don't set event handlers you don't need. Saxes has always aimed to avoid doing
|
||||
work that will just be tossed away but future improvements hope to do this
|
||||
more aggressively. One way saxes knows whether or not some data is needed is
|
||||
by checking whether a handler has been set for a specific event.
|
||||
|
||||
## FAQ
|
||||
|
||||
Q. Why has saxes dropped support for limiting the size of data chunks passed to
|
||||
event handlers?
|
||||
|
||||
A. With sax you could set ``MAX_BUFFER_LENGTH`` to cause the parser to limit the
|
||||
size of data chunks passed to event handlers. So if you ran into a span of text
|
||||
above the limit, multiple ``text`` events with smaller data chunks were fired
|
||||
instead of a single event with a large chunk.
|
||||
|
||||
However, that functionality had some problematic characteristics. It had an
|
||||
arbitrary default value. It was library-wide so all parsers created from a
|
||||
single instance of the ``sax`` library shared it. This could potentially cause
|
||||
conflicts among libraries running in the same VM but using sax for different
|
||||
purposes.
|
||||
|
||||
These issues could have been easily fixed, but there were larger issues. The
|
||||
buffer limit arbitrarily applied to some events but not others. It would split
|
||||
``text``, ``cdata`` and ``script`` events. However, if a ``comment``,
|
||||
``doctype``, ``attribute`` or ``processing instruction`` were more than the
|
||||
limit, the parser would generate an error and you were left picking up the
|
||||
pieces.
|
||||
|
||||
It was not intuitive to use. You'd think setting the limit to 1K would prevent
|
||||
chunks bigger than 1K to be passed to event handlers. But that was not the
|
||||
case. A comment in the source code told you that you might go over the limit if
|
||||
you passed large chunks to ``write``. So if you want a 1K limit, don't pass 64K
|
||||
chunks to ``write``. Fair enough. You know what limit you want so you can
|
||||
control the size of the data you pass to ``write``. So you limit the chunks to
|
||||
``write`` to 1K at a time. Even if you do this, your event handlers may get data
|
||||
chunks that are 2K in size. Suppose on the previous ``write`` the parser has
|
||||
just finished processing an open tag, so it is ready for text. Your ``write``
|
||||
passes 1K of text. You are not above the limit yet, so no event is generated
|
||||
yet. The next ``write`` passes another 1K of text. It so happens that sax checks
|
||||
buffer limits only once per ``write``, after the chunk of data has been
|
||||
processed. Now you've hit the limit and you get a ``text`` event with 2K of
|
||||
data. So even if you limit your ``write`` calls to the buffer limit you've set,
|
||||
you may still get events with chunks at twice the buffer size limit you've
|
||||
specified.
|
||||
|
||||
We may consider reinstating an equivalent functionality, provided that it
|
||||
addresses the issues above and does not cause a huge performance drop for
|
||||
use-case scenarios that don't need it.
|
70
node_modules/saxes/package.json
generated
vendored
Normal file
70
node_modules/saxes/package.json
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"name": "saxes",
|
||||
"description": "An evented streaming XML parser in JavaScript",
|
||||
"author": "Louis-Dominique Dubeau <ldd@lddubeau.com>",
|
||||
"version": "5.0.1",
|
||||
"main": "saxes.js",
|
||||
"types": "saxes.d.ts",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"tsc": "tsc",
|
||||
"copy": "cp -p README.md build/dist && sed -e'/\"private\": true/d' package.json > build/dist/package.json",
|
||||
"build": "npm run tsc && npm run copy",
|
||||
"test": "npm run build && mocha --delay",
|
||||
"lint": "eslint --ignore-path .gitignore '**/*.ts' '**/*.js'",
|
||||
"lint-fix": "npm run lint -- --fix",
|
||||
"posttest": "npm run lint",
|
||||
"typedoc": "typedoc --tsconfig tsconfig.json --name saxes --out build/docs/ --listInvalidSymbolLinks --excludePrivate --excludeNotExported",
|
||||
"build-docs": "npm run typedoc",
|
||||
"gh-pages": "npm run build-docs && mkdir -p build && (cd build; rm -rf gh-pages; git clone .. --branch gh-pages gh-pages) && mkdir -p build/gh-pages/latest && find build/gh-pages/latest -type f -delete && cp -rp build/docs/* build/gh-pages/latest && find build/gh-pages -type d -empty -delete",
|
||||
"self:publish": "cd build/dist && npm_config_tag=`simple-dist-tag` npm publish",
|
||||
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
|
||||
"postversion": "npm run test && npm run self:publish",
|
||||
"postpublish": "git push origin --follow-tags"
|
||||
},
|
||||
"repository": "https://github.com/lddubeau/saxes.git",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^8.3.5",
|
||||
"@commitlint/config-angular": "^8.3.4",
|
||||
"@types/chai": "^4.2.11",
|
||||
"@types/mocha": "^7.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "^2.27.0",
|
||||
"@typescript-eslint/eslint-plugin-tslint": "^2.27.0",
|
||||
"@typescript-eslint/parser": "^2.27.0",
|
||||
"@xml-conformance-suite/js": "^2.0.0",
|
||||
"@xml-conformance-suite/mocha": "^2.0.0",
|
||||
"@xml-conformance-suite/test-data": "^2.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"conventional-changelog-cli": "^2.0.31",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-lddubeau-base": "^5.2.0",
|
||||
"eslint-config-lddubeau-ts": "^1.1.7",
|
||||
"eslint-import-resolver-typescript": "^2.0.0",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.3",
|
||||
"eslint-plugin-prefer-arrow": "^1.2.0",
|
||||
"eslint-plugin-react": "^7.19.0",
|
||||
"eslint-plugin-simple-import-sort": "^5.0.2",
|
||||
"husky": "^4.2.5",
|
||||
"mocha": "^7.1.1",
|
||||
"renovate-config-lddubeau": "^1.0.0",
|
||||
"simple-dist-tag": "^1.0.2",
|
||||
"ts-node": "^8.8.2",
|
||||
"tsd": "^0.11.0",
|
||||
"tslint": "^6.1.1",
|
||||
"tslint-microsoft-contrib": "^6.2.0",
|
||||
"typedoc": "^0.17.4",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"xmlchars": "^2.2.0"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
||||
}
|
||||
}
|
||||
}
|
635
node_modules/saxes/saxes.d.ts
generated
vendored
Normal file
635
node_modules/saxes/saxes.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,635 @@
|
|||
/**
|
||||
* The list of supported events.
|
||||
*/
|
||||
export declare const EVENTS: readonly ["xmldecl", "text", "processinginstruction", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "cdata", "error", "end", "ready"];
|
||||
/**
|
||||
* Event handler for the
|
||||
*
|
||||
* @param text The text data encountered by the parser.
|
||||
*
|
||||
*/
|
||||
export declare type XMLDeclHandler = (decl: XMLDecl) => void;
|
||||
/**
|
||||
* Event handler for text data.
|
||||
*
|
||||
* @param text The text data encountered by the parser.
|
||||
*
|
||||
*/
|
||||
export declare type TextHandler = (text: string) => void;
|
||||
/**
|
||||
* Event handler for processing instructions.
|
||||
*
|
||||
* @param data The target and body of the processing instruction.
|
||||
*/
|
||||
export declare type PIHandler = (data: {
|
||||
target: string;
|
||||
body: string;
|
||||
}) => void;
|
||||
/**
|
||||
* Event handler for doctype.
|
||||
*
|
||||
* @param doctype The doctype contents.
|
||||
*/
|
||||
export declare type DoctypeHandler = (doctype: string) => void;
|
||||
/**
|
||||
* Event handler for comments.
|
||||
*
|
||||
* @param comment The comment contents.
|
||||
*/
|
||||
export declare type CommentHandler = (comment: string) => void;
|
||||
/**
|
||||
* Event handler for the start of an open tag. This is called as soon as we
|
||||
* have a tag name.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*/
|
||||
export declare type OpenTagStartHandler<O> = (tag: StartTagForOptions<O>) => void;
|
||||
export declare type AttributeEventForOptions<O extends SaxesOptions> = O extends {
|
||||
xmlns: true;
|
||||
} ? SaxesAttributeNSIncomplete : O extends {
|
||||
xmlns?: false | undefined;
|
||||
} ? SaxesAttributePlain : SaxesAttribute;
|
||||
/**
|
||||
* Event handler for attributes.
|
||||
*/
|
||||
export declare type AttributeHandler<O> = (attribute: AttributeEventForOptions<O>) => void;
|
||||
/**
|
||||
* Event handler for an open tag. This is called when the open tag is
|
||||
* complete. (We've encountered the ">" that ends the open tag.)
|
||||
*
|
||||
* @param tag The tag.
|
||||
*/
|
||||
export declare type OpenTagHandler<O> = (tag: TagForOptions<O>) => void;
|
||||
/**
|
||||
* Event handler for a close tag. Note that for self-closing tags, this is
|
||||
* called right after ``opentag``.
|
||||
*
|
||||
* @param tag The tag.
|
||||
*/
|
||||
export declare type CloseTagHandler<O> = (tag: TagForOptions<O>) => void;
|
||||
/**
|
||||
* Event handler for a CDATA section. This is called when ending the
|
||||
* CDATA section.
|
||||
*
|
||||
* @param cdata The contents of the CDATA section.
|
||||
*/
|
||||
export declare type CDataHandler = (cdata: string) => void;
|
||||
/**
|
||||
* Event handler for the stream end. This is called when the stream has been
|
||||
* closed with ``close`` or by passing ``null`` to ``write``.
|
||||
*/
|
||||
export declare type EndHandler = () => void;
|
||||
/**
|
||||
* Event handler indicating parser readiness . This is called when the parser
|
||||
* is ready to parse a new document.
|
||||
*/
|
||||
export declare type ReadyHandler = () => void;
|
||||
/**
|
||||
* Event handler indicating an error.
|
||||
*
|
||||
* @param err The error that occurred.
|
||||
*/
|
||||
export declare type ErrorHandler = (err: Error) => void;
|
||||
export declare type EventName = (typeof EVENTS)[number];
|
||||
export declare type EventNameToHandler<O, N extends EventName> = {
|
||||
"xmldecl": XMLDeclHandler;
|
||||
"text": TextHandler;
|
||||
"processinginstruction": PIHandler;
|
||||
"doctype": DoctypeHandler;
|
||||
"comment": CommentHandler;
|
||||
"opentagstart": OpenTagStartHandler<O>;
|
||||
"attribute": AttributeHandler<O>;
|
||||
"opentag": OpenTagHandler<O>;
|
||||
"closetag": CloseTagHandler<O>;
|
||||
"cdata": CDataHandler;
|
||||
"error": ErrorHandler;
|
||||
"end": EndHandler;
|
||||
"ready": ReadyHandler;
|
||||
}[N];
|
||||
/**
|
||||
* This interface defines the structure of attributes when the parser is
|
||||
* processing namespaces (created with ``xmlns: true``).
|
||||
*/
|
||||
export interface SaxesAttributeNS {
|
||||
/**
|
||||
* The attribute's name. This is the combination of prefix and local name.
|
||||
* For instance ``a:b="c"`` would have ``a:b`` for name.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The attribute's prefix. For instance ``a:b="c"`` would have ``"a"`` for
|
||||
* ``prefix``.
|
||||
*/
|
||||
prefix: string;
|
||||
/**
|
||||
* The attribute's local name. For instance ``a:b="c"`` would have ``"b"`` for
|
||||
* ``local``.
|
||||
*/
|
||||
local: string;
|
||||
/** The namespace URI of this attribute. */
|
||||
uri: string;
|
||||
/** The attribute's value. */
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* This is an attribute, as recorded by a parser which parses namespaces but
|
||||
* prior to the URI being resolvable. This is what is passed to the attribute
|
||||
* event handler.
|
||||
*/
|
||||
export declare type SaxesAttributeNSIncomplete = Exclude<SaxesAttributeNS, "uri">;
|
||||
/**
|
||||
* This interface defines the structure of attributes when the parser is
|
||||
* NOT processing namespaces (created with ``xmlns: false``).
|
||||
*/
|
||||
export interface SaxesAttributePlain {
|
||||
/**
|
||||
* The attribute's name.
|
||||
*/
|
||||
name: string;
|
||||
/** The attribute's value. */
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* A saxes attribute, with or without namespace information.
|
||||
*/
|
||||
export declare type SaxesAttribute = SaxesAttributeNS | SaxesAttributePlain;
|
||||
/**
|
||||
* This are the fields that MAY be present on a complete tag.
|
||||
*/
|
||||
export interface SaxesTag {
|
||||
/**
|
||||
* The tag's name. This is the combination of prefix and global name. For
|
||||
* instance ``<a:b>`` would have ``"a:b"`` for ``name``.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* A map of attribute name to attributes. If namespaces are tracked, the
|
||||
* values in the map are attribute objects. Otherwise, they are strings.
|
||||
*/
|
||||
attributes: Record<string, SaxesAttributeNS> | Record<string, string>;
|
||||
/**
|
||||
* The namespace bindings in effect.
|
||||
*/
|
||||
ns?: Record<string, string>;
|
||||
/**
|
||||
* The tag's prefix. For instance ``<a:b>`` would have ``"a"`` for
|
||||
* ``prefix``. Undefined if we do not track namespaces.
|
||||
*/
|
||||
prefix?: string;
|
||||
/**
|
||||
* The tag's local name. For instance ``<a:b>`` would
|
||||
* have ``"b"`` for ``local``. Undefined if we do not track namespaces.
|
||||
*/
|
||||
local?: string;
|
||||
/**
|
||||
* The namespace URI of this tag. Undefined if we do not track namespaces.
|
||||
*/
|
||||
uri?: string;
|
||||
/** Whether the tag is self-closing (e.g. ``<foo/>``). */
|
||||
isSelfClosing: boolean;
|
||||
}
|
||||
/**
|
||||
* This type defines the fields that are present on a tag object when
|
||||
* ``onopentagstart`` is called. This interface is namespace-agnostic.
|
||||
*/
|
||||
export declare type SaxesStartTag = Pick<SaxesTag, "name" | "attributes" | "ns">;
|
||||
/**
|
||||
* This type defines the fields that are present on a tag object when
|
||||
* ``onopentagstart`` is called on a parser that does not processes namespaces.
|
||||
*/
|
||||
export declare type SaxesStartTagPlain = Pick<SaxesStartTag, "name" | "attributes">;
|
||||
/**
|
||||
* This type defines the fields that are present on a tag object when
|
||||
* ``onopentagstart`` is called on a parser that does process namespaces.
|
||||
*/
|
||||
export declare type SaxesStartTagNS = Required<SaxesStartTag>;
|
||||
/**
|
||||
* This are the fields that are present on a complete tag produced by a parser
|
||||
* that does process namespaces.
|
||||
*/
|
||||
export declare type SaxesTagNS = Required<SaxesTag> & {
|
||||
attributes: Record<string, SaxesAttributeNS>;
|
||||
};
|
||||
/**
|
||||
* This are the fields that are present on a complete tag produced by a parser
|
||||
* that does not process namespaces.
|
||||
*/
|
||||
export declare type SaxesTagPlain = Pick<SaxesTag, "name" | "attributes" | "isSelfClosing"> & {
|
||||
attributes: Record<string, string>;
|
||||
};
|
||||
/**
|
||||
* An XML declaration.
|
||||
*/
|
||||
export interface XMLDecl {
|
||||
/** The version specified by the XML declaration. */
|
||||
version?: string;
|
||||
/** The encoding specified by the XML declaration. */
|
||||
encoding?: string;
|
||||
/** The value of the standalone parameter */
|
||||
standalone?: string;
|
||||
}
|
||||
/**
|
||||
* A callback for resolving name prefixes.
|
||||
*
|
||||
* @param prefix The prefix to check.
|
||||
*
|
||||
* @returns The URI corresponding to the prefix, if any.
|
||||
*/
|
||||
export declare type ResolvePrefix = (prefix: string) => string | undefined;
|
||||
export interface CommonOptions {
|
||||
/** Whether to accept XML fragments. Unset means ``false``. */
|
||||
fragment?: boolean;
|
||||
/** Whether to track positions. Unset means ``true``. */
|
||||
position?: boolean;
|
||||
/**
|
||||
* A file name to use for error reporting. "File name" is a loose concept. You
|
||||
* could use a URL to some resource, or any descriptive name you like.
|
||||
*/
|
||||
fileName?: string;
|
||||
}
|
||||
export interface NSOptions {
|
||||
/** Whether to track namespaces. Unset means ``false``. */
|
||||
xmlns?: boolean;
|
||||
/**
|
||||
* A plain object whose key, value pairs define namespaces known before
|
||||
* parsing the XML file. It is not legal to pass bindings for the namespaces
|
||||
* ``"xml"`` or ``"xmlns"``.
|
||||
*/
|
||||
additionalNamespaces?: Record<string, string>;
|
||||
/**
|
||||
* A function that will be used if the parser cannot resolve a namespace
|
||||
* prefix on its own.
|
||||
*/
|
||||
resolvePrefix?: ResolvePrefix;
|
||||
}
|
||||
export interface NSOptionsWithoutNamespaces extends NSOptions {
|
||||
xmlns?: false;
|
||||
additionalNamespaces?: undefined;
|
||||
resolvePrefix?: undefined;
|
||||
}
|
||||
export interface NSOptionsWithNamespaces extends NSOptions {
|
||||
xmlns: true;
|
||||
}
|
||||
export interface XMLVersionOptions {
|
||||
/**
|
||||
* The default XML version to use. If unspecified, and there is no XML
|
||||
* encoding declaration, the default version is "1.0".
|
||||
*/
|
||||
defaultXMLVersion?: "1.0" | "1.1";
|
||||
/**
|
||||
* A flag indicating whether to force the XML version used for parsing to the
|
||||
* value of ``defaultXMLVersion``. When this flag is ``true``,
|
||||
* ``defaultXMLVersion`` must be specified. If unspecified, the default value
|
||||
* of this flag is ``false``.
|
||||
*/
|
||||
forceXMLVersion?: boolean;
|
||||
}
|
||||
export interface NoForcedXMLVersion extends XMLVersionOptions {
|
||||
forceXMLVersion?: false;
|
||||
}
|
||||
export interface ForcedXMLVersion extends XMLVersionOptions {
|
||||
forceXMLVersion: true;
|
||||
defaultXMLVersion: Exclude<XMLVersionOptions["defaultXMLVersion"], undefined>;
|
||||
}
|
||||
/**
|
||||
* The entire set of options supported by saxes.
|
||||
*/
|
||||
export declare type SaxesOptions = CommonOptions & NSOptions & XMLVersionOptions;
|
||||
export declare type TagForOptions<O extends SaxesOptions> = O extends {
|
||||
xmlns: true;
|
||||
} ? SaxesTagNS : O extends {
|
||||
xmlns?: false | undefined;
|
||||
} ? SaxesTagPlain : SaxesTag;
|
||||
export declare type StartTagForOptions<O extends SaxesOptions> = O extends {
|
||||
xmlns: true;
|
||||
} ? SaxesStartTagNS : O extends {
|
||||
xmlns?: false | undefined;
|
||||
} ? SaxesStartTagPlain : SaxesStartTag;
|
||||
export declare class SaxesParser<O extends SaxesOptions = {}> {
|
||||
private readonly fragmentOpt;
|
||||
private readonly xmlnsOpt;
|
||||
private readonly trackPosition;
|
||||
private readonly fileName?;
|
||||
private readonly nameStartCheck;
|
||||
private readonly nameCheck;
|
||||
private readonly isName;
|
||||
private readonly ns;
|
||||
private openWakaBang;
|
||||
private text;
|
||||
private name;
|
||||
private piTarget;
|
||||
private entity;
|
||||
private q;
|
||||
private tags;
|
||||
private tag;
|
||||
private topNS;
|
||||
private chunk;
|
||||
private chunkPosition;
|
||||
private i;
|
||||
private prevI;
|
||||
private carriedFromPrevious?;
|
||||
private forbiddenState;
|
||||
private attribList;
|
||||
private state;
|
||||
private reportedTextBeforeRoot;
|
||||
private reportedTextAfterRoot;
|
||||
private closedRoot;
|
||||
private sawRoot;
|
||||
private xmlDeclPossible;
|
||||
private xmlDeclExpects;
|
||||
private entityReturnState?;
|
||||
private processAttribs;
|
||||
private positionAtNewLine;
|
||||
private doctype;
|
||||
private getCode;
|
||||
private isChar;
|
||||
private pushAttrib;
|
||||
private _closed;
|
||||
private currentXMLVersion;
|
||||
private readonly stateTable;
|
||||
private xmldeclHandler?;
|
||||
private textHandler?;
|
||||
private piHandler?;
|
||||
private doctypeHandler?;
|
||||
private commentHandler?;
|
||||
private openTagStartHandler?;
|
||||
private openTagHandler?;
|
||||
private closeTagHandler?;
|
||||
private cdataHandler?;
|
||||
private errorHandler?;
|
||||
private endHandler?;
|
||||
private readyHandler?;
|
||||
private attributeHandler?;
|
||||
/**
|
||||
* Indicates whether or not the parser is closed. If ``true``, wait for
|
||||
* the ``ready`` event to write again.
|
||||
*/
|
||||
get closed(): boolean;
|
||||
readonly opt: SaxesOptions;
|
||||
/**
|
||||
* The XML declaration for this document.
|
||||
*/
|
||||
xmlDecl: XMLDecl;
|
||||
/**
|
||||
* The line number of the next character to be read by the parser. This field
|
||||
* is one-based. (The first line is numbered 1.)
|
||||
*/
|
||||
line: number;
|
||||
/**
|
||||
* The column number of the next character to be read by the parser. *
|
||||
* This field is zero-based. (The first column is 0.)
|
||||
*
|
||||
* This field counts columns by *Unicode character*. Note that this *can*
|
||||
* be different from the index of the character in a JavaScript string due
|
||||
* to how JavaScript handles astral plane characters.
|
||||
*
|
||||
* See [[columnIndex]] for a number that corresponds to the JavaScript index.
|
||||
*/
|
||||
column: number;
|
||||
/**
|
||||
* A map of entity name to expansion.
|
||||
*/
|
||||
ENTITIES: Record<string, string>;
|
||||
/**
|
||||
* @param opt The parser options.
|
||||
*/
|
||||
constructor(opt?: O);
|
||||
_init(): void;
|
||||
/**
|
||||
* The stream position the parser is currently looking at. This field is
|
||||
* zero-based.
|
||||
*
|
||||
* This field is not based on counting Unicode characters but is to be
|
||||
* interpreted as a plain index into a JavaScript string.
|
||||
*/
|
||||
get position(): number;
|
||||
/**
|
||||
* The column number of the next character to be read by the parser. *
|
||||
* This field is zero-based. (The first column in a line is 0.)
|
||||
*
|
||||
* This field reports the index at which the next character would be in the
|
||||
* line if the line were represented as a JavaScript string. Note that this
|
||||
* *can* be different to a count based on the number of *Unicode characters*
|
||||
* due to how JavaScript handles astral plane characters.
|
||||
*
|
||||
* See [[column]] for a number that corresponds to a count of Unicode
|
||||
* characters.
|
||||
*/
|
||||
get columnIndex(): number;
|
||||
/**
|
||||
* Set an event listener on an event. The parser supports one handler per
|
||||
* event type. If you try to set an event handler over an existing handler,
|
||||
* the old handler is silently overwritten.
|
||||
*
|
||||
* @param name The event to listen to.
|
||||
*
|
||||
* @param handler The handler to set.
|
||||
*/
|
||||
on<N extends EventName>(name: N, handler: EventNameToHandler<O, N>): void;
|
||||
/**
|
||||
* Unset an event handler.
|
||||
*
|
||||
* @parma name The event to stop listening to.
|
||||
*/
|
||||
off(name: EventName): void;
|
||||
/**
|
||||
* Make an error object. The error object will have a message that contains
|
||||
* the ``fileName`` option passed at the creation of the parser. If position
|
||||
* tracking was turned on, it will also have line and column number
|
||||
* information.
|
||||
*
|
||||
* @param message The message describing the error to report.
|
||||
*
|
||||
* @returns An error object with a properly formatted message.
|
||||
*/
|
||||
makeError(message: string): Error;
|
||||
/**
|
||||
* Report a parsing error. This method is made public so that client code may
|
||||
* check for issues that are outside the scope of this project and can report
|
||||
* errors.
|
||||
*
|
||||
* @param message The error to report.
|
||||
*
|
||||
* @returns this
|
||||
*/
|
||||
fail(message: string): this;
|
||||
/**
|
||||
* Write a XML data to the parser.
|
||||
*
|
||||
* @param chunk The XML data to write.
|
||||
*
|
||||
* @returns this
|
||||
*/
|
||||
write(chunk: string | {} | null): this;
|
||||
/**
|
||||
* Close the current stream. Perform final well-formedness checks and reset
|
||||
* the parser tstate.
|
||||
*
|
||||
* @returns this
|
||||
*/
|
||||
close(): this;
|
||||
/**
|
||||
* Get a single code point out of the current chunk. This updates the current
|
||||
* position if we do position tracking.
|
||||
*
|
||||
* This is the algorithm to use for XML 1.0.
|
||||
*
|
||||
* @returns The character read.
|
||||
*/
|
||||
private getCode10;
|
||||
/**
|
||||
* Get a single code point out of the current chunk. This updates the current
|
||||
* position if we do position tracking.
|
||||
*
|
||||
* This is the algorithm to use for XML 1.1.
|
||||
*
|
||||
* @returns {number} The character read.
|
||||
*/
|
||||
private getCode11;
|
||||
/**
|
||||
* Like ``getCode`` but with the return value normalized so that ``NL`` is
|
||||
* returned for ``NL_LIKE``.
|
||||
*/
|
||||
private getCodeNorm;
|
||||
private unget;
|
||||
/**
|
||||
* Capture characters into a buffer until encountering one of a set of
|
||||
* characters.
|
||||
*
|
||||
* @param chars An array of codepoints. Encountering a character in the array
|
||||
* ends the capture. (``chars`` may safely contain ``NL``.)
|
||||
*
|
||||
* @return The character code that made the capture end, or ``EOC`` if we hit
|
||||
* the end of the chunk. The return value cannot be NL_LIKE: NL is returned
|
||||
* instead.
|
||||
*/
|
||||
private captureTo;
|
||||
/**
|
||||
* Capture characters into a buffer until encountering a character.
|
||||
*
|
||||
* @param char The codepoint that ends the capture. **NOTE ``char`` MAY NOT
|
||||
* CONTAIN ``NL``.** Passing ``NL`` will result in buggy behavior.
|
||||
*
|
||||
* @return ``true`` if we ran into the character. Otherwise, we ran into the
|
||||
* end of the current chunk.
|
||||
*/
|
||||
private captureToChar;
|
||||
/**
|
||||
* Capture characters that satisfy ``isNameChar`` into the ``name`` field of
|
||||
* this parser.
|
||||
*
|
||||
* @return The character code that made the test fail, or ``EOC`` if we hit
|
||||
* the end of the chunk. The return value cannot be NL_LIKE: NL is returned
|
||||
* instead.
|
||||
*/
|
||||
private captureNameChars;
|
||||
/**
|
||||
* Skip white spaces.
|
||||
*
|
||||
* @return The character that ended the skip, or ``EOC`` if we hit
|
||||
* the end of the chunk. The return value cannot be NL_LIKE: NL is returned
|
||||
* instead.
|
||||
*/
|
||||
private skipSpaces;
|
||||
private setXMLVersion;
|
||||
private sBegin;
|
||||
private sBeginWhitespace;
|
||||
private sDoctype;
|
||||
private sDoctypeQuote;
|
||||
private sDTD;
|
||||
private sDTDQuoted;
|
||||
private sDTDOpenWaka;
|
||||
private sDTDOpenWakaBang;
|
||||
private sDTDComment;
|
||||
private sDTDCommentEnding;
|
||||
private sDTDCommentEnded;
|
||||
private sDTDPI;
|
||||
private sDTDPIEnding;
|
||||
private sText;
|
||||
private sEntity;
|
||||
private sOpenWaka;
|
||||
private sOpenWakaBang;
|
||||
private sComment;
|
||||
private sCommentEnding;
|
||||
private sCommentEnded;
|
||||
private sCData;
|
||||
private sCDataEnding;
|
||||
private sCDataEnding2;
|
||||
private sPIFirstChar;
|
||||
private sPIRest;
|
||||
private sPIBody;
|
||||
private sPIEnding;
|
||||
private sXMLDeclNameStart;
|
||||
private sXMLDeclName;
|
||||
private sXMLDeclEq;
|
||||
private sXMLDeclValueStart;
|
||||
private sXMLDeclValue;
|
||||
private sXMLDeclSeparator;
|
||||
private sXMLDeclEnding;
|
||||
private sOpenTag;
|
||||
private sOpenTagSlash;
|
||||
private sAttrib;
|
||||
private sAttribName;
|
||||
private sAttribNameSawWhite;
|
||||
private sAttribValue;
|
||||
private sAttribValueQuoted;
|
||||
private sAttribValueClosed;
|
||||
private sAttribValueUnquoted;
|
||||
private sCloseTag;
|
||||
private sCloseTagSawWhite;
|
||||
private handleTextInRoot;
|
||||
private handleTextOutsideRoot;
|
||||
private pushAttribNS;
|
||||
private pushAttribPlain;
|
||||
/**
|
||||
* End parsing. This performs final well-formedness checks and resets the
|
||||
* parser to a clean state.
|
||||
*
|
||||
* @returns this
|
||||
*/
|
||||
private end;
|
||||
/**
|
||||
* Resolve a namespace prefix.
|
||||
*
|
||||
* @param prefix The prefix to resolve.
|
||||
*
|
||||
* @returns The namespace URI or ``undefined`` if the prefix is not defined.
|
||||
*/
|
||||
resolve(prefix: string): string | undefined;
|
||||
/**
|
||||
* Parse a qname into its prefix and local name parts.
|
||||
*
|
||||
* @param name The name to parse
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
private qname;
|
||||
private processAttribsNS;
|
||||
private processAttribsPlain;
|
||||
/**
|
||||
* Handle a complete open tag. This parser code calls this once it has seen
|
||||
* the whole tag. This method checks for well-formeness and then emits
|
||||
* ``onopentag``.
|
||||
*/
|
||||
private openTag;
|
||||
/**
|
||||
* Handle a complete self-closing tag. This parser code calls this once it has
|
||||
* seen the whole tag. This method checks for well-formeness and then emits
|
||||
* ``onopentag`` and ``onclosetag``.
|
||||
*/
|
||||
private openSelfClosingTag;
|
||||
/**
|
||||
* Handle a complete close tag. This parser code calls this once it has seen
|
||||
* the whole tag. This method checks for well-formeness and then emits
|
||||
* ``onclosetag``.
|
||||
*/
|
||||
private closeTag;
|
||||
/**
|
||||
* Resolves an entity. Makes any necessary well-formedness checks.
|
||||
*
|
||||
* @param entity The entity to resolve.
|
||||
*
|
||||
* @returns The parsed entity.
|
||||
*/
|
||||
private parseEntity;
|
||||
}
|
2064
node_modules/saxes/saxes.js
generated
vendored
Normal file
2064
node_modules/saxes/saxes.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/saxes/saxes.js.map
generated
vendored
Normal file
1
node_modules/saxes/saxes.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue