@rgrove/parse-xml 4.0.0 → 4.0.1

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/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @rgrove/parse-xml v4.0.0 | ISC License | Copyright Ryan Grove */
1
+ /*! @rgrove/parse-xml v4.0.1 | ISC License | Copyright Ryan Grove */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/lib/StringScanner.ts", "../src/lib/syntax.ts", "../src/lib/XmlNode.ts", "../src/lib/XmlText.ts", "../src/lib/XmlCdata.ts", "../src/lib/XmlComment.ts", "../src/lib/XmlElement.ts", "../src/lib/XmlDocument.ts", "../src/lib/XmlProcessingInstruction.ts", "../src/lib/Parser.ts"],
4
- "sourcesContent": ["import { Parser } from './lib/Parser.js';\n\nimport type { ParserOptions } from './lib/Parser.js';\n\nexport * from './lib/types.js';\nexport { XmlCdata } from './lib/XmlCdata.js';\nexport { XmlComment } from './lib/XmlComment.js';\nexport { XmlDocument } from './lib/XmlDocument.js';\nexport { XmlElement } from './lib/XmlElement.js';\nexport { XmlNode } from './lib/XmlNode.js';\nexport { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';\nexport { XmlText } from './lib/XmlText.js';\n\nexport type { ParserOptions } from './lib/Parser.js';\n\n/**\n * Parses the given XML string and returns an `XmlDocument` instance\n * representing the document tree.\n *\n * @example\n *\n * import { parseXml } from '@rgrove/parse-xml';\n * let doc = parseXml('<kittens fuzzy=\"yes\">I like fuzzy kittens.</kittens>');\n *\n * @param xml XML string to parse.\n * @param options Parser options.\n */\nexport function parseXml(xml: string, options: ParserOptions) {\n return (new Parser(xml, options)).document;\n}\n", "const emptyString = '';\nconst surrogatePair = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\n/** @private */\nexport class StringScanner {\n charIndex: number;\n readonly string: string;\n\n private readonly charCount: number;\n private readonly charsToBytes: number[] | undefined;\n private readonly length: number;\n private readonly multiByteMode: boolean;\n\n constructor(string: string) {\n this.charCount = this.charLength(string, true);\n this.charIndex = 0;\n this.length = string.length;\n this.multiByteMode = this.charCount !== this.length;\n this.string = string;\n\n if (this.multiByteMode) {\n let charsToBytes = [];\n\n // Create a mapping of character indexes to byte indexes. Since the string\n // contains multibyte characters, a byte index may not necessarily align\n // with a character index.\n for (let byteIndex = 0, charIndex = 0; charIndex < this.charCount; ++charIndex) {\n charsToBytes[charIndex] = byteIndex;\n byteIndex += (string.codePointAt(byteIndex) as number) > 65535 ? 2 : 1;\n }\n\n this.charsToBytes = charsToBytes;\n }\n }\n\n /**\n * Whether the current character index is at the end of the input string.\n */\n get isEnd() {\n return this.charIndex >= this.charCount;\n }\n\n // -- Protected Methods ------------------------------------------------------\n\n /**\n * Returns the byte index of the given character index in the string. The two\n * may differ in strings that contain multibyte characters.\n */\n protected charIndexToByteIndex(charIndex: number = this.charIndex): number {\n return this.multiByteMode\n ? (this.charsToBytes as number[])[charIndex] ?? Infinity\n : charIndex;\n }\n\n /**\n * Returns the number of characters in the given string, which may differ from\n * the byte length if the string contains multibyte characters.\n */\n protected charLength(string: string, multiByteSafe = this.multiByteMode): number {\n // We could get the char length with `[ ...string ].length`, but that's\n // actually slower than replacing surrogate pairs with single-byte\n // characters and then counting the result.\n return multiByteSafe\n ? string.replace(surrogatePair, '_').length\n : string.length;\n }\n\n // -- Public Methods ---------------------------------------------------------\n\n /**\n * Advances the scanner by the given number of characters, stopping if the end\n * of the string is reached.\n */\n advance(count = 1) {\n this.charIndex = Math.min(this.charCount, this.charIndex + count);\n }\n\n /**\n * Consumes and returns the given number of characters if possible, advancing\n * the scanner and stopping if the end of the string is reached.\n *\n * If no characters could be consumed, an empty string will be returned.\n */\n consume(count = 1): string {\n let chars = this.peek(count);\n this.advance(count);\n return chars;\n }\n\n /**\n * Consumes a match for the given sticky regex, advances the scanner, updates\n * the `lastIndex` property of the regex, and returns the matching string.\n *\n * The regex must have a sticky flag (\"y\") so that its `lastIndex` prop can be\n * used to anchor the match at the current scanner position.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeMatch(regex: RegExp): string {\n if (!regex.sticky) {\n throw new Error('`regex` must have a sticky flag (\"y\")');\n }\n\n regex.lastIndex = this.charIndexToByteIndex();\n\n let result = regex.exec(this.string);\n\n if (result === null || result.length === 0) {\n return emptyString;\n }\n\n let match = result[0] as string;\n this.advance(this.charLength(match));\n return match;\n }\n\n /**\n * Consumes and returns all characters for which the given function returns a\n * truthy value, stopping on the first falsy return value or if the end of the\n * input is reached.\n */\n consumeMatchFn(fn: (char: string) => boolean): string {\n let char;\n let match = emptyString;\n\n while ((char = this.peek()) && fn(char)) {\n match += char;\n this.advance();\n }\n\n return match;\n }\n\n /**\n * Consumes the given string if it exists at the current character index, and\n * advances the scanner.\n *\n * If the given string doesn't exist at the current character index, an empty\n * string will be returned and the scanner will not be advanced.\n */\n consumeString(stringToConsume: string): string {\n if (this.consumeStringFast(stringToConsume)) {\n return stringToConsume;\n }\n\n if (this.multiByteMode) {\n let { length } = stringToConsume;\n let charLengthToMatch = this.charLength(stringToConsume);\n\n if (charLengthToMatch !== length\n && stringToConsume === this.peek(charLengthToMatch)) {\n\n this.advance(charLengthToMatch);\n return stringToConsume;\n }\n }\n\n return emptyString;\n }\n\n /**\n * Does the same thing as `consumeString()`, but doesn't support consuming\n * multibyte characters. This can be faster if you only need to match single\n * byte characters.\n */\n consumeStringFast(stringToConsume: string): string {\n let { length } = stringToConsume;\n\n if (this.peek(length) === stringToConsume) {\n this.advance(length);\n return stringToConsume;\n }\n\n return emptyString;\n }\n\n /**\n * Consumes characters until the given global regex is matched, advancing the\n * scanner up to (but not beyond) the beginning of the match. If the regex\n * doesn't match, nothing will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilMatch(regex: RegExp): string {\n let restOfString = this.string.slice(this.charIndexToByteIndex());\n let matchByteIndex = restOfString.search(regex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = restOfString.slice(0, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Consumes characters until the given string is found, advancing the scanner\n * up to (but not beyond) that point. If the string is never found, nothing\n * will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilString(searchString: string): string {\n let { string } = this;\n let byteIndex = this.charIndexToByteIndex();\n let matchByteIndex = string.indexOf(searchString, byteIndex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = string.slice(byteIndex, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Returns the given number of characters starting at the current character\n * index, without advancing the scanner and without exceeding the end of the\n * input string.\n */\n peek(count = 1): string {\n let { charIndex, multiByteMode, string } = this;\n\n if (multiByteMode) {\n // Inlining this comparison instead of checking `this.isEnd` improves perf\n // slightly since `peek()` is called so frequently.\n if (charIndex >= this.charCount) {\n return emptyString;\n }\n\n return string.slice(\n this.charIndexToByteIndex(charIndex),\n this.charIndexToByteIndex(charIndex + count),\n );\n }\n\n return string.slice(charIndex, charIndex + count);\n }\n\n /**\n * Resets the scanner position to the given character _index_, or to the start\n * of the input string if no index is given.\n *\n * If _index_ is negative, the scanner position will be moved backward by that\n * many characters, stopping if the beginning of the string is reached.\n */\n reset(index = 0) {\n this.charIndex = index >= 0\n ? Math.min(this.charCount, index)\n : Math.max(0, this.charIndex + index);\n }\n}\n", "/**\n * Regular expression that matches one or more `AttValue` characters in a\n * double-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharDoubleQuote = /[^\"&<]+/y;\n\n/**\n * Regular expression that matches one or more `AttValue` characters in a\n * single-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharSingleQuote = /[^'&<]+/y;\n\n/**\n * Regular expression that matches a whitespace character that should be\n * normalized to a space character in an attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize\n */\nexport const attValueNormalizedWhitespace = /[\\t\\n]/g;\n\n/**\n * Regular expression that matches one or more characters that signal the end of\n * XML `CharData` content.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\nexport const endCharData = /<|&|]]>/;\n\n/**\n * Mapping of predefined entity names to their replacement values.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent\n */\nexport const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {\n amp: '&',\n apos: \"'\",\n gt: '>',\n lt: '<',\n quot: '\"',\n}));\n\n/**\n * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar\n */\nexport function isNameChar(char: string): boolean {\n let cp = getCodePoint(char);\n\n // Including the most common NameStartChars here improves performance\n // slightly.\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || (cp >= 0x30 && cp <= 0x39) // 0-9\n || cp === 0x2D // -\n || cp === 0x2E // .\n || cp === 0xB7\n || (cp >= 0x300 && cp <= 0x36F)\n || (cp >= 0x203F && cp <= 0x2040)\n || isNameStartChar(char, cp);\n}\n\n/**\n * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar\n */\nexport function isNameStartChar(char: string, cp = getCodePoint(char)): boolean {\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || cp === 0x3A // :\n || cp === 0x5F // _\n || (cp >= 0xC0 && cp <= 0xD6)\n || (cp >= 0xD8 && cp <= 0xF6)\n || (cp >= 0xF8 && cp <= 0x2FF)\n || (cp >= 0x370 && cp <= 0x37D)\n || (cp >= 0x37F && cp <= 0x1FFF)\n || (cp >= 0x200C && cp <= 0x200D)\n || (cp >= 0x2070 && cp <= 0x218F)\n || (cp >= 0x2C00 && cp <= 0x2FEF)\n || (cp >= 0x3001 && cp <= 0xD7FF)\n || (cp >= 0xF900 && cp <= 0xFDCF)\n || (cp >= 0xFDF0 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0xEFFFF);\n}\n\n/**\n * Returns `true` if _char_ is a valid reference character (which may appear\n * between `&` and `;` in a reference), `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references\n */\nexport function isReferenceChar(char: string): boolean {\n return char === '#' || isNameChar(char);\n}\n\n/**\n * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\nexport function isWhitespace(char: string): boolean {\n let cp = getCodePoint(char);\n\n return cp === 0x20\n || cp === 0x9\n || cp === 0xA\n || cp === 0xD;\n}\n\n/**\n * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`\n * otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char\n */\nexport function isXmlCodePoint(cp: number): boolean {\n return cp === 0x9\n || cp === 0xA\n || cp === 0xD\n || (cp >= 0x20 && cp <= 0xD7FF)\n || (cp >= 0xE000 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0x10FFFF);\n}\n\n/**\n * Returns the Unicode code point value of the given character, or `-1` if\n * _char_ is empty.\n */\nfunction getCodePoint(char: string): number {\n return char.codePointAt(0) || -1;\n}\n", "import type { JsonObject } from './types.js';\nimport type { XmlDocument } from './XmlDocument.js';\nimport type { XmlElement } from './XmlElement.js';\n\n/**\n * Base interface for a node in an XML document.\n */\nexport class XmlNode {\n /**\n * Type value for an `XmlCdata` node.\n */\n static readonly TYPE_CDATA = 'cdata';\n\n /**\n * Type value for an `XmlComment` node.\n */\n static readonly TYPE_COMMENT = 'comment';\n\n /**\n * Type value for an `XmlDocument` node.\n */\n static readonly TYPE_DOCUMENT = 'document';\n\n /**\n * Type value for an `XmlElement` node.\n */\n static readonly TYPE_ELEMENT = 'element';\n\n /**\n * Type value for an `XmlProcessingInstruction` node.\n */\n static readonly TYPE_PROCESSING_INSTRUCTION = 'pi';\n\n /**\n * Type value for an `XmlText` node.\n */\n static readonly TYPE_TEXT = 'text';\n\n /**\n * Parent node of this node, or `null` if this node has no parent.\n */\n parent: XmlDocument | XmlElement | null = null;\n\n /**\n * Document that contains this node, or `null` if this node is not associated\n * with a document.\n */\n get document(): XmlDocument | null {\n return this.parent?.document ?? null;\n }\n\n /**\n * Whether this node is the root node of the document.\n */\n get isRootNode(): boolean {\n return this.parent !== null && this.parent === this.document;\n }\n\n /**\n * Whether whitespace should be preserved in the content of this element and\n * its children.\n *\n * This is influenced by the value of the special `xml:space` attribute, and\n * will be `true` for any node whose `xml:space` attribute is set to\n * \"preserve\". If a node has no such attribute, it will inherit the value of\n * the nearest ancestor that does (if any).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space\n */\n get preserveWhitespace(): boolean {\n return Boolean(this.parent?.preserveWhitespace);\n }\n\n /**\n * Type of this node.\n *\n * The value of this property is a string that matches one of the static\n * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,\n * `TYPE_TEXT`, etc.).\n *\n * The `XmlNode` class itself is a base class and doesn't have its own type\n * name.\n */\n get type() {\n return '';\n }\n\n /**\n * Returns a JSON-serializable object representing this node, minus properties\n * that could result in circular references.\n */\n toJSON(): JsonObject {\n let json: JsonObject = {\n type: this.type,\n };\n\n if (this.isRootNode) {\n json.isRootNode = true;\n }\n\n if (this.preserveWhitespace) {\n json.preserveWhitespace = true;\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * Text content within an XML document.\n */\nexport class XmlText extends XmlNode {\n /**\n * Text content of this node.\n */\n text: string;\n\n constructor(text = '') {\n super();\n this.text = text;\n }\n\n override get type() {\n return XmlNode.TYPE_TEXT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n text: this.text,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\nimport { XmlText } from './XmlText.js';\n\n/**\n * A CDATA section within an XML document.\n */\nexport class XmlCdata extends XmlText {\n override get type() {\n return XmlNode.TYPE_CDATA;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A comment within an XML document.\n */\nexport class XmlComment extends XmlNode {\n /**\n * Content of this comment.\n */\n content: string;\n\n constructor(content = '') {\n super();\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_COMMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n content: this.content,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\nimport type { JsonObject } from './types.js';\nimport type { XmlCdata } from './XmlCdata.js';\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport type { XmlText } from './XmlText.js';\n\n/**\n * Element in an XML document.\n */\nexport class XmlElement extends XmlNode {\n /**\n * Attributes on this element.\n */\n attributes: {[attrName: string]: string};\n\n /**\n * Child nodes of this element.\n */\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;\n\n /**\n * Name of this element.\n */\n name: string;\n\n constructor(\n name: string,\n attributes: {[attrName: string]: string} = Object.create(null),\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText> = [],\n ) {\n super();\n\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n\n /**\n * Whether this element is empty (meaning it has no children).\n */\n get isEmpty(): boolean {\n return this.children.length === 0;\n }\n\n override get preserveWhitespace(): boolean {\n let node: XmlNode | null = this; // eslint-disable-line @typescript-eslint/no-this-alias\n\n while (node instanceof XmlElement) {\n if ('xml:space' in node.attributes) {\n return node.attributes['xml:space'] === 'preserve';\n }\n\n node = node.parent;\n }\n\n return false;\n }\n\n /**\n * Text content of this element and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_ELEMENT;\n }\n\n override toJSON(): JsonObject {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n attributes: this.attributes,\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlElement } from './XmlElement.js';\nimport { XmlNode } from './XmlNode.js';\n\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\n\n/**\n * Represents an XML document. All elements within the document are descendants\n * of this node.\n */\nexport class XmlDocument extends XmlNode {\n /**\n * Child nodes of this document.\n */\n readonly children: Array<XmlComment | XmlProcessingInstruction | XmlElement>;\n\n constructor(children: Array<XmlComment | XmlElement | XmlProcessingInstruction> = []) {\n super();\n this.children = children;\n }\n\n override get document() {\n return this;\n }\n\n /**\n * Root element of this document, or `null` if this document is empty.\n */\n get root(): XmlElement | null {\n for (let child of this.children) {\n if (child instanceof XmlElement) {\n return child;\n }\n }\n\n return null;\n }\n\n /**\n * Text content of this document and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A processing instruction within an XML document.\n */\nexport class XmlProcessingInstruction extends XmlNode {\n /**\n * Content of this processing instruction.\n */\n content: string;\n\n /**\n * Name of this processing instruction. Also sometimes referred to as the\n * processing instruction \"target\".\n */\n name: string;\n\n constructor(name: string, content = '') {\n super();\n\n this.name = name;\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_PROCESSING_INSTRUCTION;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n content: this.content,\n });\n }\n}\n", "import { StringScanner } from './StringScanner.js';\nimport * as syntax from './syntax.js';\nimport { XmlCdata } from './XmlCdata.js';\nimport { XmlComment } from './XmlComment.js';\nimport { XmlDocument } from './XmlDocument.js';\nimport { XmlElement } from './XmlElement.js';\nimport { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport { XmlText } from './XmlText.js';\n\nimport type { XmlNode } from './XmlNode.js';\n\n\nconst emptyString = '';\n\n/**\n * Parses an XML string into an `XmlDocument`.\n *\n * @private\n */\nexport class Parser {\n readonly document: XmlDocument;\n\n private currentNode: XmlDocument | XmlElement;\n private readonly options: ParserOptions;\n private readonly scanner: StringScanner;\n\n /**\n * @param xml XML string to parse.\n * @param options Parser options.\n */\n constructor(xml: string, options: ParserOptions = {}) {\n this.document = new XmlDocument();\n this.currentNode = this.document;\n this.options = options;\n this.scanner = new StringScanner(normalizeXmlString(xml));\n\n this.consumeProlog();\n\n if (!this.consumeElement()) {\n throw this.error('Root element is missing or invalid');\n }\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (!this.scanner.isEnd) {\n throw this.error('Extra content at the end of the document');\n }\n }\n\n /**\n * Adds the given `XmlNode` as a child of `this.currentNode`.\n */\n addNode(node: XmlNode) {\n node.parent = this.currentNode;\n\n // @ts-expect-error: XmlDocument has a more limited set of possible children\n // than XmlElement so TypeScript is unhappy, but we always do the right\n // thing.\n this.currentNode.children.push(node);\n }\n\n /**\n * Adds the given _text_ to the document, either by appending it to a\n * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.\n */\n addText(text: string) {\n let { children } = this.currentNode;\n let { length } = children;\n\n if (length > 0) {\n let prevNode = children[length - 1];\n\n if (prevNode instanceof XmlText) {\n // The previous node is a text node, so we can append to it and avoid\n // creating another node.\n prevNode.text += text;\n return;\n }\n }\n\n this.addNode(new XmlText(text));\n }\n\n /**\n * Consumes element attributes.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags\n */\n consumeAttributes(): Record<string, string> {\n let attributes = Object.create(null);\n\n while (this.consumeWhitespace()) {\n let attrName = this.consumeName();\n\n if (!attrName) {\n break;\n }\n\n let attrValue = this.consumeEqual() && this.consumeAttributeValue();\n\n if (attrValue === false) {\n throw this.error('Attribute value expected');\n }\n\n if (attrName in attributes) {\n throw this.error(`Duplicate attribute: ${attrName}`);\n }\n\n if (attrName === 'xml:space'\n && attrValue !== 'default'\n && attrValue !== 'preserve') {\n\n throw this.error('Value of the `xml:space` attribute must be \"default\" or \"preserve\"');\n }\n\n attributes[attrName] = attrValue;\n }\n\n if (this.options.sortAttributes) {\n let attrNames = Object.keys(attributes).sort();\n let sortedAttributes = Object.create(null);\n\n for (let i = 0; i < attrNames.length; ++i) {\n let attrName = attrNames[i] as string;\n sortedAttributes[attrName] = attributes[attrName];\n }\n\n attributes = sortedAttributes;\n }\n\n return attributes;\n }\n\n /**\n * Consumes an `AttValue` (attribute value) if possible.\n *\n * @returns\n * Contents of the `AttValue` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that an `AttValue` was consumed but\n * was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\n consumeAttributeValue(): string | false {\n let { scanner } = this;\n let quote = scanner.peek();\n\n if (quote !== '\"' && quote !== \"'\") {\n return false;\n }\n\n scanner.advance();\n\n let chars;\n let isClosed = false;\n let value = emptyString;\n let regex = quote === '\"'\n ? syntax.attValueCharDoubleQuote\n : syntax.attValueCharSingleQuote;\n\n matchLoop: while (!scanner.isEnd) {\n chars = scanner.consumeMatch(regex);\n\n if (chars) {\n this.validateChars(chars);\n value += chars.replace(syntax.attValueNormalizedWhitespace, ' ');\n }\n\n switch (scanner.peek()) {\n case quote:\n isClosed = true;\n break matchLoop;\n\n case '&':\n value += this.consumeReference();\n continue;\n\n case '<':\n throw this.error('Unescaped `<` is not allowed in an attribute value');\n\n case emptyString:\n break matchLoop;\n }\n }\n\n if (!isClosed) {\n throw this.error('Unclosed attribute');\n }\n\n scanner.advance();\n return value;\n }\n\n /**\n * Consumes a CDATA section if possible.\n *\n * @returns Whether a CDATA section was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect\n */\n consumeCdataSection(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<![CDATA[')) {\n return false;\n }\n\n let text = scanner.consumeUntilString(']]>');\n this.validateChars(text);\n\n if (!scanner.consumeStringFast(']]>')) {\n throw this.error('Unclosed CDATA section');\n }\n\n if (this.options.preserveCdata) {\n this.addNode(new XmlCdata(text));\n } else {\n this.addText(text);\n }\n\n return true;\n }\n\n /**\n * Consumes character data if possible.\n *\n * @returns Whether character data was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\n consumeCharData(): boolean {\n let { scanner } = this;\n let charData = scanner.consumeUntilMatch(syntax.endCharData);\n\n if (!charData) {\n return false;\n }\n\n this.validateChars(charData);\n\n if (scanner.peek(3) === ']]>') {\n throw this.error('Element content may not contain the CDATA section close delimiter `]]>`');\n }\n\n this.addText(charData);\n return true;\n }\n\n /**\n * Consumes a comment if possible.\n *\n * @returns Whether a comment was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment\n */\n consumeComment(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!--')) {\n return false;\n }\n\n let content = scanner.consumeUntilString('--');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('-->')) {\n if (scanner.peek(2) === '--') {\n throw this.error(\"The string `--` isn't allowed inside a comment\");\n }\n\n throw this.error('Unclosed comment');\n }\n\n if (this.options.preserveComments) {\n this.addNode(new XmlComment(content.trim()));\n }\n\n return true;\n }\n\n /**\n * Consumes a reference in a content context if possible.\n *\n * This differs from `consumeReference()` in that a consumed reference will be\n * added to the document as a text node instead of returned.\n *\n * @returns Whether a reference was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc\n */\n consumeContentReference(): boolean {\n let ref = this.consumeReference();\n\n if (ref) {\n this.addText(ref);\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes a doctype declaration if possible.\n *\n * This is a loose implementation since doctype declarations are currently\n * discarded without further parsing.\n *\n * @returns Whether a doctype declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd\n */\n consumeDoctypeDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!DOCTYPE')\n || !this.consumeWhitespace()) {\n\n return false;\n }\n\n scanner.consumeMatch(/[^[>]+/y);\n\n if (scanner.consumeMatch(/\\[[\\s\\S]+?\\][\\x20\\t\\r\\n]*>/y)) {\n return true;\n }\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error('Unclosed doctype declaration');\n }\n\n return true;\n }\n\n /**\n * Consumes an element if possible.\n *\n * @returns Whether an element was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element\n */\n consumeElement(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (!name) {\n scanner.reset(mark);\n return false;\n }\n\n let attributes = this.consumeAttributes();\n let isEmpty = Boolean(scanner.consumeStringFast('/>'));\n let element = new XmlElement(name, attributes);\n\n element.parent = this.currentNode;\n\n if (!isEmpty) {\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed start tag for element \\`${name}\\``);\n }\n\n this.currentNode = element;\n\n do {\n this.consumeCharData();\n } while (\n this.consumeElement()\n || this.consumeContentReference()\n || this.consumeCdataSection()\n || this.consumeProcessingInstruction()\n || this.consumeComment()\n );\n\n let endTagMark = scanner.charIndex;\n let endTagName;\n\n if (!scanner.consumeStringFast('</')\n || !(endTagName = this.consumeName())\n || endTagName !== name) {\n\n scanner.reset(endTagMark);\n throw this.error(`Missing end tag for element ${name}`);\n }\n\n this.consumeWhitespace();\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed end tag for element ${name}`);\n }\n\n this.currentNode = element.parent;\n }\n\n this.addNode(element);\n return true;\n }\n\n /**\n * Consumes an `Eq` production if possible.\n *\n * @returns Whether an `Eq` production was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq\n */\n consumeEqual(): boolean {\n this.consumeWhitespace();\n\n if (this.scanner.consumeStringFast('=')) {\n this.consumeWhitespace();\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes `Misc` content if possible.\n *\n * @returns Whether anything was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc\n */\n consumeMisc(): boolean {\n return this.consumeComment()\n || this.consumeProcessingInstruction()\n || this.consumeWhitespace();\n }\n\n /**\n * Consumes one or more `Name` characters if possible.\n *\n * @returns `Name` characters, or an empty string if none were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name\n */\n consumeName(): string {\n return syntax.isNameStartChar(this.scanner.peek())\n ? this.scanner.consumeMatchFn(syntax.isNameChar)\n : emptyString;\n }\n\n /**\n * Consumes a processing instruction if possible.\n *\n * @returns Whether a processing instruction was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi\n */\n consumeProcessingInstruction(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<?')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (name) {\n if (name.toLowerCase() === 'xml') {\n scanner.reset(mark);\n throw this.error(\"XML declaration isn't allowed here\");\n }\n } else {\n throw this.error('Invalid processing instruction');\n }\n\n if (!this.consumeWhitespace()) {\n if (scanner.consumeStringFast('?>')) {\n this.addNode(new XmlProcessingInstruction(name));\n return true;\n }\n\n throw this.error('Whitespace is required after a processing instruction name');\n }\n\n let content = scanner.consumeUntilString('?>');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Unterminated processing instruction');\n }\n\n this.addNode(new XmlProcessingInstruction(name, content));\n return true;\n }\n\n /**\n * Consumes a prolog if possible.\n *\n * @returns Whether a prolog was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd\n */\n consumeProlog(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n this.consumeXmlDeclaration();\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (this.consumeDoctypeDeclaration()) {\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n }\n\n return mark < scanner.charIndex;\n }\n\n /**\n * Consumes a reference if possible.\n *\n * This differs from `consumeContentReference()` in that a consumed reference\n * will be returned rather than added to the document.\n *\n * @returns\n * Parsed reference value, or `false` if nothing was consumed (to\n * distinguish from a reference that resolves to an empty string).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference\n */\n consumeReference(): string | false {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('&')) {\n return false;\n }\n\n let ref = scanner.consumeMatchFn(syntax.isReferenceChar);\n\n if (scanner.consume() !== ';') {\n throw this.error('Unterminated reference (a reference must end with `;`)');\n }\n\n let parsedValue;\n\n if (ref[0] === '#') {\n // This is a character reference.\n let codePoint = ref[1] === 'x'\n ? parseInt(ref.slice(2), 16) // Hex codepoint.\n : parseInt(ref.slice(1), 10); // Decimal codepoint.\n\n if (isNaN(codePoint)) {\n throw this.error('Invalid character reference');\n }\n\n if (!syntax.isXmlCodePoint(codePoint)) {\n throw this.error('Character reference resolves to an invalid character');\n }\n\n parsedValue = String.fromCodePoint(codePoint);\n } else {\n // This is an entity reference.\n parsedValue = syntax.predefinedEntities[ref];\n\n if (parsedValue === undefined) {\n let {\n ignoreUndefinedEntities,\n resolveUndefinedEntity,\n } = this.options;\n\n let wrappedRef = `&${ref};`; // for backcompat with <= 2.x\n\n if (resolveUndefinedEntity) {\n let resolvedValue = resolveUndefinedEntity(wrappedRef);\n\n if (resolvedValue !== null && resolvedValue !== undefined) {\n let type = typeof resolvedValue;\n\n if (type !== 'string') {\n throw new TypeError(`\\`resolveUndefinedEntity()\\` must return a string, \\`null\\`, or \\`undefined\\`, but returned a value of type ${type}`);\n }\n\n return resolvedValue;\n }\n }\n\n if (ignoreUndefinedEntities) {\n return wrappedRef;\n }\n\n scanner.reset(-wrappedRef.length);\n throw this.error(`Named entity isn't defined: ${wrappedRef}`);\n }\n }\n\n return parsedValue;\n }\n\n /**\n * Consumes a `SystemLiteral` if possible.\n *\n * A `SystemLiteral` is similar to an attribute value, but allows the\n * characters `<` and `&` and doesn't replace references.\n *\n * @returns\n * Value of the `SystemLiteral` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that a `SystemLiteral` was consumed\n * but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral\n */\n consumeSystemLiteral(): string | false {\n let { scanner } = this;\n let quote = scanner.consumeStringFast('\"') || scanner.consumeStringFast(\"'\");\n\n if (!quote) {\n return false;\n }\n\n let value = scanner.consumeUntilString(quote);\n this.validateChars(value);\n\n if (!scanner.consumeStringFast(quote)) {\n throw this.error('Missing end quote');\n }\n\n return value;\n }\n\n /**\n * Consumes one or more whitespace characters if possible.\n *\n * @returns Whether any whitespace characters were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\n consumeWhitespace(): boolean {\n return Boolean(this.scanner.consumeMatchFn(syntax.isWhitespace));\n }\n\n /**\n * Consumes an XML declaration if possible.\n *\n * @returns Whether an XML declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl\n */\n consumeXmlDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<?xml')) {\n return false;\n }\n\n if (!this.consumeWhitespace()) {\n throw this.error('Invalid XML declaration');\n }\n\n let version = Boolean(scanner.consumeStringFast('version'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (version === false) {\n throw this.error('XML version is missing or invalid');\n } else if (!/^1\\.[0-9]+$/.test(version)) {\n throw this.error('Invalid character in version number');\n }\n\n if (this.consumeWhitespace()) {\n let encoding = Boolean(scanner.consumeStringFast('encoding'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (encoding) {\n this.consumeWhitespace();\n }\n\n let standalone = Boolean(scanner.consumeStringFast('standalone'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (standalone) {\n if (standalone !== 'yes' && standalone !== 'no') {\n throw this.error('Only \"yes\" and \"no\" are permitted as values of `standalone`');\n }\n\n this.consumeWhitespace();\n }\n }\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Invalid or unclosed XML declaration');\n }\n\n return true;\n }\n\n /**\n * Throws an error at the current scanner position.\n */\n error(message: string) {\n let { charIndex, string: xml } = this.scanner;\n let column = 1;\n let excerpt = '';\n let line = 1;\n\n // Find the line and column where the error occurred.\n for (let i = 0; i < charIndex; ++i) {\n let char = xml[i];\n\n if (char === '\\n') {\n column = 1;\n excerpt = '';\n line += 1;\n } else {\n column += 1;\n excerpt += char;\n }\n }\n\n let eol = xml.indexOf('\\n', charIndex);\n\n excerpt += eol === -1\n ? xml.slice(charIndex)\n : xml.slice(charIndex, eol);\n\n let excerptStart = 0;\n\n // Keep the excerpt below 50 chars, but always keep the error position in\n // view.\n if (excerpt.length > 50) {\n if (column < 40) {\n excerpt = excerpt.slice(0, 50);\n } else {\n excerptStart = column - 20;\n excerpt = excerpt.slice(excerptStart, column + 30);\n }\n }\n\n let err = new Error(\n `${message} (line ${line}, column ${column})\\n`\n + ` ${excerpt}\\n`\n + ' '.repeat(column - excerptStart + 1) + '^\\n',\n );\n\n Object.assign(err, {\n column,\n excerpt,\n line,\n pos: charIndex,\n });\n\n return err;\n }\n\n /**\n * Throws an invalid character error if any character in the given _string_\n * isn't a valid XML character.\n */\n validateChars(string: string) {\n let { length } = string;\n\n for (let i = 0; i < length; ++i) {\n let cp = string.codePointAt(i) as number;\n\n if (!syntax.isXmlCodePoint(cp)) {\n this.scanner.reset(-([ ...string ].length - i));\n throw this.error('Invalid character');\n }\n\n if (cp > 65535) {\n i += 1;\n }\n }\n }\n}\n\n// -- Private Functions --------------------------------------------------------\n\n/**\n * Normalizes the given XML string by stripping a byte order mark (if present)\n * and replacing CRLF sequences and lone CR characters with LF characters.\n */\nfunction normalizeXmlString(xml: string): string {\n if (xml[0] === '\\uFEFF') {\n xml = xml.slice(1);\n }\n\n return xml.replace(/\\r\\n?/g, '\\n');\n}\n\n// -- Types --------------------------------------------------------------------\nexport type ParserOptions = {\n /**\n * When `true`, an undefined named entity (like \"&bogus;\") will be left in the\n * output as is instead of causing a parse error.\n *\n * @default false\n */\n ignoreUndefinedEntities?: boolean;\n\n /**\n * When `true`, CDATA sections will be preserved in the document as `XmlCdata`\n * nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,\n * which keeps the node tree simpler and easier to work with.\n *\n * @default false\n */\n preserveCdata?: boolean;\n\n /**\n * When `true`, comments will be preserved in the document as `XmlComment`\n * nodes. Otherwise comments will not be included in the node tree.\n *\n * @default false\n */\n preserveComments?: boolean;\n\n /**\n * When an undefined named entity is encountered, this function will be called\n * with the entity as its only argument. It should return a string value with\n * which to replace the entity, or `null` or `undefined` to treat the entity\n * as undefined (which may result in a parse error depending on the value of\n * `ignoreUndefinedEntities`).\n */\n resolveUndefinedEntity?: (entity: string) => string | null | undefined;\n\n /**\n * When `true`, attributes in an element's `attributes` object will be sorted\n * in alphanumeric order by name. Otherwise they'll retain their original\n * order as found in the XML.\n *\n * @default false\n */\n sortAttributes?: boolean;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,cAAc;AACpB,IAAM,gBAAgB;AAGf,IAAM,gBAAN,MAAoB;AAAA,EASzB,YAAY,QAAgB;AAC1B,SAAKA,IAAY,KAAKC,EAAW,QAAQ,IAAI;AAC7C,SAAKC,IAAY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AO,KAAK,OAAO,EAAG;AACpC;",
4
+ "sourcesContent": ["import { Parser } from './lib/Parser.js';\n\nimport type { ParserOptions } from './lib/Parser.js';\n\nexport * from './lib/types.js';\nexport { XmlCdata } from './lib/XmlCdata.js';\nexport { XmlComment } from './lib/XmlComment.js';\nexport { XmlDocument } from './lib/XmlDocument.js';\nexport { XmlElement } from './lib/XmlElement.js';\nexport { XmlNode } from './lib/XmlNode.js';\nexport { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';\nexport { XmlText } from './lib/XmlText.js';\n\nexport type { ParserOptions } from './lib/Parser.js';\n\n/**\n * Parses the given XML string and returns an `XmlDocument` instance\n * representing the document tree.\n *\n * @example\n *\n * import { parseXml } from '@rgrove/parse-xml';\n * let doc = parseXml('<kittens fuzzy=\"yes\">I like fuzzy kittens.</kittens>');\n *\n * @param xml XML string to parse.\n * @param options Parser options.\n */\nexport function parseXml(xml: string, options?: ParserOptions) {\n return (new Parser(xml, options)).document;\n}\n", "const emptyString = '';\nconst surrogatePair = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\n/** @private */\nexport class StringScanner {\n charIndex: number;\n readonly string: string;\n\n private readonly charCount: number;\n private readonly charsToBytes: number[] | undefined;\n private readonly length: number;\n private readonly multiByteMode: boolean;\n\n constructor(string: string) {\n this.charCount = this.charLength(string, true);\n this.charIndex = 0;\n this.length = string.length;\n this.multiByteMode = this.charCount !== this.length;\n this.string = string;\n\n if (this.multiByteMode) {\n let charsToBytes = [];\n\n // Create a mapping of character indexes to byte indexes. Since the string\n // contains multibyte characters, a byte index may not necessarily align\n // with a character index.\n for (let byteIndex = 0, charIndex = 0; charIndex < this.charCount; ++charIndex) {\n charsToBytes[charIndex] = byteIndex;\n byteIndex += (string.codePointAt(byteIndex) as number) > 65535 ? 2 : 1;\n }\n\n this.charsToBytes = charsToBytes;\n }\n }\n\n /**\n * Whether the current character index is at the end of the input string.\n */\n get isEnd() {\n return this.charIndex >= this.charCount;\n }\n\n // -- Protected Methods ------------------------------------------------------\n\n /**\n * Returns the byte index of the given character index in the string. The two\n * may differ in strings that contain multibyte characters.\n */\n protected charIndexToByteIndex(charIndex: number = this.charIndex): number {\n return this.multiByteMode\n ? (this.charsToBytes as number[])[charIndex] ?? Infinity\n : charIndex;\n }\n\n /**\n * Returns the number of characters in the given string, which may differ from\n * the byte length if the string contains multibyte characters.\n */\n protected charLength(string: string, multiByteSafe = this.multiByteMode): number {\n // We could get the char length with `[ ...string ].length`, but that's\n // actually slower than replacing surrogate pairs with single-byte\n // characters and then counting the result.\n return multiByteSafe\n ? string.replace(surrogatePair, '_').length\n : string.length;\n }\n\n // -- Public Methods ---------------------------------------------------------\n\n /**\n * Advances the scanner by the given number of characters, stopping if the end\n * of the string is reached.\n */\n advance(count = 1) {\n this.charIndex = Math.min(this.charCount, this.charIndex + count);\n }\n\n /**\n * Consumes and returns the given number of characters if possible, advancing\n * the scanner and stopping if the end of the string is reached.\n *\n * If no characters could be consumed, an empty string will be returned.\n */\n consume(count = 1): string {\n let chars = this.peek(count);\n this.advance(count);\n return chars;\n }\n\n /**\n * Consumes a match for the given sticky regex, advances the scanner, updates\n * the `lastIndex` property of the regex, and returns the matching string.\n *\n * The regex must have a sticky flag (\"y\") so that its `lastIndex` prop can be\n * used to anchor the match at the current scanner position.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeMatch(regex: RegExp): string {\n if (!regex.sticky) {\n throw new Error('`regex` must have a sticky flag (\"y\")');\n }\n\n regex.lastIndex = this.charIndexToByteIndex();\n\n let result = regex.exec(this.string);\n\n if (result === null || result.length === 0) {\n return emptyString;\n }\n\n let match = result[0] as string;\n this.advance(this.charLength(match));\n return match;\n }\n\n /**\n * Consumes and returns all characters for which the given function returns a\n * truthy value, stopping on the first falsy return value or if the end of the\n * input is reached.\n */\n consumeMatchFn(fn: (char: string) => boolean): string {\n let char;\n let match = emptyString;\n\n while ((char = this.peek()) && fn(char)) {\n match += char;\n this.advance();\n }\n\n return match;\n }\n\n /**\n * Consumes the given string if it exists at the current character index, and\n * advances the scanner.\n *\n * If the given string doesn't exist at the current character index, an empty\n * string will be returned and the scanner will not be advanced.\n */\n consumeString(stringToConsume: string): string {\n if (this.consumeStringFast(stringToConsume)) {\n return stringToConsume;\n }\n\n if (this.multiByteMode) {\n let { length } = stringToConsume;\n let charLengthToMatch = this.charLength(stringToConsume);\n\n if (charLengthToMatch !== length\n && stringToConsume === this.peek(charLengthToMatch)) {\n\n this.advance(charLengthToMatch);\n return stringToConsume;\n }\n }\n\n return emptyString;\n }\n\n /**\n * Does the same thing as `consumeString()`, but doesn't support consuming\n * multibyte characters. This can be faster if you only need to match single\n * byte characters.\n */\n consumeStringFast(stringToConsume: string): string {\n let { length } = stringToConsume;\n\n if (this.peek(length) === stringToConsume) {\n this.advance(length);\n return stringToConsume;\n }\n\n return emptyString;\n }\n\n /**\n * Consumes characters until the given global regex is matched, advancing the\n * scanner up to (but not beyond) the beginning of the match. If the regex\n * doesn't match, nothing will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilMatch(regex: RegExp): string {\n let restOfString = this.string.slice(this.charIndexToByteIndex());\n let matchByteIndex = restOfString.search(regex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = restOfString.slice(0, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Consumes characters until the given string is found, advancing the scanner\n * up to (but not beyond) that point. If the string is never found, nothing\n * will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilString(searchString: string): string {\n let { string } = this;\n let byteIndex = this.charIndexToByteIndex();\n let matchByteIndex = string.indexOf(searchString, byteIndex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = string.slice(byteIndex, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Returns the given number of characters starting at the current character\n * index, without advancing the scanner and without exceeding the end of the\n * input string.\n */\n peek(count = 1): string {\n let { charIndex, multiByteMode, string } = this;\n\n if (multiByteMode) {\n // Inlining this comparison instead of checking `this.isEnd` improves perf\n // slightly since `peek()` is called so frequently.\n if (charIndex >= this.charCount) {\n return emptyString;\n }\n\n return string.slice(\n this.charIndexToByteIndex(charIndex),\n this.charIndexToByteIndex(charIndex + count),\n );\n }\n\n return string.slice(charIndex, charIndex + count);\n }\n\n /**\n * Resets the scanner position to the given character _index_, or to the start\n * of the input string if no index is given.\n *\n * If _index_ is negative, the scanner position will be moved backward by that\n * many characters, stopping if the beginning of the string is reached.\n */\n reset(index = 0) {\n this.charIndex = index >= 0\n ? Math.min(this.charCount, index)\n : Math.max(0, this.charIndex + index);\n }\n}\n", "/**\n * Regular expression that matches one or more `AttValue` characters in a\n * double-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharDoubleQuote = /[^\"&<]+/y;\n\n/**\n * Regular expression that matches one or more `AttValue` characters in a\n * single-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharSingleQuote = /[^'&<]+/y;\n\n/**\n * Regular expression that matches a whitespace character that should be\n * normalized to a space character in an attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize\n */\nexport const attValueNormalizedWhitespace = /[\\t\\n]/g;\n\n/**\n * Regular expression that matches one or more characters that signal the end of\n * XML `CharData` content.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\nexport const endCharData = /<|&|]]>/;\n\n/**\n * Mapping of predefined entity names to their replacement values.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent\n */\nexport const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {\n amp: '&',\n apos: \"'\",\n gt: '>',\n lt: '<',\n quot: '\"',\n}));\n\n/**\n * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar\n */\nexport function isNameChar(char: string): boolean {\n let cp = getCodePoint(char);\n\n // Including the most common NameStartChars here improves performance\n // slightly.\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || (cp >= 0x30 && cp <= 0x39) // 0-9\n || cp === 0x2D // -\n || cp === 0x2E // .\n || cp === 0xB7\n || (cp >= 0x300 && cp <= 0x36F)\n || (cp >= 0x203F && cp <= 0x2040)\n || isNameStartChar(char, cp);\n}\n\n/**\n * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar\n */\nexport function isNameStartChar(char: string, cp = getCodePoint(char)): boolean {\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || cp === 0x3A // :\n || cp === 0x5F // _\n || (cp >= 0xC0 && cp <= 0xD6)\n || (cp >= 0xD8 && cp <= 0xF6)\n || (cp >= 0xF8 && cp <= 0x2FF)\n || (cp >= 0x370 && cp <= 0x37D)\n || (cp >= 0x37F && cp <= 0x1FFF)\n || (cp >= 0x200C && cp <= 0x200D)\n || (cp >= 0x2070 && cp <= 0x218F)\n || (cp >= 0x2C00 && cp <= 0x2FEF)\n || (cp >= 0x3001 && cp <= 0xD7FF)\n || (cp >= 0xF900 && cp <= 0xFDCF)\n || (cp >= 0xFDF0 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0xEFFFF);\n}\n\n/**\n * Returns `true` if _char_ is a valid reference character (which may appear\n * between `&` and `;` in a reference), `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references\n */\nexport function isReferenceChar(char: string): boolean {\n return char === '#' || isNameChar(char);\n}\n\n/**\n * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\nexport function isWhitespace(char: string): boolean {\n let cp = getCodePoint(char);\n\n return cp === 0x20\n || cp === 0x9\n || cp === 0xA\n || cp === 0xD;\n}\n\n/**\n * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`\n * otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char\n */\nexport function isXmlCodePoint(cp: number): boolean {\n return cp === 0x9\n || cp === 0xA\n || cp === 0xD\n || (cp >= 0x20 && cp <= 0xD7FF)\n || (cp >= 0xE000 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0x10FFFF);\n}\n\n/**\n * Returns the Unicode code point value of the given character, or `-1` if\n * _char_ is empty.\n */\nfunction getCodePoint(char: string): number {\n return char.codePointAt(0) || -1;\n}\n", "import type { JsonObject } from './types.js';\nimport type { XmlDocument } from './XmlDocument.js';\nimport type { XmlElement } from './XmlElement.js';\n\n/**\n * Base interface for a node in an XML document.\n */\nexport class XmlNode {\n /**\n * Type value for an `XmlCdata` node.\n */\n static readonly TYPE_CDATA = 'cdata';\n\n /**\n * Type value for an `XmlComment` node.\n */\n static readonly TYPE_COMMENT = 'comment';\n\n /**\n * Type value for an `XmlDocument` node.\n */\n static readonly TYPE_DOCUMENT = 'document';\n\n /**\n * Type value for an `XmlElement` node.\n */\n static readonly TYPE_ELEMENT = 'element';\n\n /**\n * Type value for an `XmlProcessingInstruction` node.\n */\n static readonly TYPE_PROCESSING_INSTRUCTION = 'pi';\n\n /**\n * Type value for an `XmlText` node.\n */\n static readonly TYPE_TEXT = 'text';\n\n /**\n * Parent node of this node, or `null` if this node has no parent.\n */\n parent: XmlDocument | XmlElement | null = null;\n\n /**\n * Document that contains this node, or `null` if this node is not associated\n * with a document.\n */\n get document(): XmlDocument | null {\n return this.parent?.document ?? null;\n }\n\n /**\n * Whether this node is the root node of the document.\n */\n get isRootNode(): boolean {\n return this.parent !== null && this.parent === this.document;\n }\n\n /**\n * Whether whitespace should be preserved in the content of this element and\n * its children.\n *\n * This is influenced by the value of the special `xml:space` attribute, and\n * will be `true` for any node whose `xml:space` attribute is set to\n * \"preserve\". If a node has no such attribute, it will inherit the value of\n * the nearest ancestor that does (if any).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space\n */\n get preserveWhitespace(): boolean {\n return Boolean(this.parent?.preserveWhitespace);\n }\n\n /**\n * Type of this node.\n *\n * The value of this property is a string that matches one of the static\n * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,\n * `TYPE_TEXT`, etc.).\n *\n * The `XmlNode` class itself is a base class and doesn't have its own type\n * name.\n */\n get type() {\n return '';\n }\n\n /**\n * Returns a JSON-serializable object representing this node, minus properties\n * that could result in circular references.\n */\n toJSON(): JsonObject {\n let json: JsonObject = {\n type: this.type,\n };\n\n if (this.isRootNode) {\n json.isRootNode = true;\n }\n\n if (this.preserveWhitespace) {\n json.preserveWhitespace = true;\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * Text content within an XML document.\n */\nexport class XmlText extends XmlNode {\n /**\n * Text content of this node.\n */\n text: string;\n\n constructor(text = '') {\n super();\n this.text = text;\n }\n\n override get type() {\n return XmlNode.TYPE_TEXT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n text: this.text,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\nimport { XmlText } from './XmlText.js';\n\n/**\n * A CDATA section within an XML document.\n */\nexport class XmlCdata extends XmlText {\n override get type() {\n return XmlNode.TYPE_CDATA;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A comment within an XML document.\n */\nexport class XmlComment extends XmlNode {\n /**\n * Content of this comment.\n */\n content: string;\n\n constructor(content = '') {\n super();\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_COMMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n content: this.content,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\nimport type { JsonObject } from './types.js';\nimport type { XmlCdata } from './XmlCdata.js';\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport type { XmlText } from './XmlText.js';\n\n/**\n * Element in an XML document.\n */\nexport class XmlElement extends XmlNode {\n /**\n * Attributes on this element.\n */\n attributes: {[attrName: string]: string};\n\n /**\n * Child nodes of this element.\n */\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;\n\n /**\n * Name of this element.\n */\n name: string;\n\n constructor(\n name: string,\n attributes: {[attrName: string]: string} = Object.create(null),\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText> = [],\n ) {\n super();\n\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n\n /**\n * Whether this element is empty (meaning it has no children).\n */\n get isEmpty(): boolean {\n return this.children.length === 0;\n }\n\n override get preserveWhitespace(): boolean {\n let node: XmlNode | null = this; // eslint-disable-line @typescript-eslint/no-this-alias\n\n while (node instanceof XmlElement) {\n if ('xml:space' in node.attributes) {\n return node.attributes['xml:space'] === 'preserve';\n }\n\n node = node.parent;\n }\n\n return false;\n }\n\n /**\n * Text content of this element and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_ELEMENT;\n }\n\n override toJSON(): JsonObject {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n attributes: this.attributes,\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlElement } from './XmlElement.js';\nimport { XmlNode } from './XmlNode.js';\n\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\n\n/**\n * Represents an XML document. All elements within the document are descendants\n * of this node.\n */\nexport class XmlDocument extends XmlNode {\n /**\n * Child nodes of this document.\n */\n readonly children: Array<XmlComment | XmlProcessingInstruction | XmlElement>;\n\n constructor(children: Array<XmlComment | XmlElement | XmlProcessingInstruction> = []) {\n super();\n this.children = children;\n }\n\n override get document() {\n return this;\n }\n\n /**\n * Root element of this document, or `null` if this document is empty.\n */\n get root(): XmlElement | null {\n for (let child of this.children) {\n if (child instanceof XmlElement) {\n return child;\n }\n }\n\n return null;\n }\n\n /**\n * Text content of this document and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A processing instruction within an XML document.\n */\nexport class XmlProcessingInstruction extends XmlNode {\n /**\n * Content of this processing instruction.\n */\n content: string;\n\n /**\n * Name of this processing instruction. Also sometimes referred to as the\n * processing instruction \"target\".\n */\n name: string;\n\n constructor(name: string, content = '') {\n super();\n\n this.name = name;\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_PROCESSING_INSTRUCTION;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n content: this.content,\n });\n }\n}\n", "import { StringScanner } from './StringScanner.js';\nimport * as syntax from './syntax.js';\nimport { XmlCdata } from './XmlCdata.js';\nimport { XmlComment } from './XmlComment.js';\nimport { XmlDocument } from './XmlDocument.js';\nimport { XmlElement } from './XmlElement.js';\nimport { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport { XmlText } from './XmlText.js';\n\nimport type { XmlNode } from './XmlNode.js';\n\n\nconst emptyString = '';\n\n/**\n * Parses an XML string into an `XmlDocument`.\n *\n * @private\n */\nexport class Parser {\n readonly document: XmlDocument;\n\n private currentNode: XmlDocument | XmlElement;\n private readonly options: ParserOptions;\n private readonly scanner: StringScanner;\n\n /**\n * @param xml XML string to parse.\n * @param options Parser options.\n */\n constructor(xml: string, options: ParserOptions = {}) {\n this.document = new XmlDocument();\n this.currentNode = this.document;\n this.options = options;\n this.scanner = new StringScanner(normalizeXmlString(xml));\n\n this.consumeProlog();\n\n if (!this.consumeElement()) {\n throw this.error('Root element is missing or invalid');\n }\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (!this.scanner.isEnd) {\n throw this.error('Extra content at the end of the document');\n }\n }\n\n /**\n * Adds the given `XmlNode` as a child of `this.currentNode`.\n */\n addNode(node: XmlNode) {\n node.parent = this.currentNode;\n\n // @ts-expect-error: XmlDocument has a more limited set of possible children\n // than XmlElement so TypeScript is unhappy, but we always do the right\n // thing.\n this.currentNode.children.push(node);\n }\n\n /**\n * Adds the given _text_ to the document, either by appending it to a\n * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.\n */\n addText(text: string) {\n let { children } = this.currentNode;\n let { length } = children;\n\n if (length > 0) {\n let prevNode = children[length - 1];\n\n if (prevNode instanceof XmlText) {\n // The previous node is a text node, so we can append to it and avoid\n // creating another node.\n prevNode.text += text;\n return;\n }\n }\n\n this.addNode(new XmlText(text));\n }\n\n /**\n * Consumes element attributes.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags\n */\n consumeAttributes(): Record<string, string> {\n let attributes = Object.create(null);\n\n while (this.consumeWhitespace()) {\n let attrName = this.consumeName();\n\n if (!attrName) {\n break;\n }\n\n let attrValue = this.consumeEqual() && this.consumeAttributeValue();\n\n if (attrValue === false) {\n throw this.error('Attribute value expected');\n }\n\n if (attrName in attributes) {\n throw this.error(`Duplicate attribute: ${attrName}`);\n }\n\n if (attrName === 'xml:space'\n && attrValue !== 'default'\n && attrValue !== 'preserve') {\n\n throw this.error('Value of the `xml:space` attribute must be \"default\" or \"preserve\"');\n }\n\n attributes[attrName] = attrValue;\n }\n\n if (this.options.sortAttributes) {\n let attrNames = Object.keys(attributes).sort();\n let sortedAttributes = Object.create(null);\n\n for (let i = 0; i < attrNames.length; ++i) {\n let attrName = attrNames[i] as string;\n sortedAttributes[attrName] = attributes[attrName];\n }\n\n attributes = sortedAttributes;\n }\n\n return attributes;\n }\n\n /**\n * Consumes an `AttValue` (attribute value) if possible.\n *\n * @returns\n * Contents of the `AttValue` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that an `AttValue` was consumed but\n * was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\n consumeAttributeValue(): string | false {\n let { scanner } = this;\n let quote = scanner.peek();\n\n if (quote !== '\"' && quote !== \"'\") {\n return false;\n }\n\n scanner.advance();\n\n let chars;\n let isClosed = false;\n let value = emptyString;\n let regex = quote === '\"'\n ? syntax.attValueCharDoubleQuote\n : syntax.attValueCharSingleQuote;\n\n matchLoop: while (!scanner.isEnd) {\n chars = scanner.consumeMatch(regex);\n\n if (chars) {\n this.validateChars(chars);\n value += chars.replace(syntax.attValueNormalizedWhitespace, ' ');\n }\n\n switch (scanner.peek()) {\n case quote:\n isClosed = true;\n break matchLoop;\n\n case '&':\n value += this.consumeReference();\n continue;\n\n case '<':\n throw this.error('Unescaped `<` is not allowed in an attribute value');\n\n case emptyString:\n break matchLoop;\n }\n }\n\n if (!isClosed) {\n throw this.error('Unclosed attribute');\n }\n\n scanner.advance();\n return value;\n }\n\n /**\n * Consumes a CDATA section if possible.\n *\n * @returns Whether a CDATA section was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect\n */\n consumeCdataSection(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<![CDATA[')) {\n return false;\n }\n\n let text = scanner.consumeUntilString(']]>');\n this.validateChars(text);\n\n if (!scanner.consumeStringFast(']]>')) {\n throw this.error('Unclosed CDATA section');\n }\n\n if (this.options.preserveCdata) {\n this.addNode(new XmlCdata(text));\n } else {\n this.addText(text);\n }\n\n return true;\n }\n\n /**\n * Consumes character data if possible.\n *\n * @returns Whether character data was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\n consumeCharData(): boolean {\n let { scanner } = this;\n let charData = scanner.consumeUntilMatch(syntax.endCharData);\n\n if (!charData) {\n return false;\n }\n\n this.validateChars(charData);\n\n if (scanner.peek(3) === ']]>') {\n throw this.error('Element content may not contain the CDATA section close delimiter `]]>`');\n }\n\n this.addText(charData);\n return true;\n }\n\n /**\n * Consumes a comment if possible.\n *\n * @returns Whether a comment was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment\n */\n consumeComment(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!--')) {\n return false;\n }\n\n let content = scanner.consumeUntilString('--');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('-->')) {\n if (scanner.peek(2) === '--') {\n throw this.error(\"The string `--` isn't allowed inside a comment\");\n }\n\n throw this.error('Unclosed comment');\n }\n\n if (this.options.preserveComments) {\n this.addNode(new XmlComment(content.trim()));\n }\n\n return true;\n }\n\n /**\n * Consumes a reference in a content context if possible.\n *\n * This differs from `consumeReference()` in that a consumed reference will be\n * added to the document as a text node instead of returned.\n *\n * @returns Whether a reference was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc\n */\n consumeContentReference(): boolean {\n let ref = this.consumeReference();\n\n if (ref) {\n this.addText(ref);\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes a doctype declaration if possible.\n *\n * This is a loose implementation since doctype declarations are currently\n * discarded without further parsing.\n *\n * @returns Whether a doctype declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd\n */\n consumeDoctypeDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!DOCTYPE')\n || !this.consumeWhitespace()) {\n\n return false;\n }\n\n scanner.consumeMatch(/[^[>]+/y);\n\n if (scanner.consumeMatch(/\\[[\\s\\S]+?\\][\\x20\\t\\r\\n]*>/y)) {\n return true;\n }\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error('Unclosed doctype declaration');\n }\n\n return true;\n }\n\n /**\n * Consumes an element if possible.\n *\n * @returns Whether an element was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element\n */\n consumeElement(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (!name) {\n scanner.reset(mark);\n return false;\n }\n\n let attributes = this.consumeAttributes();\n let isEmpty = Boolean(scanner.consumeStringFast('/>'));\n let element = new XmlElement(name, attributes);\n\n element.parent = this.currentNode;\n\n if (!isEmpty) {\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed start tag for element \\`${name}\\``);\n }\n\n this.currentNode = element;\n\n do {\n this.consumeCharData();\n } while (\n this.consumeElement()\n || this.consumeContentReference()\n || this.consumeCdataSection()\n || this.consumeProcessingInstruction()\n || this.consumeComment()\n );\n\n let endTagMark = scanner.charIndex;\n let endTagName;\n\n if (!scanner.consumeStringFast('</')\n || !(endTagName = this.consumeName())\n || endTagName !== name) {\n\n scanner.reset(endTagMark);\n throw this.error(`Missing end tag for element ${name}`);\n }\n\n this.consumeWhitespace();\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed end tag for element ${name}`);\n }\n\n this.currentNode = element.parent;\n }\n\n this.addNode(element);\n return true;\n }\n\n /**\n * Consumes an `Eq` production if possible.\n *\n * @returns Whether an `Eq` production was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq\n */\n consumeEqual(): boolean {\n this.consumeWhitespace();\n\n if (this.scanner.consumeStringFast('=')) {\n this.consumeWhitespace();\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes `Misc` content if possible.\n *\n * @returns Whether anything was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc\n */\n consumeMisc(): boolean {\n return this.consumeComment()\n || this.consumeProcessingInstruction()\n || this.consumeWhitespace();\n }\n\n /**\n * Consumes one or more `Name` characters if possible.\n *\n * @returns `Name` characters, or an empty string if none were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name\n */\n consumeName(): string {\n return syntax.isNameStartChar(this.scanner.peek())\n ? this.scanner.consumeMatchFn(syntax.isNameChar)\n : emptyString;\n }\n\n /**\n * Consumes a processing instruction if possible.\n *\n * @returns Whether a processing instruction was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi\n */\n consumeProcessingInstruction(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<?')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (name) {\n if (name.toLowerCase() === 'xml') {\n scanner.reset(mark);\n throw this.error(\"XML declaration isn't allowed here\");\n }\n } else {\n throw this.error('Invalid processing instruction');\n }\n\n if (!this.consumeWhitespace()) {\n if (scanner.consumeStringFast('?>')) {\n this.addNode(new XmlProcessingInstruction(name));\n return true;\n }\n\n throw this.error('Whitespace is required after a processing instruction name');\n }\n\n let content = scanner.consumeUntilString('?>');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Unterminated processing instruction');\n }\n\n this.addNode(new XmlProcessingInstruction(name, content));\n return true;\n }\n\n /**\n * Consumes a prolog if possible.\n *\n * @returns Whether a prolog was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd\n */\n consumeProlog(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n this.consumeXmlDeclaration();\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (this.consumeDoctypeDeclaration()) {\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n }\n\n return mark < scanner.charIndex;\n }\n\n /**\n * Consumes a reference if possible.\n *\n * This differs from `consumeContentReference()` in that a consumed reference\n * will be returned rather than added to the document.\n *\n * @returns\n * Parsed reference value, or `false` if nothing was consumed (to\n * distinguish from a reference that resolves to an empty string).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference\n */\n consumeReference(): string | false {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('&')) {\n return false;\n }\n\n let ref = scanner.consumeMatchFn(syntax.isReferenceChar);\n\n if (scanner.consume() !== ';') {\n throw this.error('Unterminated reference (a reference must end with `;`)');\n }\n\n let parsedValue;\n\n if (ref[0] === '#') {\n // This is a character reference.\n let codePoint = ref[1] === 'x'\n ? parseInt(ref.slice(2), 16) // Hex codepoint.\n : parseInt(ref.slice(1), 10); // Decimal codepoint.\n\n if (isNaN(codePoint)) {\n throw this.error('Invalid character reference');\n }\n\n if (!syntax.isXmlCodePoint(codePoint)) {\n throw this.error('Character reference resolves to an invalid character');\n }\n\n parsedValue = String.fromCodePoint(codePoint);\n } else {\n // This is an entity reference.\n parsedValue = syntax.predefinedEntities[ref];\n\n if (parsedValue === undefined) {\n let {\n ignoreUndefinedEntities,\n resolveUndefinedEntity,\n } = this.options;\n\n let wrappedRef = `&${ref};`; // for backcompat with <= 2.x\n\n if (resolveUndefinedEntity) {\n let resolvedValue = resolveUndefinedEntity(wrappedRef);\n\n if (resolvedValue !== null && resolvedValue !== undefined) {\n let type = typeof resolvedValue;\n\n if (type !== 'string') {\n throw new TypeError(`\\`resolveUndefinedEntity()\\` must return a string, \\`null\\`, or \\`undefined\\`, but returned a value of type ${type}`);\n }\n\n return resolvedValue;\n }\n }\n\n if (ignoreUndefinedEntities) {\n return wrappedRef;\n }\n\n scanner.reset(-wrappedRef.length);\n throw this.error(`Named entity isn't defined: ${wrappedRef}`);\n }\n }\n\n return parsedValue;\n }\n\n /**\n * Consumes a `SystemLiteral` if possible.\n *\n * A `SystemLiteral` is similar to an attribute value, but allows the\n * characters `<` and `&` and doesn't replace references.\n *\n * @returns\n * Value of the `SystemLiteral` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that a `SystemLiteral` was consumed\n * but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral\n */\n consumeSystemLiteral(): string | false {\n let { scanner } = this;\n let quote = scanner.consumeStringFast('\"') || scanner.consumeStringFast(\"'\");\n\n if (!quote) {\n return false;\n }\n\n let value = scanner.consumeUntilString(quote);\n this.validateChars(value);\n\n if (!scanner.consumeStringFast(quote)) {\n throw this.error('Missing end quote');\n }\n\n return value;\n }\n\n /**\n * Consumes one or more whitespace characters if possible.\n *\n * @returns Whether any whitespace characters were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\n consumeWhitespace(): boolean {\n return Boolean(this.scanner.consumeMatchFn(syntax.isWhitespace));\n }\n\n /**\n * Consumes an XML declaration if possible.\n *\n * @returns Whether an XML declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl\n */\n consumeXmlDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<?xml')) {\n return false;\n }\n\n if (!this.consumeWhitespace()) {\n throw this.error('Invalid XML declaration');\n }\n\n let version = Boolean(scanner.consumeStringFast('version'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (version === false) {\n throw this.error('XML version is missing or invalid');\n } else if (!/^1\\.[0-9]+$/.test(version)) {\n throw this.error('Invalid character in version number');\n }\n\n if (this.consumeWhitespace()) {\n let encoding = Boolean(scanner.consumeStringFast('encoding'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (encoding) {\n this.consumeWhitespace();\n }\n\n let standalone = Boolean(scanner.consumeStringFast('standalone'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (standalone) {\n if (standalone !== 'yes' && standalone !== 'no') {\n throw this.error('Only \"yes\" and \"no\" are permitted as values of `standalone`');\n }\n\n this.consumeWhitespace();\n }\n }\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Invalid or unclosed XML declaration');\n }\n\n return true;\n }\n\n /**\n * Throws an error at the current scanner position.\n */\n error(message: string) {\n let { charIndex, string: xml } = this.scanner;\n let column = 1;\n let excerpt = '';\n let line = 1;\n\n // Find the line and column where the error occurred.\n for (let i = 0; i < charIndex; ++i) {\n let char = xml[i];\n\n if (char === '\\n') {\n column = 1;\n excerpt = '';\n line += 1;\n } else {\n column += 1;\n excerpt += char;\n }\n }\n\n let eol = xml.indexOf('\\n', charIndex);\n\n excerpt += eol === -1\n ? xml.slice(charIndex)\n : xml.slice(charIndex, eol);\n\n let excerptStart = 0;\n\n // Keep the excerpt below 50 chars, but always keep the error position in\n // view.\n if (excerpt.length > 50) {\n if (column < 40) {\n excerpt = excerpt.slice(0, 50);\n } else {\n excerptStart = column - 20;\n excerpt = excerpt.slice(excerptStart, column + 30);\n }\n }\n\n let err = new Error(\n `${message} (line ${line}, column ${column})\\n`\n + ` ${excerpt}\\n`\n + ' '.repeat(column - excerptStart + 1) + '^\\n',\n );\n\n Object.assign(err, {\n column,\n excerpt,\n line,\n pos: charIndex,\n });\n\n return err;\n }\n\n /**\n * Throws an invalid character error if any character in the given _string_\n * isn't a valid XML character.\n */\n validateChars(string: string) {\n let { length } = string;\n\n for (let i = 0; i < length; ++i) {\n let cp = string.codePointAt(i) as number;\n\n if (!syntax.isXmlCodePoint(cp)) {\n this.scanner.reset(-([ ...string ].length - i));\n throw this.error('Invalid character');\n }\n\n if (cp > 65535) {\n i += 1;\n }\n }\n }\n}\n\n// -- Private Functions --------------------------------------------------------\n\n/**\n * Normalizes the given XML string by stripping a byte order mark (if present)\n * and replacing CRLF sequences and lone CR characters with LF characters.\n */\nfunction normalizeXmlString(xml: string): string {\n if (xml[0] === '\\uFEFF') {\n xml = xml.slice(1);\n }\n\n return xml.replace(/\\r\\n?/g, '\\n');\n}\n\n// -- Types --------------------------------------------------------------------\nexport type ParserOptions = {\n /**\n * When `true`, an undefined named entity (like \"&bogus;\") will be left in the\n * output as is instead of causing a parse error.\n *\n * @default false\n */\n ignoreUndefinedEntities?: boolean;\n\n /**\n * When `true`, CDATA sections will be preserved in the document as `XmlCdata`\n * nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,\n * which keeps the node tree simpler and easier to work with.\n *\n * @default false\n */\n preserveCdata?: boolean;\n\n /**\n * When `true`, comments will be preserved in the document as `XmlComment`\n * nodes. Otherwise comments will not be included in the node tree.\n *\n * @default false\n */\n preserveComments?: boolean;\n\n /**\n * When an undefined named entity is encountered, this function will be called\n * with the entity as its only argument. It should return a string value with\n * which to replace the entity, or `null` or `undefined` to treat the entity\n * as undefined (which may result in a parse error depending on the value of\n * `ignoreUndefinedEntities`).\n */\n resolveUndefinedEntity?: (entity: string) => string | null | undefined;\n\n /**\n * When `true`, attributes in an element's `attributes` object will be sorted\n * in alphanumeric order by name. Otherwise they'll retain their original\n * order as found in the XML.\n *\n * @default false\n */\n sortAttributes?: boolean;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,cAAc;AACpB,IAAM,gBAAgB;AAGf,IAAM,gBAAN,MAAoB;AAAA,EASzB,YAAY,QAAgB;AAC1B,SAAKA,IAAY,KAAKC,EAAW,QAAQ,IAAI;AAC7C,SAAKC,IAAY;AACjB,SAAK,SAAS,OAAO;AACrB,SAAKC,IAAgB,KAAKH,MAAc,KAAK;AAC7C,SAAK,SAAS;AAEd,QAAI,KAAKG,GAAe;AACtB,UAAI,eAAe,CAAC;AAKpB,eAAS,YAAY,GAAG,YAAY,GAAG,YAAY,KAAKH,GAAW,EAAE,WAAW;AAC9E,qBAAa,aAAa;AAC1B,qBAAc,OAAO,YAAY,SAAS,IAAe,QAAQ,IAAI;AAAA,MACvE;AAEA,WAAKI,IAAe;AAAA,IACtB;AAAA,EACF;AAAA,EAKA,IAAIC,IAAQ;AACV,WAAO,KAAKH,KAAa,KAAKF;AAAA,EAChC;AAAA,EAQUM,EAAqB,YAAoB,KAAKJ,GAAmB;AAhD7E;AAiDI,WAAO,KAAKC,KACP,UAAKC,EAA0B,eAA/B,YAA6C,WAC9C;AAAA,EACN;AAAA,EAMUH,EAAW,QAAgB,gBAAgB,KAAKE,GA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MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IACP,CAAC;AAED,WAAO;AAAA,EACT;AAAA,EAMAgB,EAAc,QAAgB;AAC5B,QAAI,EAAE,OAAO,IAAI;AAEjB,aAAS,IAAI,GAAG,IAAI,QAAQ,EAAE,GAAG;AAC/B,UAAI,KAAK,OAAO,YAAY,CAAC;AAE7B,UAAI,CAAQ,eAAe,EAAE,GAAG;AAC9B,aAAKhB,EAAQ2B,EAAM,EAAE,CAAE,GAAG,MAAO,EAAE,SAAS,EAAE;AAC9C,cAAM,KAAKxB,EAAM,mBAAmB;AAAA,MACtC;AAEA,UAAI,KAAK,OAAO;AACd,aAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACF;AAQA,SAAS,mBAAmB,KAAqB;AAC/C,MAAI,IAAI,OAAO,UAAU;AACvB,UAAM,IAAI,MAAM,CAAC;AAAA,EACnB;AAEA,SAAO,IAAI,QAAQ,UAAU,IAAI;AACnC;;;AVzuBO,SAAS,SAAS,KAAa,SAAyB;AAC7D,SAAQ,IAAI,OAAO,KAAK,OAAO,EAAG;AACpC;",
6
6
  "names": ["charCount", "charLength", "charIndex", "multiByteMode", "charsToBytes", "isEnd", "charIndexToByteIndex", "advance", "consume", "peek", "consumeMatch", "consumeMatchFn", "consumeString", "consumeStringFast", "consumeUntilMatch", "consumeUntilString", "reset", "emptyString", "currentNode", "scanner", "consumeProlog", "consumeElement", "error", "consumeMisc", "isEnd", "addNode", "addText", "consumeAttributes", "consumeWhitespace", "consumeName", "consumeEqual", "consumeAttributeValue", "peek", "advance", "consumeMatch", "validateChars", "consumeReference", "consumeCdataSection", "consumeStringFast", "consumeUntilString", "consumeCharData", "consumeUntilMatch", "consumeComment", "consumeContentReference", "consumeDoctypeDeclaration", "charIndex", "reset", "consumeProcessingInstruction", "consumeMatchFn", "consumeXmlDeclaration", "consume", "consumeSystemLiteral"]
7
7
  }
@@ -1,4 +1,4 @@
1
- /*! @rgrove/parse-xml v4.0.0 | ISC License | Copyright Ryan Grove */
1
+ /*! @rgrove/parse-xml v4.0.1 | ISC License | Copyright Ryan Grove */
2
2
  "use strict";var parseXml=(()=>{var X=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var R=(n,t)=>{for(var e in t)X(n,e,{get:t[e],enumerable:!0})},_=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of J(t))!U.call(n,i)&&i!==e&&X(n,i,{get:()=>t[i],enumerable:!(r=M(t,i))||r.enumerable});return n};var Y=n=>_(X({},"__esModule",{value:!0}),n);var W={};R(W,{XmlCdata:()=>d,XmlComment:()=>p,XmlDocument:()=>x,XmlElement:()=>a,XmlNode:()=>s,XmlProcessingInstruction:()=>f,XmlText:()=>u,parseXml:()=>V});var c="",$=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,g=class{constructor(t){if(this.l=this.c(t,!0),this.i=0,this.length=t.length,this.h=this.l!==this.length,this.string=t,this.h){let e=[];for(let r=0,i=0;i<this.l;++i)e[i]=r,r+=t.codePointAt(r)>65535?2:1;this.E=e}}get O(){return this.i>=this.l}f(t=this.i){var e;return this.h?(e=this.E[t])!=null?e:1/0:t}c(t,e=this.h){return e?t.replace($,"_").length:t.length}s(t=1){this.i=Math.min(this.l,this.i+t)}D(t=1){let e=this.o(t);return this.s(t),e}y(t){if(!t.sticky)throw new Error('`regex` must have a sticky flag ("y")');t.lastIndex=this.f();let e=t.exec(this.string);if(e===null||e.length===0)return c;let r=e[0];return this.s(this.c(r)),r}b(t){let e,r=c;for(;(e=this.o())&&t(e);)r+=e,this.s();return r}_(t){if(this.e(t))return t;if(this.h){let{length:e}=t,r=this.c(t);if(r!==e&&t===this.o(r))return this.s(r),t}return c}e(t){let{length:e}=t;return this.o(e)===t?(this.s(e),t):c}T(t){let e=this.string.slice(this.f()),r=e.search(t);if(r<=0)return c;let i=e.slice(0,r);return this.s(this.c(i)),i}p(t){let{string:e}=this,r=this.f(),i=e.indexOf(t,r);if(i<=0)return c;let o=e.slice(r,i);return this.s(this.c(o)),o}o(t=1){let{i:e,h:r,string:i}=this;return r?e>=this.l?c:i.slice(this.f(e),this.f(e+t)):i.slice(e,e+t)}d(t=0){this.i=t>=0?Math.min(this.l,t):Math.max(0,this.i+t)}};var P=/[^"&<]+/y,D=/[^'&<]+/y,T=/[\t\n]/g,j=/<|&|]]>/,S=Object.freeze(Object.assign(Object.create(null),{amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}));function w(n){let t=C(n);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===45||t===46||t===183||t>=768&&t<=879||t>=8255&&t<=8256||v(n,t)}function v(n,t=C(n)){return t>=97&&t<=122||t>=65&&t<=90||t===58||t===95||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t>=8204&&t<=8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}function I(n){return n==="#"||w(n)}function A(n){let t=C(n);return t===32||t===9||t===10||t===13}function E(n){return n===9||n===10||n===13||n>=32&&n<=55295||n>=57344&&n<=65533||n>=65536&&n<=1114111}function C(n){return n.codePointAt(0)||-1}var s=class{constructor(){this.parent=null}get document(){var t,e;return(e=(t=this.parent)==null?void 0:t.document)!=null?e:null}get isRootNode(){return this.parent!==null&&this.parent===this.document}get preserveWhitespace(){var t;return Boolean((t=this.parent)==null?void 0:t.preserveWhitespace)}get type(){return""}toJSON(){let t={type:this.type};return this.isRootNode&&(t.isRootNode=!0),this.preserveWhitespace&&(t.preserveWhitespace=!0),t}};s.TYPE_CDATA="cdata",s.TYPE_COMMENT="comment",s.TYPE_DOCUMENT="document",s.TYPE_ELEMENT="element",s.TYPE_PROCESSING_INSTRUCTION="pi",s.TYPE_TEXT="text";var u=class extends s{constructor(e=""){super();this.text=e}get type(){return s.TYPE_TEXT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{text:this.text})}};var d=class extends u{get type(){return s.TYPE_CDATA}};var p=class extends s{constructor(e=""){super();this.content=e}get type(){return s.TYPE_COMMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{content:this.content})}};var a=class extends s{constructor(e,r=Object.create(null),i=[]){super();this.name=e,this.attributes=r,this.children=i}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let e=this;for(;e instanceof a;){if("xml:space"in e.attributes)return e.attributes["xml:space"]==="preserve";e=e.parent}return!1}get text(){return this.children.map(e=>"text"in e?e.text:"").join("")}get type(){return s.TYPE_ELEMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(e=>e.toJSON())})}};var x=class extends s{constructor(e=[]){super();this.children=e}get document(){return this}get root(){for(let e of this.children)if(e instanceof a)return e;return null}get text(){return this.children.map(e=>"text"in e?e.text:"").join("")}get type(){return s.TYPE_DOCUMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{children:this.children.map(e=>e.toJSON())})}};var f=class extends s{constructor(e,r=""){super();this.name=e,this.content=r}get type(){return s.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{name:this.name,content:this.content})}};var O="",y=class{constructor(t,e={}){if(this.document=new x,this.a=this.document,this.options=e,this.r=new g(k(t)),this.j(),!this.C())throw this.t("Root element is missing or invalid");for(;this.X(););if(!this.r.O)throw this.t("Extra content at the end of the document")}m(t){t.parent=this.a,this.a.children.push(t)}w(t){let{children:e}=this.a,{length:r}=e;if(r>0){let i=e[r-1];if(i instanceof u){i.text+=t;return}}this.m(new u(t))}S(){let t=Object.create(null);for(;this.n();){let e=this.x();if(!e)break;let r=this.g()&&this.I();if(r===!1)throw this.t("Attribute value expected");if(e in t)throw this.t(`Duplicate attribute: ${e}`);if(e==="xml:space"&&r!=="default"&&r!=="preserve")throw this.t('Value of the `xml:space` attribute must be "default" or "preserve"');t[e]=r}if(this.options.sortAttributes){let e=Object.keys(t).sort(),r=Object.create(null);for(let i=0;i<e.length;++i){let o=e[i];r[o]=t[o]}t=r}return t}I(){let{r:t}=this,e=t.o();if(e!=='"'&&e!=="'")return!1;t.s();let r,i=!1,o=O,l=e==='"'?P:D;t:for(;!t.O;)switch(r=t.y(l),r&&(this.u(r),o+=r.replace(T," ")),t.o()){case e:i=!0;break t;case"&":o+=this.N();continue;case"<":throw this.t("Unescaped `<` is not allowed in an attribute value");case O:break t}if(!i)throw this.t("Unclosed attribute");return t.s(),o}A(){let{r:t}=this;if(!t.e("<![CDATA["))return!1;let e=t.p("]]>");if(this.u(e),!t.e("]]>"))throw this.t("Unclosed CDATA section");return this.options.preserveCdata?this.m(new d(e)):this.w(e),!0}J(){let{r:t}=this,e=t.T(j);if(!e)return!1;if(this.u(e),t.o(3)==="]]>")throw this.t("Element content may not contain the CDATA section close delimiter `]]>`");return this.w(e),!0}F(){let{r:t}=this;if(!t.e("<!--"))return!1;let e=t.p("--");if(this.u(e),!t.e("-->"))throw t.o(2)==="--"?this.t("The string `--` isn't allowed inside a comment"):this.t("Unclosed comment");return this.options.preserveComments&&this.m(new p(e.trim())),!0}M(){let t=this.N();return t?(this.w(t),!0):!1}U(){let{r:t}=this;if(!t.e("<!DOCTYPE")||!this.n())return!1;if(t.y(/[^[>]+/y),t.y(/\[[\s\S]+?\][\x20\t\r\n]*>/y))return!0;if(!t.e(">"))throw this.t("Unclosed doctype declaration");return!0}C(){let{r:t}=this,e=t.i;if(!t.e("<"))return!1;let r=this.x();if(!r)return t.d(e),!1;let i=this.S(),o=Boolean(t.e("/>")),l=new a(r,i);if(l.parent=this.a,!o){if(!t.e(">"))throw this.t(`Unclosed start tag for element \`${r}\``);this.a=l;do this.J();while(this.C()||this.M()||this.A()||this.P()||this.F());let h=t.i,m;if(!t.e("</")||!(m=this.x())||m!==r)throw t.d(h),this.t(`Missing end tag for element ${r}`);if(this.n(),!t.e(">"))throw this.t(`Unclosed end tag for element ${r}`);this.a=l.parent}return this.m(l),!0}g(){return this.n(),this.r.e("=")?(this.n(),!0):!1}X(){return this.F()||this.P()||this.n()}x(){return v(this.r.o())?this.r.b(w):O}P(){let{r:t}=this,e=t.i;if(!t.e("<?"))return!1;let r=this.x();if(r){if(r.toLowerCase()==="xml")throw t.d(e),this.t("XML declaration isn't allowed here")}else throw this.t("Invalid processing instruction");if(!this.n()){if(t.e("?>"))return this.m(new f(r)),!0;throw this.t("Whitespace is required after a processing instruction name")}let i=t.p("?>");if(this.u(i),!t.e("?>"))throw this.t("Unterminated processing instruction");return this.m(new f(r,i)),!0}j(){let{r:t}=this,e=t.i;for(this.R();this.X(););if(this.U())for(;this.X(););return e<t.i}N(){let{r:t}=this;if(!t.e("&"))return!1;let e=t.b(I);if(t.D()!==";")throw this.t("Unterminated reference (a reference must end with `;`)");let r;if(e[0]==="#"){let i=e[1]==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10);if(isNaN(i))throw this.t("Invalid character reference");if(!E(i))throw this.t("Character reference resolves to an invalid character");r=String.fromCodePoint(i)}else if(r=S[e],r===void 0){let{ignoreUndefinedEntities:i,resolveUndefinedEntity:o}=this.options,l=`&${e};`;if(o){let h=o(l);if(h!=null){let m=typeof h;if(m!=="string")throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${m}`);return h}}if(i)return l;throw t.d(-l.length),this.t(`Named entity isn't defined: ${l}`)}return r}v(){let{r:t}=this,e=t.e('"')||t.e("'");if(!e)return!1;let r=t.p(e);if(this.u(r),!t.e(e))throw this.t("Missing end quote");return r}n(){return Boolean(this.r.b(A))}R(){let{r:t}=this;if(!t.e("<?xml"))return!1;if(!this.n())throw this.t("Invalid XML declaration");let e=Boolean(t.e("version"))&&this.g()&&this.v();if(e===!1)throw this.t("XML version is missing or invalid");if(!/^1\.[0-9]+$/.test(e))throw this.t("Invalid character in version number");if(this.n()){Boolean(t.e("encoding"))&&this.g()&&this.v()&&this.n();let i=Boolean(t.e("standalone"))&&this.g()&&this.v();if(i){if(i!=="yes"&&i!=="no")throw this.t('Only "yes" and "no" are permitted as values of `standalone`');this.n()}}if(!t.e("?>"))throw this.t("Invalid or unclosed XML declaration");return!0}t(t){let{i:e,string:r}=this.r,i=1,o="",l=1;for(let b=0;b<e;++b){let F=r[b];F===`
3
3
  `?(i=1,o="",l+=1):(i+=1,o+=F)}let h=r.indexOf(`
4
4
  `,e);o+=h===-1?r.slice(e):r.slice(e,h);let m=0;o.length>50&&(i<40?o=o.slice(0,50):(m=i-20,o=o.slice(m,i+30)));let N=new Error(`${t} (line ${l}, column ${i})
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/lib/StringScanner.ts", "../src/lib/syntax.ts", "../src/lib/XmlNode.ts", "../src/lib/XmlText.ts", "../src/lib/XmlCdata.ts", "../src/lib/XmlComment.ts", "../src/lib/XmlElement.ts", "../src/lib/XmlDocument.ts", "../src/lib/XmlProcessingInstruction.ts", "../src/lib/Parser.ts"],
4
- "sourcesContent": ["import { Parser } from './lib/Parser.js';\n\nimport type { ParserOptions } from './lib/Parser.js';\n\nexport * from './lib/types.js';\nexport { XmlCdata } from './lib/XmlCdata.js';\nexport { XmlComment } from './lib/XmlComment.js';\nexport { XmlDocument } from './lib/XmlDocument.js';\nexport { XmlElement } from './lib/XmlElement.js';\nexport { XmlNode } from './lib/XmlNode.js';\nexport { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';\nexport { XmlText } from './lib/XmlText.js';\n\nexport type { ParserOptions } from './lib/Parser.js';\n\n/**\n * Parses the given XML string and returns an `XmlDocument` instance\n * representing the document tree.\n *\n * @example\n *\n * import { parseXml } from '@rgrove/parse-xml';\n * let doc = parseXml('<kittens fuzzy=\"yes\">I like fuzzy kittens.</kittens>');\n *\n * @param xml XML string to parse.\n * @param options Parser options.\n */\nexport function parseXml(xml: string, options: ParserOptions) {\n return (new Parser(xml, options)).document;\n}\n", "const emptyString = '';\nconst surrogatePair = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\n/** @private */\nexport class StringScanner {\n charIndex: number;\n readonly string: string;\n\n private readonly charCount: number;\n private readonly charsToBytes: number[] | undefined;\n private readonly length: number;\n private readonly multiByteMode: boolean;\n\n constructor(string: string) {\n this.charCount = this.charLength(string, true);\n this.charIndex = 0;\n this.length = string.length;\n this.multiByteMode = this.charCount !== this.length;\n this.string = string;\n\n if (this.multiByteMode) {\n let charsToBytes = [];\n\n // Create a mapping of character indexes to byte indexes. Since the string\n // contains multibyte characters, a byte index may not necessarily align\n // with a character index.\n for (let byteIndex = 0, charIndex = 0; charIndex < this.charCount; ++charIndex) {\n charsToBytes[charIndex] = byteIndex;\n byteIndex += (string.codePointAt(byteIndex) as number) > 65535 ? 2 : 1;\n }\n\n this.charsToBytes = charsToBytes;\n }\n }\n\n /**\n * Whether the current character index is at the end of the input string.\n */\n get isEnd() {\n return this.charIndex >= this.charCount;\n }\n\n // -- Protected Methods ------------------------------------------------------\n\n /**\n * Returns the byte index of the given character index in the string. The two\n * may differ in strings that contain multibyte characters.\n */\n protected charIndexToByteIndex(charIndex: number = this.charIndex): number {\n return this.multiByteMode\n ? (this.charsToBytes as number[])[charIndex] ?? Infinity\n : charIndex;\n }\n\n /**\n * Returns the number of characters in the given string, which may differ from\n * the byte length if the string contains multibyte characters.\n */\n protected charLength(string: string, multiByteSafe = this.multiByteMode): number {\n // We could get the char length with `[ ...string ].length`, but that's\n // actually slower than replacing surrogate pairs with single-byte\n // characters and then counting the result.\n return multiByteSafe\n ? string.replace(surrogatePair, '_').length\n : string.length;\n }\n\n // -- Public Methods ---------------------------------------------------------\n\n /**\n * Advances the scanner by the given number of characters, stopping if the end\n * of the string is reached.\n */\n advance(count = 1) {\n this.charIndex = Math.min(this.charCount, this.charIndex + count);\n }\n\n /**\n * Consumes and returns the given number of characters if possible, advancing\n * the scanner and stopping if the end of the string is reached.\n *\n * If no characters could be consumed, an empty string will be returned.\n */\n consume(count = 1): string {\n let chars = this.peek(count);\n this.advance(count);\n return chars;\n }\n\n /**\n * Consumes a match for the given sticky regex, advances the scanner, updates\n * the `lastIndex` property of the regex, and returns the matching string.\n *\n * The regex must have a sticky flag (\"y\") so that its `lastIndex` prop can be\n * used to anchor the match at the current scanner position.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeMatch(regex: RegExp): string {\n if (!regex.sticky) {\n throw new Error('`regex` must have a sticky flag (\"y\")');\n }\n\n regex.lastIndex = this.charIndexToByteIndex();\n\n let result = regex.exec(this.string);\n\n if (result === null || result.length === 0) {\n return emptyString;\n }\n\n let match = result[0] as string;\n this.advance(this.charLength(match));\n return match;\n }\n\n /**\n * Consumes and returns all characters for which the given function returns a\n * truthy value, stopping on the first falsy return value or if the end of the\n * input is reached.\n */\n consumeMatchFn(fn: (char: string) => boolean): string {\n let char;\n let match = emptyString;\n\n while ((char = this.peek()) && fn(char)) {\n match += char;\n this.advance();\n }\n\n return match;\n }\n\n /**\n * Consumes the given string if it exists at the current character index, and\n * advances the scanner.\n *\n * If the given string doesn't exist at the current character index, an empty\n * string will be returned and the scanner will not be advanced.\n */\n consumeString(stringToConsume: string): string {\n if (this.consumeStringFast(stringToConsume)) {\n return stringToConsume;\n }\n\n if (this.multiByteMode) {\n let { length } = stringToConsume;\n let charLengthToMatch = this.charLength(stringToConsume);\n\n if (charLengthToMatch !== length\n && stringToConsume === this.peek(charLengthToMatch)) {\n\n this.advance(charLengthToMatch);\n return stringToConsume;\n }\n }\n\n return emptyString;\n }\n\n /**\n * Does the same thing as `consumeString()`, but doesn't support consuming\n * multibyte characters. This can be faster if you only need to match single\n * byte characters.\n */\n consumeStringFast(stringToConsume: string): string {\n let { length } = stringToConsume;\n\n if (this.peek(length) === stringToConsume) {\n this.advance(length);\n return stringToConsume;\n }\n\n return emptyString;\n }\n\n /**\n * Consumes characters until the given global regex is matched, advancing the\n * scanner up to (but not beyond) the beginning of the match. If the regex\n * doesn't match, nothing will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilMatch(regex: RegExp): string {\n let restOfString = this.string.slice(this.charIndexToByteIndex());\n let matchByteIndex = restOfString.search(regex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = restOfString.slice(0, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Consumes characters until the given string is found, advancing the scanner\n * up to (but not beyond) that point. If the string is never found, nothing\n * will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilString(searchString: string): string {\n let { string } = this;\n let byteIndex = this.charIndexToByteIndex();\n let matchByteIndex = string.indexOf(searchString, byteIndex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = string.slice(byteIndex, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Returns the given number of characters starting at the current character\n * index, without advancing the scanner and without exceeding the end of the\n * input string.\n */\n peek(count = 1): string {\n let { charIndex, multiByteMode, string } = this;\n\n if (multiByteMode) {\n // Inlining this comparison instead of checking `this.isEnd` improves perf\n // slightly since `peek()` is called so frequently.\n if (charIndex >= this.charCount) {\n return emptyString;\n }\n\n return string.slice(\n this.charIndexToByteIndex(charIndex),\n this.charIndexToByteIndex(charIndex + count),\n );\n }\n\n return string.slice(charIndex, charIndex + count);\n }\n\n /**\n * Resets the scanner position to the given character _index_, or to the start\n * of the input string if no index is given.\n *\n * If _index_ is negative, the scanner position will be moved backward by that\n * many characters, stopping if the beginning of the string is reached.\n */\n reset(index = 0) {\n this.charIndex = index >= 0\n ? Math.min(this.charCount, index)\n : Math.max(0, this.charIndex + index);\n }\n}\n", "/**\n * Regular expression that matches one or more `AttValue` characters in a\n * double-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharDoubleQuote = /[^\"&<]+/y;\n\n/**\n * Regular expression that matches one or more `AttValue` characters in a\n * single-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharSingleQuote = /[^'&<]+/y;\n\n/**\n * Regular expression that matches a whitespace character that should be\n * normalized to a space character in an attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize\n */\nexport const attValueNormalizedWhitespace = /[\\t\\n]/g;\n\n/**\n * Regular expression that matches one or more characters that signal the end of\n * XML `CharData` content.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\nexport const endCharData = /<|&|]]>/;\n\n/**\n * Mapping of predefined entity names to their replacement values.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent\n */\nexport const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {\n amp: '&',\n apos: \"'\",\n gt: '>',\n lt: '<',\n quot: '\"',\n}));\n\n/**\n * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar\n */\nexport function isNameChar(char: string): boolean {\n let cp = getCodePoint(char);\n\n // Including the most common NameStartChars here improves performance\n // slightly.\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || (cp >= 0x30 && cp <= 0x39) // 0-9\n || cp === 0x2D // -\n || cp === 0x2E // .\n || cp === 0xB7\n || (cp >= 0x300 && cp <= 0x36F)\n || (cp >= 0x203F && cp <= 0x2040)\n || isNameStartChar(char, cp);\n}\n\n/**\n * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar\n */\nexport function isNameStartChar(char: string, cp = getCodePoint(char)): boolean {\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || cp === 0x3A // :\n || cp === 0x5F // _\n || (cp >= 0xC0 && cp <= 0xD6)\n || (cp >= 0xD8 && cp <= 0xF6)\n || (cp >= 0xF8 && cp <= 0x2FF)\n || (cp >= 0x370 && cp <= 0x37D)\n || (cp >= 0x37F && cp <= 0x1FFF)\n || (cp >= 0x200C && cp <= 0x200D)\n || (cp >= 0x2070 && cp <= 0x218F)\n || (cp >= 0x2C00 && cp <= 0x2FEF)\n || (cp >= 0x3001 && cp <= 0xD7FF)\n || (cp >= 0xF900 && cp <= 0xFDCF)\n || (cp >= 0xFDF0 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0xEFFFF);\n}\n\n/**\n * Returns `true` if _char_ is a valid reference character (which may appear\n * between `&` and `;` in a reference), `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references\n */\nexport function isReferenceChar(char: string): boolean {\n return char === '#' || isNameChar(char);\n}\n\n/**\n * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\nexport function isWhitespace(char: string): boolean {\n let cp = getCodePoint(char);\n\n return cp === 0x20\n || cp === 0x9\n || cp === 0xA\n || cp === 0xD;\n}\n\n/**\n * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`\n * otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char\n */\nexport function isXmlCodePoint(cp: number): boolean {\n return cp === 0x9\n || cp === 0xA\n || cp === 0xD\n || (cp >= 0x20 && cp <= 0xD7FF)\n || (cp >= 0xE000 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0x10FFFF);\n}\n\n/**\n * Returns the Unicode code point value of the given character, or `-1` if\n * _char_ is empty.\n */\nfunction getCodePoint(char: string): number {\n return char.codePointAt(0) || -1;\n}\n", "import type { JsonObject } from './types.js';\nimport type { XmlDocument } from './XmlDocument.js';\nimport type { XmlElement } from './XmlElement.js';\n\n/**\n * Base interface for a node in an XML document.\n */\nexport class XmlNode {\n /**\n * Type value for an `XmlCdata` node.\n */\n static readonly TYPE_CDATA = 'cdata';\n\n /**\n * Type value for an `XmlComment` node.\n */\n static readonly TYPE_COMMENT = 'comment';\n\n /**\n * Type value for an `XmlDocument` node.\n */\n static readonly TYPE_DOCUMENT = 'document';\n\n /**\n * Type value for an `XmlElement` node.\n */\n static readonly TYPE_ELEMENT = 'element';\n\n /**\n * Type value for an `XmlProcessingInstruction` node.\n */\n static readonly TYPE_PROCESSING_INSTRUCTION = 'pi';\n\n /**\n * Type value for an `XmlText` node.\n */\n static readonly TYPE_TEXT = 'text';\n\n /**\n * Parent node of this node, or `null` if this node has no parent.\n */\n parent: XmlDocument | XmlElement | null = null;\n\n /**\n * Document that contains this node, or `null` if this node is not associated\n * with a document.\n */\n get document(): XmlDocument | null {\n return this.parent?.document ?? null;\n }\n\n /**\n * Whether this node is the root node of the document.\n */\n get isRootNode(): boolean {\n return this.parent !== null && this.parent === this.document;\n }\n\n /**\n * Whether whitespace should be preserved in the content of this element and\n * its children.\n *\n * This is influenced by the value of the special `xml:space` attribute, and\n * will be `true` for any node whose `xml:space` attribute is set to\n * \"preserve\". If a node has no such attribute, it will inherit the value of\n * the nearest ancestor that does (if any).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space\n */\n get preserveWhitespace(): boolean {\n return Boolean(this.parent?.preserveWhitespace);\n }\n\n /**\n * Type of this node.\n *\n * The value of this property is a string that matches one of the static\n * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,\n * `TYPE_TEXT`, etc.).\n *\n * The `XmlNode` class itself is a base class and doesn't have its own type\n * name.\n */\n get type() {\n return '';\n }\n\n /**\n * Returns a JSON-serializable object representing this node, minus properties\n * that could result in circular references.\n */\n toJSON(): JsonObject {\n let json: JsonObject = {\n type: this.type,\n };\n\n if (this.isRootNode) {\n json.isRootNode = true;\n }\n\n if (this.preserveWhitespace) {\n json.preserveWhitespace = true;\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * Text content within an XML document.\n */\nexport class XmlText extends XmlNode {\n /**\n * Text content of this node.\n */\n text: string;\n\n constructor(text = '') {\n super();\n this.text = text;\n }\n\n override get type() {\n return XmlNode.TYPE_TEXT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n text: this.text,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\nimport { XmlText } from './XmlText.js';\n\n/**\n * A CDATA section within an XML document.\n */\nexport class XmlCdata extends XmlText {\n override get type() {\n return XmlNode.TYPE_CDATA;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A comment within an XML document.\n */\nexport class XmlComment extends XmlNode {\n /**\n * Content of this comment.\n */\n content: string;\n\n constructor(content = '') {\n super();\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_COMMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n content: this.content,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\nimport type { JsonObject } from './types.js';\nimport type { XmlCdata } from './XmlCdata.js';\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport type { XmlText } from './XmlText.js';\n\n/**\n * Element in an XML document.\n */\nexport class XmlElement extends XmlNode {\n /**\n * Attributes on this element.\n */\n attributes: {[attrName: string]: string};\n\n /**\n * Child nodes of this element.\n */\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;\n\n /**\n * Name of this element.\n */\n name: string;\n\n constructor(\n name: string,\n attributes: {[attrName: string]: string} = Object.create(null),\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText> = [],\n ) {\n super();\n\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n\n /**\n * Whether this element is empty (meaning it has no children).\n */\n get isEmpty(): boolean {\n return this.children.length === 0;\n }\n\n override get preserveWhitespace(): boolean {\n let node: XmlNode | null = this; // eslint-disable-line @typescript-eslint/no-this-alias\n\n while (node instanceof XmlElement) {\n if ('xml:space' in node.attributes) {\n return node.attributes['xml:space'] === 'preserve';\n }\n\n node = node.parent;\n }\n\n return false;\n }\n\n /**\n * Text content of this element and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_ELEMENT;\n }\n\n override toJSON(): JsonObject {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n attributes: this.attributes,\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlElement } from './XmlElement.js';\nimport { XmlNode } from './XmlNode.js';\n\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\n\n/**\n * Represents an XML document. All elements within the document are descendants\n * of this node.\n */\nexport class XmlDocument extends XmlNode {\n /**\n * Child nodes of this document.\n */\n readonly children: Array<XmlComment | XmlProcessingInstruction | XmlElement>;\n\n constructor(children: Array<XmlComment | XmlElement | XmlProcessingInstruction> = []) {\n super();\n this.children = children;\n }\n\n override get document() {\n return this;\n }\n\n /**\n * Root element of this document, or `null` if this document is empty.\n */\n get root(): XmlElement | null {\n for (let child of this.children) {\n if (child instanceof XmlElement) {\n return child;\n }\n }\n\n return null;\n }\n\n /**\n * Text content of this document and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A processing instruction within an XML document.\n */\nexport class XmlProcessingInstruction extends XmlNode {\n /**\n * Content of this processing instruction.\n */\n content: string;\n\n /**\n * Name of this processing instruction. Also sometimes referred to as the\n * processing instruction \"target\".\n */\n name: string;\n\n constructor(name: string, content = '') {\n super();\n\n this.name = name;\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_PROCESSING_INSTRUCTION;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n content: this.content,\n });\n }\n}\n", "import { StringScanner } from './StringScanner.js';\nimport * as syntax from './syntax.js';\nimport { XmlCdata } from './XmlCdata.js';\nimport { XmlComment } from './XmlComment.js';\nimport { XmlDocument } from './XmlDocument.js';\nimport { XmlElement } from './XmlElement.js';\nimport { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport { XmlText } from './XmlText.js';\n\nimport type { XmlNode } from './XmlNode.js';\n\n\nconst emptyString = '';\n\n/**\n * Parses an XML string into an `XmlDocument`.\n *\n * @private\n */\nexport class Parser {\n readonly document: XmlDocument;\n\n private currentNode: XmlDocument | XmlElement;\n private readonly options: ParserOptions;\n private readonly scanner: StringScanner;\n\n /**\n * @param xml XML string to parse.\n * @param options Parser options.\n */\n constructor(xml: string, options: ParserOptions = {}) {\n this.document = new XmlDocument();\n this.currentNode = this.document;\n this.options = options;\n this.scanner = new StringScanner(normalizeXmlString(xml));\n\n this.consumeProlog();\n\n if (!this.consumeElement()) {\n throw this.error('Root element is missing or invalid');\n }\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (!this.scanner.isEnd) {\n throw this.error('Extra content at the end of the document');\n }\n }\n\n /**\n * Adds the given `XmlNode` as a child of `this.currentNode`.\n */\n addNode(node: XmlNode) {\n node.parent = this.currentNode;\n\n // @ts-expect-error: XmlDocument has a more limited set of possible children\n // than XmlElement so TypeScript is unhappy, but we always do the right\n // thing.\n this.currentNode.children.push(node);\n }\n\n /**\n * Adds the given _text_ to the document, either by appending it to a\n * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.\n */\n addText(text: string) {\n let { children } = this.currentNode;\n let { length } = children;\n\n if (length > 0) {\n let prevNode = children[length - 1];\n\n if (prevNode instanceof XmlText) {\n // The previous node is a text node, so we can append to it and avoid\n // creating another node.\n prevNode.text += text;\n return;\n }\n }\n\n this.addNode(new XmlText(text));\n }\n\n /**\n * Consumes element attributes.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags\n */\n consumeAttributes(): Record<string, string> {\n let attributes = Object.create(null);\n\n while (this.consumeWhitespace()) {\n let attrName = this.consumeName();\n\n if (!attrName) {\n break;\n }\n\n let attrValue = this.consumeEqual() && this.consumeAttributeValue();\n\n if (attrValue === false) {\n throw this.error('Attribute value expected');\n }\n\n if (attrName in attributes) {\n throw this.error(`Duplicate attribute: ${attrName}`);\n }\n\n if (attrName === 'xml:space'\n && attrValue !== 'default'\n && attrValue !== 'preserve') {\n\n throw this.error('Value of the `xml:space` attribute must be \"default\" or \"preserve\"');\n }\n\n attributes[attrName] = attrValue;\n }\n\n if (this.options.sortAttributes) {\n let attrNames = Object.keys(attributes).sort();\n let sortedAttributes = Object.create(null);\n\n for (let i = 0; i < attrNames.length; ++i) {\n let attrName = attrNames[i] as string;\n sortedAttributes[attrName] = attributes[attrName];\n }\n\n attributes = sortedAttributes;\n }\n\n return attributes;\n }\n\n /**\n * Consumes an `AttValue` (attribute value) if possible.\n *\n * @returns\n * Contents of the `AttValue` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that an `AttValue` was consumed but\n * was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\n consumeAttributeValue(): string | false {\n let { scanner } = this;\n let quote = scanner.peek();\n\n if (quote !== '\"' && quote !== \"'\") {\n return false;\n }\n\n scanner.advance();\n\n let chars;\n let isClosed = false;\n let value = emptyString;\n let regex = quote === '\"'\n ? syntax.attValueCharDoubleQuote\n : syntax.attValueCharSingleQuote;\n\n matchLoop: while (!scanner.isEnd) {\n chars = scanner.consumeMatch(regex);\n\n if (chars) {\n this.validateChars(chars);\n value += chars.replace(syntax.attValueNormalizedWhitespace, ' ');\n }\n\n switch (scanner.peek()) {\n case quote:\n isClosed = true;\n break matchLoop;\n\n case '&':\n value += this.consumeReference();\n continue;\n\n case '<':\n throw this.error('Unescaped `<` is not allowed in an attribute value');\n\n case emptyString:\n break matchLoop;\n }\n }\n\n if (!isClosed) {\n throw this.error('Unclosed attribute');\n }\n\n scanner.advance();\n return value;\n }\n\n /**\n * Consumes a CDATA section if possible.\n *\n * @returns Whether a CDATA section was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect\n */\n consumeCdataSection(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<![CDATA[')) {\n return false;\n }\n\n let text = scanner.consumeUntilString(']]>');\n this.validateChars(text);\n\n if (!scanner.consumeStringFast(']]>')) {\n throw this.error('Unclosed CDATA section');\n }\n\n if (this.options.preserveCdata) {\n this.addNode(new XmlCdata(text));\n } else {\n this.addText(text);\n }\n\n return true;\n }\n\n /**\n * Consumes character data if possible.\n *\n * @returns Whether character data was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\n consumeCharData(): boolean {\n let { scanner } = this;\n let charData = scanner.consumeUntilMatch(syntax.endCharData);\n\n if (!charData) {\n return false;\n }\n\n this.validateChars(charData);\n\n if (scanner.peek(3) === ']]>') {\n throw this.error('Element content may not contain the CDATA section close delimiter `]]>`');\n }\n\n this.addText(charData);\n return true;\n }\n\n /**\n * Consumes a comment if possible.\n *\n * @returns Whether a comment was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment\n */\n consumeComment(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!--')) {\n return false;\n }\n\n let content = scanner.consumeUntilString('--');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('-->')) {\n if (scanner.peek(2) === '--') {\n throw this.error(\"The string `--` isn't allowed inside a comment\");\n }\n\n throw this.error('Unclosed comment');\n }\n\n if (this.options.preserveComments) {\n this.addNode(new XmlComment(content.trim()));\n }\n\n return true;\n }\n\n /**\n * Consumes a reference in a content context if possible.\n *\n * This differs from `consumeReference()` in that a consumed reference will be\n * added to the document as a text node instead of returned.\n *\n * @returns Whether a reference was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc\n */\n consumeContentReference(): boolean {\n let ref = this.consumeReference();\n\n if (ref) {\n this.addText(ref);\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes a doctype declaration if possible.\n *\n * This is a loose implementation since doctype declarations are currently\n * discarded without further parsing.\n *\n * @returns Whether a doctype declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd\n */\n consumeDoctypeDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!DOCTYPE')\n || !this.consumeWhitespace()) {\n\n return false;\n }\n\n scanner.consumeMatch(/[^[>]+/y);\n\n if (scanner.consumeMatch(/\\[[\\s\\S]+?\\][\\x20\\t\\r\\n]*>/y)) {\n return true;\n }\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error('Unclosed doctype declaration');\n }\n\n return true;\n }\n\n /**\n * Consumes an element if possible.\n *\n * @returns Whether an element was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element\n */\n consumeElement(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (!name) {\n scanner.reset(mark);\n return false;\n }\n\n let attributes = this.consumeAttributes();\n let isEmpty = Boolean(scanner.consumeStringFast('/>'));\n let element = new XmlElement(name, attributes);\n\n element.parent = this.currentNode;\n\n if (!isEmpty) {\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed start tag for element \\`${name}\\``);\n }\n\n this.currentNode = element;\n\n do {\n this.consumeCharData();\n } while (\n this.consumeElement()\n || this.consumeContentReference()\n || this.consumeCdataSection()\n || this.consumeProcessingInstruction()\n || this.consumeComment()\n );\n\n let endTagMark = scanner.charIndex;\n let endTagName;\n\n if (!scanner.consumeStringFast('</')\n || !(endTagName = this.consumeName())\n || endTagName !== name) {\n\n scanner.reset(endTagMark);\n throw this.error(`Missing end tag for element ${name}`);\n }\n\n this.consumeWhitespace();\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed end tag for element ${name}`);\n }\n\n this.currentNode = element.parent;\n }\n\n this.addNode(element);\n return true;\n }\n\n /**\n * Consumes an `Eq` production if possible.\n *\n * @returns Whether an `Eq` production was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq\n */\n consumeEqual(): boolean {\n this.consumeWhitespace();\n\n if (this.scanner.consumeStringFast('=')) {\n this.consumeWhitespace();\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes `Misc` content if possible.\n *\n * @returns Whether anything was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc\n */\n consumeMisc(): boolean {\n return this.consumeComment()\n || this.consumeProcessingInstruction()\n || this.consumeWhitespace();\n }\n\n /**\n * Consumes one or more `Name` characters if possible.\n *\n * @returns `Name` characters, or an empty string if none were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name\n */\n consumeName(): string {\n return syntax.isNameStartChar(this.scanner.peek())\n ? this.scanner.consumeMatchFn(syntax.isNameChar)\n : emptyString;\n }\n\n /**\n * Consumes a processing instruction if possible.\n *\n * @returns Whether a processing instruction was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi\n */\n consumeProcessingInstruction(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<?')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (name) {\n if (name.toLowerCase() === 'xml') {\n scanner.reset(mark);\n throw this.error(\"XML declaration isn't allowed here\");\n }\n } else {\n throw this.error('Invalid processing instruction');\n }\n\n if (!this.consumeWhitespace()) {\n if (scanner.consumeStringFast('?>')) {\n this.addNode(new XmlProcessingInstruction(name));\n return true;\n }\n\n throw this.error('Whitespace is required after a processing instruction name');\n }\n\n let content = scanner.consumeUntilString('?>');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Unterminated processing instruction');\n }\n\n this.addNode(new XmlProcessingInstruction(name, content));\n return true;\n }\n\n /**\n * Consumes a prolog if possible.\n *\n * @returns Whether a prolog was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd\n */\n consumeProlog(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n this.consumeXmlDeclaration();\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (this.consumeDoctypeDeclaration()) {\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n }\n\n return mark < scanner.charIndex;\n }\n\n /**\n * Consumes a reference if possible.\n *\n * This differs from `consumeContentReference()` in that a consumed reference\n * will be returned rather than added to the document.\n *\n * @returns\n * Parsed reference value, or `false` if nothing was consumed (to\n * distinguish from a reference that resolves to an empty string).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference\n */\n consumeReference(): string | false {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('&')) {\n return false;\n }\n\n let ref = scanner.consumeMatchFn(syntax.isReferenceChar);\n\n if (scanner.consume() !== ';') {\n throw this.error('Unterminated reference (a reference must end with `;`)');\n }\n\n let parsedValue;\n\n if (ref[0] === '#') {\n // This is a character reference.\n let codePoint = ref[1] === 'x'\n ? parseInt(ref.slice(2), 16) // Hex codepoint.\n : parseInt(ref.slice(1), 10); // Decimal codepoint.\n\n if (isNaN(codePoint)) {\n throw this.error('Invalid character reference');\n }\n\n if (!syntax.isXmlCodePoint(codePoint)) {\n throw this.error('Character reference resolves to an invalid character');\n }\n\n parsedValue = String.fromCodePoint(codePoint);\n } else {\n // This is an entity reference.\n parsedValue = syntax.predefinedEntities[ref];\n\n if (parsedValue === undefined) {\n let {\n ignoreUndefinedEntities,\n resolveUndefinedEntity,\n } = this.options;\n\n let wrappedRef = `&${ref};`; // for backcompat with <= 2.x\n\n if (resolveUndefinedEntity) {\n let resolvedValue = resolveUndefinedEntity(wrappedRef);\n\n if (resolvedValue !== null && resolvedValue !== undefined) {\n let type = typeof resolvedValue;\n\n if (type !== 'string') {\n throw new TypeError(`\\`resolveUndefinedEntity()\\` must return a string, \\`null\\`, or \\`undefined\\`, but returned a value of type ${type}`);\n }\n\n return resolvedValue;\n }\n }\n\n if (ignoreUndefinedEntities) {\n return wrappedRef;\n }\n\n scanner.reset(-wrappedRef.length);\n throw this.error(`Named entity isn't defined: ${wrappedRef}`);\n }\n }\n\n return parsedValue;\n }\n\n /**\n * Consumes a `SystemLiteral` if possible.\n *\n * A `SystemLiteral` is similar to an attribute value, but allows the\n * characters `<` and `&` and doesn't replace references.\n *\n * @returns\n * Value of the `SystemLiteral` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that a `SystemLiteral` was consumed\n * but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral\n */\n consumeSystemLiteral(): string | false {\n let { scanner } = this;\n let quote = scanner.consumeStringFast('\"') || scanner.consumeStringFast(\"'\");\n\n if (!quote) {\n return false;\n }\n\n let value = scanner.consumeUntilString(quote);\n this.validateChars(value);\n\n if (!scanner.consumeStringFast(quote)) {\n throw this.error('Missing end quote');\n }\n\n return value;\n }\n\n /**\n * Consumes one or more whitespace characters if possible.\n *\n * @returns Whether any whitespace characters were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\n consumeWhitespace(): boolean {\n return Boolean(this.scanner.consumeMatchFn(syntax.isWhitespace));\n }\n\n /**\n * Consumes an XML declaration if possible.\n *\n * @returns Whether an XML declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl\n */\n consumeXmlDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<?xml')) {\n return false;\n }\n\n if (!this.consumeWhitespace()) {\n throw this.error('Invalid XML declaration');\n }\n\n let version = Boolean(scanner.consumeStringFast('version'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (version === false) {\n throw this.error('XML version is missing or invalid');\n } else if (!/^1\\.[0-9]+$/.test(version)) {\n throw this.error('Invalid character in version number');\n }\n\n if (this.consumeWhitespace()) {\n let encoding = Boolean(scanner.consumeStringFast('encoding'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (encoding) {\n this.consumeWhitespace();\n }\n\n let standalone = Boolean(scanner.consumeStringFast('standalone'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (standalone) {\n if (standalone !== 'yes' && standalone !== 'no') {\n throw this.error('Only \"yes\" and \"no\" are permitted as values of `standalone`');\n }\n\n this.consumeWhitespace();\n }\n }\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Invalid or unclosed XML declaration');\n }\n\n return true;\n }\n\n /**\n * Throws an error at the current scanner position.\n */\n error(message: string) {\n let { charIndex, string: xml } = this.scanner;\n let column = 1;\n let excerpt = '';\n let line = 1;\n\n // Find the line and column where the error occurred.\n for (let i = 0; i < charIndex; ++i) {\n let char = xml[i];\n\n if (char === '\\n') {\n column = 1;\n excerpt = '';\n line += 1;\n } else {\n column += 1;\n excerpt += char;\n }\n }\n\n let eol = xml.indexOf('\\n', charIndex);\n\n excerpt += eol === -1\n ? xml.slice(charIndex)\n : xml.slice(charIndex, eol);\n\n let excerptStart = 0;\n\n // Keep the excerpt below 50 chars, but always keep the error position in\n // view.\n if (excerpt.length > 50) {\n if (column < 40) {\n excerpt = excerpt.slice(0, 50);\n } else {\n excerptStart = column - 20;\n excerpt = excerpt.slice(excerptStart, column + 30);\n }\n }\n\n let err = new Error(\n `${message} (line ${line}, column ${column})\\n`\n + ` ${excerpt}\\n`\n + ' '.repeat(column - excerptStart + 1) + '^\\n',\n );\n\n Object.assign(err, {\n column,\n excerpt,\n line,\n pos: charIndex,\n });\n\n return err;\n }\n\n /**\n * Throws an invalid character error if any character in the given _string_\n * isn't a valid XML character.\n */\n validateChars(string: string) {\n let { length } = string;\n\n for (let i = 0; i < length; ++i) {\n let cp = string.codePointAt(i) as number;\n\n if (!syntax.isXmlCodePoint(cp)) {\n this.scanner.reset(-([ ...string ].length - i));\n throw this.error('Invalid character');\n }\n\n if (cp > 65535) {\n i += 1;\n }\n }\n }\n}\n\n// -- Private Functions --------------------------------------------------------\n\n/**\n * Normalizes the given XML string by stripping a byte order mark (if present)\n * and replacing CRLF sequences and lone CR characters with LF characters.\n */\nfunction normalizeXmlString(xml: string): string {\n if (xml[0] === '\\uFEFF') {\n xml = xml.slice(1);\n }\n\n return xml.replace(/\\r\\n?/g, '\\n');\n}\n\n// -- Types --------------------------------------------------------------------\nexport type ParserOptions = {\n /**\n * When `true`, an undefined named entity (like \"&bogus;\") will be left in the\n * output as is instead of causing a parse error.\n *\n * @default false\n */\n ignoreUndefinedEntities?: boolean;\n\n /**\n * When `true`, CDATA sections will be preserved in the document as `XmlCdata`\n * nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,\n * which keeps the node tree simpler and easier to work with.\n *\n * @default false\n */\n preserveCdata?: boolean;\n\n /**\n * When `true`, comments will be preserved in the document as `XmlComment`\n * nodes. Otherwise comments will not be included in the node tree.\n *\n * @default false\n */\n preserveComments?: boolean;\n\n /**\n * When an undefined named entity is encountered, this function will be called\n * with the entity as its only argument. It should return a string value with\n * which to replace the entity, or `null` or `undefined` to treat the entity\n * as undefined (which may result in a parse error depending on the value of\n * `ignoreUndefinedEntities`).\n */\n resolveUndefinedEntity?: (entity: string) => string | null | undefined;\n\n /**\n * When `true`, attributes in an element's `attributes` object will be sorted\n * in alphanumeric order by name. Otherwise they'll retain their original\n * order as found in the XML.\n *\n * @default false\n */\n sortAttributes?: boolean;\n};\n"],
5
- "mappings": ";4bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,eAAAC,EAAA,gBAAAC,EAAA,eAAAC,EAAA,YAAAC,EAAA,6BAAAC,EAAA,YAAAC,EAAA,aAAAC,ICAA,IAAMC,EAAc,GACdC,EAAgB,kCAGTC,EAAN,KAAoB,C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AEjB,QAASL,EAAI,EAAGA,EAAI3E,EAAQ,EAAE2E,EAAG,CAC/B,IAAIM,EAAKD,EAAO,YAAYL,CAAC,EAE7B,GAAI,CAAQf,EAAeqB,CAAE,EAC3B,WAAK9F,EAAQyD,EAAM,EAAE,CAAE,GAAGoC,CAAO,EAAE,OAASL,EAAE,EACxC,KAAKnF,EAAM,mBAAmB,EAGlCyF,EAAK,QACPN,GAAK,EAET,CACF,CACF,EAQA,SAAStF,EAAmBN,EAAqB,CAC/C,OAAIA,EAAI,KAAO,WACbA,EAAMA,EAAI,MAAM,CAAC,GAGZA,EAAI,QAAQ,SAAU;AAAA,CAAI,CACnC,CVzuBO,SAASmG,EAASC,EAAaC,EAAwB,CAC5D,OAAQ,IAAIC,EAAOF,EAAKC,CAAO,EAAG,QACpC",
4
+ "sourcesContent": ["import { Parser } from './lib/Parser.js';\n\nimport type { ParserOptions } from './lib/Parser.js';\n\nexport * from './lib/types.js';\nexport { XmlCdata } from './lib/XmlCdata.js';\nexport { XmlComment } from './lib/XmlComment.js';\nexport { XmlDocument } from './lib/XmlDocument.js';\nexport { XmlElement } from './lib/XmlElement.js';\nexport { XmlNode } from './lib/XmlNode.js';\nexport { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';\nexport { XmlText } from './lib/XmlText.js';\n\nexport type { ParserOptions } from './lib/Parser.js';\n\n/**\n * Parses the given XML string and returns an `XmlDocument` instance\n * representing the document tree.\n *\n * @example\n *\n * import { parseXml } from '@rgrove/parse-xml';\n * let doc = parseXml('<kittens fuzzy=\"yes\">I like fuzzy kittens.</kittens>');\n *\n * @param xml XML string to parse.\n * @param options Parser options.\n */\nexport function parseXml(xml: string, options?: ParserOptions) {\n return (new Parser(xml, options)).document;\n}\n", "const emptyString = '';\nconst surrogatePair = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\n/** @private */\nexport class StringScanner {\n charIndex: number;\n readonly string: string;\n\n private readonly charCount: number;\n private readonly charsToBytes: number[] | undefined;\n private readonly length: number;\n private readonly multiByteMode: boolean;\n\n constructor(string: string) {\n this.charCount = this.charLength(string, true);\n this.charIndex = 0;\n this.length = string.length;\n this.multiByteMode = this.charCount !== this.length;\n this.string = string;\n\n if (this.multiByteMode) {\n let charsToBytes = [];\n\n // Create a mapping of character indexes to byte indexes. Since the string\n // contains multibyte characters, a byte index may not necessarily align\n // with a character index.\n for (let byteIndex = 0, charIndex = 0; charIndex < this.charCount; ++charIndex) {\n charsToBytes[charIndex] = byteIndex;\n byteIndex += (string.codePointAt(byteIndex) as number) > 65535 ? 2 : 1;\n }\n\n this.charsToBytes = charsToBytes;\n }\n }\n\n /**\n * Whether the current character index is at the end of the input string.\n */\n get isEnd() {\n return this.charIndex >= this.charCount;\n }\n\n // -- Protected Methods ------------------------------------------------------\n\n /**\n * Returns the byte index of the given character index in the string. The two\n * may differ in strings that contain multibyte characters.\n */\n protected charIndexToByteIndex(charIndex: number = this.charIndex): number {\n return this.multiByteMode\n ? (this.charsToBytes as number[])[charIndex] ?? Infinity\n : charIndex;\n }\n\n /**\n * Returns the number of characters in the given string, which may differ from\n * the byte length if the string contains multibyte characters.\n */\n protected charLength(string: string, multiByteSafe = this.multiByteMode): number {\n // We could get the char length with `[ ...string ].length`, but that's\n // actually slower than replacing surrogate pairs with single-byte\n // characters and then counting the result.\n return multiByteSafe\n ? string.replace(surrogatePair, '_').length\n : string.length;\n }\n\n // -- Public Methods ---------------------------------------------------------\n\n /**\n * Advances the scanner by the given number of characters, stopping if the end\n * of the string is reached.\n */\n advance(count = 1) {\n this.charIndex = Math.min(this.charCount, this.charIndex + count);\n }\n\n /**\n * Consumes and returns the given number of characters if possible, advancing\n * the scanner and stopping if the end of the string is reached.\n *\n * If no characters could be consumed, an empty string will be returned.\n */\n consume(count = 1): string {\n let chars = this.peek(count);\n this.advance(count);\n return chars;\n }\n\n /**\n * Consumes a match for the given sticky regex, advances the scanner, updates\n * the `lastIndex` property of the regex, and returns the matching string.\n *\n * The regex must have a sticky flag (\"y\") so that its `lastIndex` prop can be\n * used to anchor the match at the current scanner position.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeMatch(regex: RegExp): string {\n if (!regex.sticky) {\n throw new Error('`regex` must have a sticky flag (\"y\")');\n }\n\n regex.lastIndex = this.charIndexToByteIndex();\n\n let result = regex.exec(this.string);\n\n if (result === null || result.length === 0) {\n return emptyString;\n }\n\n let match = result[0] as string;\n this.advance(this.charLength(match));\n return match;\n }\n\n /**\n * Consumes and returns all characters for which the given function returns a\n * truthy value, stopping on the first falsy return value or if the end of the\n * input is reached.\n */\n consumeMatchFn(fn: (char: string) => boolean): string {\n let char;\n let match = emptyString;\n\n while ((char = this.peek()) && fn(char)) {\n match += char;\n this.advance();\n }\n\n return match;\n }\n\n /**\n * Consumes the given string if it exists at the current character index, and\n * advances the scanner.\n *\n * If the given string doesn't exist at the current character index, an empty\n * string will be returned and the scanner will not be advanced.\n */\n consumeString(stringToConsume: string): string {\n if (this.consumeStringFast(stringToConsume)) {\n return stringToConsume;\n }\n\n if (this.multiByteMode) {\n let { length } = stringToConsume;\n let charLengthToMatch = this.charLength(stringToConsume);\n\n if (charLengthToMatch !== length\n && stringToConsume === this.peek(charLengthToMatch)) {\n\n this.advance(charLengthToMatch);\n return stringToConsume;\n }\n }\n\n return emptyString;\n }\n\n /**\n * Does the same thing as `consumeString()`, but doesn't support consuming\n * multibyte characters. This can be faster if you only need to match single\n * byte characters.\n */\n consumeStringFast(stringToConsume: string): string {\n let { length } = stringToConsume;\n\n if (this.peek(length) === stringToConsume) {\n this.advance(length);\n return stringToConsume;\n }\n\n return emptyString;\n }\n\n /**\n * Consumes characters until the given global regex is matched, advancing the\n * scanner up to (but not beyond) the beginning of the match. If the regex\n * doesn't match, nothing will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilMatch(regex: RegExp): string {\n let restOfString = this.string.slice(this.charIndexToByteIndex());\n let matchByteIndex = restOfString.search(regex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = restOfString.slice(0, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Consumes characters until the given string is found, advancing the scanner\n * up to (but not beyond) that point. If the string is never found, nothing\n * will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilString(searchString: string): string {\n let { string } = this;\n let byteIndex = this.charIndexToByteIndex();\n let matchByteIndex = string.indexOf(searchString, byteIndex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = string.slice(byteIndex, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Returns the given number of characters starting at the current character\n * index, without advancing the scanner and without exceeding the end of the\n * input string.\n */\n peek(count = 1): string {\n let { charIndex, multiByteMode, string } = this;\n\n if (multiByteMode) {\n // Inlining this comparison instead of checking `this.isEnd` improves perf\n // slightly since `peek()` is called so frequently.\n if (charIndex >= this.charCount) {\n return emptyString;\n }\n\n return string.slice(\n this.charIndexToByteIndex(charIndex),\n this.charIndexToByteIndex(charIndex + count),\n );\n }\n\n return string.slice(charIndex, charIndex + count);\n }\n\n /**\n * Resets the scanner position to the given character _index_, or to the start\n * of the input string if no index is given.\n *\n * If _index_ is negative, the scanner position will be moved backward by that\n * many characters, stopping if the beginning of the string is reached.\n */\n reset(index = 0) {\n this.charIndex = index >= 0\n ? Math.min(this.charCount, index)\n : Math.max(0, this.charIndex + index);\n }\n}\n", "/**\n * Regular expression that matches one or more `AttValue` characters in a\n * double-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharDoubleQuote = /[^\"&<]+/y;\n\n/**\n * Regular expression that matches one or more `AttValue` characters in a\n * single-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharSingleQuote = /[^'&<]+/y;\n\n/**\n * Regular expression that matches a whitespace character that should be\n * normalized to a space character in an attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize\n */\nexport const attValueNormalizedWhitespace = /[\\t\\n]/g;\n\n/**\n * Regular expression that matches one or more characters that signal the end of\n * XML `CharData` content.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\nexport const endCharData = /<|&|]]>/;\n\n/**\n * Mapping of predefined entity names to their replacement values.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent\n */\nexport const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {\n amp: '&',\n apos: \"'\",\n gt: '>',\n lt: '<',\n quot: '\"',\n}));\n\n/**\n * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar\n */\nexport function isNameChar(char: string): boolean {\n let cp = getCodePoint(char);\n\n // Including the most common NameStartChars here improves performance\n // slightly.\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || (cp >= 0x30 && cp <= 0x39) // 0-9\n || cp === 0x2D // -\n || cp === 0x2E // .\n || cp === 0xB7\n || (cp >= 0x300 && cp <= 0x36F)\n || (cp >= 0x203F && cp <= 0x2040)\n || isNameStartChar(char, cp);\n}\n\n/**\n * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar\n */\nexport function isNameStartChar(char: string, cp = getCodePoint(char)): boolean {\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || cp === 0x3A // :\n || cp === 0x5F // _\n || (cp >= 0xC0 && cp <= 0xD6)\n || (cp >= 0xD8 && cp <= 0xF6)\n || (cp >= 0xF8 && cp <= 0x2FF)\n || (cp >= 0x370 && cp <= 0x37D)\n || (cp >= 0x37F && cp <= 0x1FFF)\n || (cp >= 0x200C && cp <= 0x200D)\n || (cp >= 0x2070 && cp <= 0x218F)\n || (cp >= 0x2C00 && cp <= 0x2FEF)\n || (cp >= 0x3001 && cp <= 0xD7FF)\n || (cp >= 0xF900 && cp <= 0xFDCF)\n || (cp >= 0xFDF0 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0xEFFFF);\n}\n\n/**\n * Returns `true` if _char_ is a valid reference character (which may appear\n * between `&` and `;` in a reference), `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references\n */\nexport function isReferenceChar(char: string): boolean {\n return char === '#' || isNameChar(char);\n}\n\n/**\n * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\nexport function isWhitespace(char: string): boolean {\n let cp = getCodePoint(char);\n\n return cp === 0x20\n || cp === 0x9\n || cp === 0xA\n || cp === 0xD;\n}\n\n/**\n * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`\n * otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char\n */\nexport function isXmlCodePoint(cp: number): boolean {\n return cp === 0x9\n || cp === 0xA\n || cp === 0xD\n || (cp >= 0x20 && cp <= 0xD7FF)\n || (cp >= 0xE000 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0x10FFFF);\n}\n\n/**\n * Returns the Unicode code point value of the given character, or `-1` if\n * _char_ is empty.\n */\nfunction getCodePoint(char: string): number {\n return char.codePointAt(0) || -1;\n}\n", "import type { JsonObject } from './types.js';\nimport type { XmlDocument } from './XmlDocument.js';\nimport type { XmlElement } from './XmlElement.js';\n\n/**\n * Base interface for a node in an XML document.\n */\nexport class XmlNode {\n /**\n * Type value for an `XmlCdata` node.\n */\n static readonly TYPE_CDATA = 'cdata';\n\n /**\n * Type value for an `XmlComment` node.\n */\n static readonly TYPE_COMMENT = 'comment';\n\n /**\n * Type value for an `XmlDocument` node.\n */\n static readonly TYPE_DOCUMENT = 'document';\n\n /**\n * Type value for an `XmlElement` node.\n */\n static readonly TYPE_ELEMENT = 'element';\n\n /**\n * Type value for an `XmlProcessingInstruction` node.\n */\n static readonly TYPE_PROCESSING_INSTRUCTION = 'pi';\n\n /**\n * Type value for an `XmlText` node.\n */\n static readonly TYPE_TEXT = 'text';\n\n /**\n * Parent node of this node, or `null` if this node has no parent.\n */\n parent: XmlDocument | XmlElement | null = null;\n\n /**\n * Document that contains this node, or `null` if this node is not associated\n * with a document.\n */\n get document(): XmlDocument | null {\n return this.parent?.document ?? null;\n }\n\n /**\n * Whether this node is the root node of the document.\n */\n get isRootNode(): boolean {\n return this.parent !== null && this.parent === this.document;\n }\n\n /**\n * Whether whitespace should be preserved in the content of this element and\n * its children.\n *\n * This is influenced by the value of the special `xml:space` attribute, and\n * will be `true` for any node whose `xml:space` attribute is set to\n * \"preserve\". If a node has no such attribute, it will inherit the value of\n * the nearest ancestor that does (if any).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space\n */\n get preserveWhitespace(): boolean {\n return Boolean(this.parent?.preserveWhitespace);\n }\n\n /**\n * Type of this node.\n *\n * The value of this property is a string that matches one of the static\n * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,\n * `TYPE_TEXT`, etc.).\n *\n * The `XmlNode` class itself is a base class and doesn't have its own type\n * name.\n */\n get type() {\n return '';\n }\n\n /**\n * Returns a JSON-serializable object representing this node, minus properties\n * that could result in circular references.\n */\n toJSON(): JsonObject {\n let json: JsonObject = {\n type: this.type,\n };\n\n if (this.isRootNode) {\n json.isRootNode = true;\n }\n\n if (this.preserveWhitespace) {\n json.preserveWhitespace = true;\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * Text content within an XML document.\n */\nexport class XmlText extends XmlNode {\n /**\n * Text content of this node.\n */\n text: string;\n\n constructor(text = '') {\n super();\n this.text = text;\n }\n\n override get type() {\n return XmlNode.TYPE_TEXT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n text: this.text,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\nimport { XmlText } from './XmlText.js';\n\n/**\n * A CDATA section within an XML document.\n */\nexport class XmlCdata extends XmlText {\n override get type() {\n return XmlNode.TYPE_CDATA;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A comment within an XML document.\n */\nexport class XmlComment extends XmlNode {\n /**\n * Content of this comment.\n */\n content: string;\n\n constructor(content = '') {\n super();\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_COMMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n content: this.content,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\nimport type { JsonObject } from './types.js';\nimport type { XmlCdata } from './XmlCdata.js';\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport type { XmlText } from './XmlText.js';\n\n/**\n * Element in an XML document.\n */\nexport class XmlElement extends XmlNode {\n /**\n * Attributes on this element.\n */\n attributes: {[attrName: string]: string};\n\n /**\n * Child nodes of this element.\n */\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;\n\n /**\n * Name of this element.\n */\n name: string;\n\n constructor(\n name: string,\n attributes: {[attrName: string]: string} = Object.create(null),\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText> = [],\n ) {\n super();\n\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n\n /**\n * Whether this element is empty (meaning it has no children).\n */\n get isEmpty(): boolean {\n return this.children.length === 0;\n }\n\n override get preserveWhitespace(): boolean {\n let node: XmlNode | null = this; // eslint-disable-line @typescript-eslint/no-this-alias\n\n while (node instanceof XmlElement) {\n if ('xml:space' in node.attributes) {\n return node.attributes['xml:space'] === 'preserve';\n }\n\n node = node.parent;\n }\n\n return false;\n }\n\n /**\n * Text content of this element and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_ELEMENT;\n }\n\n override toJSON(): JsonObject {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n attributes: this.attributes,\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlElement } from './XmlElement.js';\nimport { XmlNode } from './XmlNode.js';\n\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\n\n/**\n * Represents an XML document. All elements within the document are descendants\n * of this node.\n */\nexport class XmlDocument extends XmlNode {\n /**\n * Child nodes of this document.\n */\n readonly children: Array<XmlComment | XmlProcessingInstruction | XmlElement>;\n\n constructor(children: Array<XmlComment | XmlElement | XmlProcessingInstruction> = []) {\n super();\n this.children = children;\n }\n\n override get document() {\n return this;\n }\n\n /**\n * Root element of this document, or `null` if this document is empty.\n */\n get root(): XmlElement | null {\n for (let child of this.children) {\n if (child instanceof XmlElement) {\n return child;\n }\n }\n\n return null;\n }\n\n /**\n * Text content of this document and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A processing instruction within an XML document.\n */\nexport class XmlProcessingInstruction extends XmlNode {\n /**\n * Content of this processing instruction.\n */\n content: string;\n\n /**\n * Name of this processing instruction. Also sometimes referred to as the\n * processing instruction \"target\".\n */\n name: string;\n\n constructor(name: string, content = '') {\n super();\n\n this.name = name;\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_PROCESSING_INSTRUCTION;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n content: this.content,\n });\n }\n}\n", "import { StringScanner } from './StringScanner.js';\nimport * as syntax from './syntax.js';\nimport { XmlCdata } from './XmlCdata.js';\nimport { XmlComment } from './XmlComment.js';\nimport { XmlDocument } from './XmlDocument.js';\nimport { XmlElement } from './XmlElement.js';\nimport { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport { XmlText } from './XmlText.js';\n\nimport type { XmlNode } from './XmlNode.js';\n\n\nconst emptyString = '';\n\n/**\n * Parses an XML string into an `XmlDocument`.\n *\n * @private\n */\nexport class Parser {\n readonly document: XmlDocument;\n\n private currentNode: XmlDocument | XmlElement;\n private readonly options: ParserOptions;\n private readonly scanner: StringScanner;\n\n /**\n * @param xml XML string to parse.\n * @param options Parser options.\n */\n constructor(xml: string, options: ParserOptions = {}) {\n this.document = new XmlDocument();\n this.currentNode = this.document;\n this.options = options;\n this.scanner = new StringScanner(normalizeXmlString(xml));\n\n this.consumeProlog();\n\n if (!this.consumeElement()) {\n throw this.error('Root element is missing or invalid');\n }\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (!this.scanner.isEnd) {\n throw this.error('Extra content at the end of the document');\n }\n }\n\n /**\n * Adds the given `XmlNode` as a child of `this.currentNode`.\n */\n addNode(node: XmlNode) {\n node.parent = this.currentNode;\n\n // @ts-expect-error: XmlDocument has a more limited set of possible children\n // than XmlElement so TypeScript is unhappy, but we always do the right\n // thing.\n this.currentNode.children.push(node);\n }\n\n /**\n * Adds the given _text_ to the document, either by appending it to a\n * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.\n */\n addText(text: string) {\n let { children } = this.currentNode;\n let { length } = children;\n\n if (length > 0) {\n let prevNode = children[length - 1];\n\n if (prevNode instanceof XmlText) {\n // The previous node is a text node, so we can append to it and avoid\n // creating another node.\n prevNode.text += text;\n return;\n }\n }\n\n this.addNode(new XmlText(text));\n }\n\n /**\n * Consumes element attributes.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags\n */\n consumeAttributes(): Record<string, string> {\n let attributes = Object.create(null);\n\n while (this.consumeWhitespace()) {\n let attrName = this.consumeName();\n\n if (!attrName) {\n break;\n }\n\n let attrValue = this.consumeEqual() && this.consumeAttributeValue();\n\n if (attrValue === false) {\n throw this.error('Attribute value expected');\n }\n\n if (attrName in attributes) {\n throw this.error(`Duplicate attribute: ${attrName}`);\n }\n\n if (attrName === 'xml:space'\n && attrValue !== 'default'\n && attrValue !== 'preserve') {\n\n throw this.error('Value of the `xml:space` attribute must be \"default\" or \"preserve\"');\n }\n\n attributes[attrName] = attrValue;\n }\n\n if (this.options.sortAttributes) {\n let attrNames = Object.keys(attributes).sort();\n let sortedAttributes = Object.create(null);\n\n for (let i = 0; i < attrNames.length; ++i) {\n let attrName = attrNames[i] as string;\n sortedAttributes[attrName] = attributes[attrName];\n }\n\n attributes = sortedAttributes;\n }\n\n return attributes;\n }\n\n /**\n * Consumes an `AttValue` (attribute value) if possible.\n *\n * @returns\n * Contents of the `AttValue` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that an `AttValue` was consumed but\n * was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\n consumeAttributeValue(): string | false {\n let { scanner } = this;\n let quote = scanner.peek();\n\n if (quote !== '\"' && quote !== \"'\") {\n return false;\n }\n\n scanner.advance();\n\n let chars;\n let isClosed = false;\n let value = emptyString;\n let regex = quote === '\"'\n ? syntax.attValueCharDoubleQuote\n : syntax.attValueCharSingleQuote;\n\n matchLoop: while (!scanner.isEnd) {\n chars = scanner.consumeMatch(regex);\n\n if (chars) {\n this.validateChars(chars);\n value += chars.replace(syntax.attValueNormalizedWhitespace, ' ');\n }\n\n switch (scanner.peek()) {\n case quote:\n isClosed = true;\n break matchLoop;\n\n case '&':\n value += this.consumeReference();\n continue;\n\n case '<':\n throw this.error('Unescaped `<` is not allowed in an attribute value');\n\n case emptyString:\n break matchLoop;\n }\n }\n\n if (!isClosed) {\n throw this.error('Unclosed attribute');\n }\n\n scanner.advance();\n return value;\n }\n\n /**\n * Consumes a CDATA section if possible.\n *\n * @returns Whether a CDATA section was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect\n */\n consumeCdataSection(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<![CDATA[')) {\n return false;\n }\n\n let text = scanner.consumeUntilString(']]>');\n this.validateChars(text);\n\n if (!scanner.consumeStringFast(']]>')) {\n throw this.error('Unclosed CDATA section');\n }\n\n if (this.options.preserveCdata) {\n this.addNode(new XmlCdata(text));\n } else {\n this.addText(text);\n }\n\n return true;\n }\n\n /**\n * Consumes character data if possible.\n *\n * @returns Whether character data was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\n consumeCharData(): boolean {\n let { scanner } = this;\n let charData = scanner.consumeUntilMatch(syntax.endCharData);\n\n if (!charData) {\n return false;\n }\n\n this.validateChars(charData);\n\n if (scanner.peek(3) === ']]>') {\n throw this.error('Element content may not contain the CDATA section close delimiter `]]>`');\n }\n\n this.addText(charData);\n return true;\n }\n\n /**\n * Consumes a comment if possible.\n *\n * @returns Whether a comment was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment\n */\n consumeComment(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!--')) {\n return false;\n }\n\n let content = scanner.consumeUntilString('--');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('-->')) {\n if (scanner.peek(2) === '--') {\n throw this.error(\"The string `--` isn't allowed inside a comment\");\n }\n\n throw this.error('Unclosed comment');\n }\n\n if (this.options.preserveComments) {\n this.addNode(new XmlComment(content.trim()));\n }\n\n return true;\n }\n\n /**\n * Consumes a reference in a content context if possible.\n *\n * This differs from `consumeReference()` in that a consumed reference will be\n * added to the document as a text node instead of returned.\n *\n * @returns Whether a reference was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc\n */\n consumeContentReference(): boolean {\n let ref = this.consumeReference();\n\n if (ref) {\n this.addText(ref);\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes a doctype declaration if possible.\n *\n * This is a loose implementation since doctype declarations are currently\n * discarded without further parsing.\n *\n * @returns Whether a doctype declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd\n */\n consumeDoctypeDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<!DOCTYPE')\n || !this.consumeWhitespace()) {\n\n return false;\n }\n\n scanner.consumeMatch(/[^[>]+/y);\n\n if (scanner.consumeMatch(/\\[[\\s\\S]+?\\][\\x20\\t\\r\\n]*>/y)) {\n return true;\n }\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error('Unclosed doctype declaration');\n }\n\n return true;\n }\n\n /**\n * Consumes an element if possible.\n *\n * @returns Whether an element was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element\n */\n consumeElement(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (!name) {\n scanner.reset(mark);\n return false;\n }\n\n let attributes = this.consumeAttributes();\n let isEmpty = Boolean(scanner.consumeStringFast('/>'));\n let element = new XmlElement(name, attributes);\n\n element.parent = this.currentNode;\n\n if (!isEmpty) {\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed start tag for element \\`${name}\\``);\n }\n\n this.currentNode = element;\n\n do {\n this.consumeCharData();\n } while (\n this.consumeElement()\n || this.consumeContentReference()\n || this.consumeCdataSection()\n || this.consumeProcessingInstruction()\n || this.consumeComment()\n );\n\n let endTagMark = scanner.charIndex;\n let endTagName;\n\n if (!scanner.consumeStringFast('</')\n || !(endTagName = this.consumeName())\n || endTagName !== name) {\n\n scanner.reset(endTagMark);\n throw this.error(`Missing end tag for element ${name}`);\n }\n\n this.consumeWhitespace();\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed end tag for element ${name}`);\n }\n\n this.currentNode = element.parent;\n }\n\n this.addNode(element);\n return true;\n }\n\n /**\n * Consumes an `Eq` production if possible.\n *\n * @returns Whether an `Eq` production was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq\n */\n consumeEqual(): boolean {\n this.consumeWhitespace();\n\n if (this.scanner.consumeStringFast('=')) {\n this.consumeWhitespace();\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes `Misc` content if possible.\n *\n * @returns Whether anything was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc\n */\n consumeMisc(): boolean {\n return this.consumeComment()\n || this.consumeProcessingInstruction()\n || this.consumeWhitespace();\n }\n\n /**\n * Consumes one or more `Name` characters if possible.\n *\n * @returns `Name` characters, or an empty string if none were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name\n */\n consumeName(): string {\n return syntax.isNameStartChar(this.scanner.peek())\n ? this.scanner.consumeMatchFn(syntax.isNameChar)\n : emptyString;\n }\n\n /**\n * Consumes a processing instruction if possible.\n *\n * @returns Whether a processing instruction was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi\n */\n consumeProcessingInstruction(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<?')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (name) {\n if (name.toLowerCase() === 'xml') {\n scanner.reset(mark);\n throw this.error(\"XML declaration isn't allowed here\");\n }\n } else {\n throw this.error('Invalid processing instruction');\n }\n\n if (!this.consumeWhitespace()) {\n if (scanner.consumeStringFast('?>')) {\n this.addNode(new XmlProcessingInstruction(name));\n return true;\n }\n\n throw this.error('Whitespace is required after a processing instruction name');\n }\n\n let content = scanner.consumeUntilString('?>');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Unterminated processing instruction');\n }\n\n this.addNode(new XmlProcessingInstruction(name, content));\n return true;\n }\n\n /**\n * Consumes a prolog if possible.\n *\n * @returns Whether a prolog was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd\n */\n consumeProlog(): boolean {\n let { scanner } = this;\n let mark = scanner.charIndex;\n\n this.consumeXmlDeclaration();\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (this.consumeDoctypeDeclaration()) {\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n }\n\n return mark < scanner.charIndex;\n }\n\n /**\n * Consumes a reference if possible.\n *\n * This differs from `consumeContentReference()` in that a consumed reference\n * will be returned rather than added to the document.\n *\n * @returns\n * Parsed reference value, or `false` if nothing was consumed (to\n * distinguish from a reference that resolves to an empty string).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference\n */\n consumeReference(): string | false {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('&')) {\n return false;\n }\n\n let ref = scanner.consumeMatchFn(syntax.isReferenceChar);\n\n if (scanner.consume() !== ';') {\n throw this.error('Unterminated reference (a reference must end with `;`)');\n }\n\n let parsedValue;\n\n if (ref[0] === '#') {\n // This is a character reference.\n let codePoint = ref[1] === 'x'\n ? parseInt(ref.slice(2), 16) // Hex codepoint.\n : parseInt(ref.slice(1), 10); // Decimal codepoint.\n\n if (isNaN(codePoint)) {\n throw this.error('Invalid character reference');\n }\n\n if (!syntax.isXmlCodePoint(codePoint)) {\n throw this.error('Character reference resolves to an invalid character');\n }\n\n parsedValue = String.fromCodePoint(codePoint);\n } else {\n // This is an entity reference.\n parsedValue = syntax.predefinedEntities[ref];\n\n if (parsedValue === undefined) {\n let {\n ignoreUndefinedEntities,\n resolveUndefinedEntity,\n } = this.options;\n\n let wrappedRef = `&${ref};`; // for backcompat with <= 2.x\n\n if (resolveUndefinedEntity) {\n let resolvedValue = resolveUndefinedEntity(wrappedRef);\n\n if (resolvedValue !== null && resolvedValue !== undefined) {\n let type = typeof resolvedValue;\n\n if (type !== 'string') {\n throw new TypeError(`\\`resolveUndefinedEntity()\\` must return a string, \\`null\\`, or \\`undefined\\`, but returned a value of type ${type}`);\n }\n\n return resolvedValue;\n }\n }\n\n if (ignoreUndefinedEntities) {\n return wrappedRef;\n }\n\n scanner.reset(-wrappedRef.length);\n throw this.error(`Named entity isn't defined: ${wrappedRef}`);\n }\n }\n\n return parsedValue;\n }\n\n /**\n * Consumes a `SystemLiteral` if possible.\n *\n * A `SystemLiteral` is similar to an attribute value, but allows the\n * characters `<` and `&` and doesn't replace references.\n *\n * @returns\n * Value of the `SystemLiteral` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that a `SystemLiteral` was consumed\n * but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral\n */\n consumeSystemLiteral(): string | false {\n let { scanner } = this;\n let quote = scanner.consumeStringFast('\"') || scanner.consumeStringFast(\"'\");\n\n if (!quote) {\n return false;\n }\n\n let value = scanner.consumeUntilString(quote);\n this.validateChars(value);\n\n if (!scanner.consumeStringFast(quote)) {\n throw this.error('Missing end quote');\n }\n\n return value;\n }\n\n /**\n * Consumes one or more whitespace characters if possible.\n *\n * @returns Whether any whitespace characters were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\n consumeWhitespace(): boolean {\n return Boolean(this.scanner.consumeMatchFn(syntax.isWhitespace));\n }\n\n /**\n * Consumes an XML declaration if possible.\n *\n * @returns Whether an XML declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl\n */\n consumeXmlDeclaration(): boolean {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('<?xml')) {\n return false;\n }\n\n if (!this.consumeWhitespace()) {\n throw this.error('Invalid XML declaration');\n }\n\n let version = Boolean(scanner.consumeStringFast('version'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (version === false) {\n throw this.error('XML version is missing or invalid');\n } else if (!/^1\\.[0-9]+$/.test(version)) {\n throw this.error('Invalid character in version number');\n }\n\n if (this.consumeWhitespace()) {\n let encoding = Boolean(scanner.consumeStringFast('encoding'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (encoding) {\n this.consumeWhitespace();\n }\n\n let standalone = Boolean(scanner.consumeStringFast('standalone'))\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (standalone) {\n if (standalone !== 'yes' && standalone !== 'no') {\n throw this.error('Only \"yes\" and \"no\" are permitted as values of `standalone`');\n }\n\n this.consumeWhitespace();\n }\n }\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Invalid or unclosed XML declaration');\n }\n\n return true;\n }\n\n /**\n * Throws an error at the current scanner position.\n */\n error(message: string) {\n let { charIndex, string: xml } = this.scanner;\n let column = 1;\n let excerpt = '';\n let line = 1;\n\n // Find the line and column where the error occurred.\n for (let i = 0; i < charIndex; ++i) {\n let char = xml[i];\n\n if (char === '\\n') {\n column = 1;\n excerpt = '';\n line += 1;\n } else {\n column += 1;\n excerpt += char;\n }\n }\n\n let eol = xml.indexOf('\\n', charIndex);\n\n excerpt += eol === -1\n ? xml.slice(charIndex)\n : xml.slice(charIndex, eol);\n\n let excerptStart = 0;\n\n // Keep the excerpt below 50 chars, but always keep the error position in\n // view.\n if (excerpt.length > 50) {\n if (column < 40) {\n excerpt = excerpt.slice(0, 50);\n } else {\n excerptStart = column - 20;\n excerpt = excerpt.slice(excerptStart, column + 30);\n }\n }\n\n let err = new Error(\n `${message} (line ${line}, column ${column})\\n`\n + ` ${excerpt}\\n`\n + ' '.repeat(column - excerptStart + 1) + '^\\n',\n );\n\n Object.assign(err, {\n column,\n excerpt,\n line,\n pos: charIndex,\n });\n\n return err;\n }\n\n /**\n * Throws an invalid character error if any character in the given _string_\n * isn't a valid XML character.\n */\n validateChars(string: string) {\n let { length } = string;\n\n for (let i = 0; i < length; ++i) {\n let cp = string.codePointAt(i) as number;\n\n if (!syntax.isXmlCodePoint(cp)) {\n this.scanner.reset(-([ ...string ].length - i));\n throw this.error('Invalid character');\n }\n\n if (cp > 65535) {\n i += 1;\n }\n }\n }\n}\n\n// -- Private Functions --------------------------------------------------------\n\n/**\n * Normalizes the given XML string by stripping a byte order mark (if present)\n * and replacing CRLF sequences and lone CR characters with LF characters.\n */\nfunction normalizeXmlString(xml: string): string {\n if (xml[0] === '\\uFEFF') {\n xml = xml.slice(1);\n }\n\n return xml.replace(/\\r\\n?/g, '\\n');\n}\n\n// -- Types --------------------------------------------------------------------\nexport type ParserOptions = {\n /**\n * When `true`, an undefined named entity (like \"&bogus;\") will be left in the\n * output as is instead of causing a parse error.\n *\n * @default false\n */\n ignoreUndefinedEntities?: boolean;\n\n /**\n * When `true`, CDATA sections will be preserved in the document as `XmlCdata`\n * nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,\n * which keeps the node tree simpler and easier to work with.\n *\n * @default false\n */\n preserveCdata?: boolean;\n\n /**\n * When `true`, comments will be preserved in the document as `XmlComment`\n * nodes. Otherwise comments will not be included in the node tree.\n *\n * @default false\n */\n preserveComments?: boolean;\n\n /**\n * When an undefined named entity is encountered, this function will be called\n * with the entity as its only argument. It should return a string value with\n * which to replace the entity, or `null` or `undefined` to treat the entity\n * as undefined (which may result in a parse error depending on the value of\n * `ignoreUndefinedEntities`).\n */\n resolveUndefinedEntity?: (entity: string) => string | null | undefined;\n\n /**\n * When `true`, attributes in an element's `attributes` object will be sorted\n * in alphanumeric order by name. Otherwise they'll retain their original\n * order as found in the XML.\n *\n * @default false\n */\n sortAttributes?: boolean;\n};\n"],
5
+ "mappings": ";4bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,eAAAC,EAAA,gBAAAC,EAAA,eAAAC,EAAA,YAAAC,EAAA,6BAAAC,EAAA,YAAAC,EAAA,aAAAC,ICAA,IAAMC,EAAc,GACdC,EAAgB,kCAGTC,EAAN,KAAoB,CASzB,YAAYC,EAAgB,CAO1B,GANA,KAAKC,EAAY,KAAKC,EAAWF,EAAQ,EAAI,EAC7C,KAAKG,EAAY,EACjB,KAAK,OAASH,EAAO,OACrB,KAAKI,EAAgB,KAAKH,IAAc,KAA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,EAAM,EAAE,CAAE,GAAGoC,CAAO,EAAE,OAASL,EAAE,EACxC,KAAKnF,EAAM,mBAAmB,EAGlCyF,EAAK,QACPN,GAAK,EAET,CACF,CACF,EAQA,SAAStF,EAAmBN,EAAqB,CAC/C,OAAIA,EAAI,KAAO,WACbA,EAAMA,EAAI,MAAM,CAAC,GAGZA,EAAI,QAAQ,SAAU;AAAA,CAAI,CACnC,CVzuBO,SAASmG,EAASC,EAAaC,EAAyB,CAC7D,OAAQ,IAAIC,EAAOF,EAAKC,CAAO,EAAG,QACpC",
6
6
  "names": ["src_exports", "__export", "XmlCdata", "XmlComment", "XmlDocument", "XmlElement", "XmlNode", "XmlProcessingInstruction", "XmlText", "parseXml", "emptyString", "surrogatePair", "StringScanner", "string", "charCount", "charLength", "charIndex", "multiByteMode", "charsToBytes", "byteIndex", "isEnd", "charIndexToByteIndex", "_a", "multiByteSafe", "advance", "count", "consume", "chars", "peek", "consumeMatch", "regex", "result", "match", "consumeMatchFn", "fn", "char", "consumeString", "stringToConsume", "consumeStringFast", "length", "charLengthToMatch", "consumeUntilMatch", "restOfString", "matchByteIndex", "consumeUntilString", "searchString", "reset", "index", "attValueCharDoubleQuote", "attValueCharSingleQuote", "attValueNormalizedWhitespace", "endCharData", "predefinedEntities", "isNameChar", "char", "cp", "getCodePoint", "isNameStartChar", "isReferenceChar", "isWhitespace", "isXmlCodePoint", "XmlNode", "_a", "_b", "json", "XmlText", "XmlNode", "text", "XmlCdata", "XmlText", "XmlNode", "XmlComment", "XmlNode", "content", "XmlElement", "XmlNode", "name", "attributes", "children", "node", "child", "XmlDocument", "XmlNode", "children", "child", "XmlElement", "XmlProcessingInstruction", "XmlNode", "name", "content", "emptyString", "Parser", "xml", "options", "XmlDocument", "currentNode", "scanner", "StringScanner", "normalizeXmlString", "consumeProlog", "consumeElement", "error", "consumeMisc", "isEnd", "addNode", "node", "addText", "text", "children", "length", "prevNode", "XmlText", "consumeAttributes", "attributes", "consumeWhitespace", "attrName", "consumeName", "attrValue", "consumeEqual", "consumeAttributeValue", "attrNames", "sortedAttributes", "quote", "peek", "advance", "chars", "isClosed", "value", "regex", "attValueCharDoubleQuote", "attValueCharSingleQuote", "matchLoop", "consumeMatch", "validateChars", "attValueNormalizedWhitespace", "consumeReference", "consumeCdataSection", "consumeStringFast", "consumeUntilString", "XmlCdata", "consumeCharData", "charData", "consumeUntilMatch", "endCharData", "consumeComment", "content", "XmlComment", "consumeContentReference", "ref", "consumeDoctypeDeclaration", "mark", "charIndex", "name", "reset", "isEmpty", "element", "XmlElement", "consumeProcessingInstruction", "endTagMark", "endTagName", "isNameStartChar", "consumeMatchFn", "isNameChar", "XmlProcessingInstruction", "consumeXmlDeclaration", "isReferenceChar", "consume", "parsedValue", "codePoint", "isXmlCodePoint", "predefinedEntities", "ignoreUndefinedEntities", "resolveUndefinedEntity", "wrappedRef", "resolvedValue", "type", "consumeSystemLiteral", "isWhitespace", "version", "standalone", "message", "column", "excerpt", "line", "i", "char", "eol", "excerptStart", "err", "string", "cp", "parseXml", "xml", "options", "Parser"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -20,5 +20,5 @@ export type { ParserOptions } from './lib/Parser.js';
20
20
  * @param xml XML string to parse.
21
21
  * @param options Parser options.
22
22
  */
23
- export declare function parseXml(xml: string, options: ParserOptions): import("./lib/XmlDocument.js").XmlDocument;
23
+ export declare function parseXml(xml: string, options?: ParserOptions): import("./lib/XmlDocument.js").XmlDocument;
24
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,8CAE3D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,8CAE5D"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAyC;AAIzC,iDAA+B;AAC/B,iDAA6C;AAApC,uGAAA,QAAQ,OAAA;AACjB,qDAAiD;AAAxC,2GAAA,UAAU,OAAA;AACnB,uDAAmD;AAA1C,6GAAA,WAAW,OAAA;AACpB,qDAAiD;AAAxC,2GAAA,UAAU,OAAA;AACnB,+CAA2C;AAAlC,qGAAA,OAAO,OAAA;AAChB,iFAA6E;AAApE,uIAAA,wBAAwB,OAAA;AACjC,+CAA2C;AAAlC,qGAAA,OAAO,OAAA;AAIhB;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,OAAsB;IAC1D,OAAO,CAAC,IAAI,kBAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7C,CAAC;AAFD,4BAEC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAyC;AAIzC,iDAA+B;AAC/B,iDAA6C;AAApC,uGAAA,QAAQ,OAAA;AACjB,qDAAiD;AAAxC,2GAAA,UAAU,OAAA;AACnB,uDAAmD;AAA1C,6GAAA,WAAW,OAAA;AACpB,qDAAiD;AAAxC,2GAAA,UAAU,OAAA;AACnB,+CAA2C;AAAlC,qGAAA,OAAO,OAAA;AAChB,iFAA6E;AAApE,uIAAA,wBAAwB,OAAA;AACjC,+CAA2C;AAAlC,qGAAA,OAAO,OAAA;AAIhB;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,OAAuB;IAC3D,OAAO,CAAC,IAAI,kBAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7C,CAAC;AAFD,4BAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rgrove/parse-xml",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "A fast, safe, compliant XML parser for Node.js and browsers.",
5
5
  "keywords": [
6
6
  "xml",
@@ -30,21 +30,6 @@
30
30
  "types": "./dist/index.d.ts",
31
31
  "main": "./dist/index.js",
32
32
  "browser": "./dist/browser.js",
33
- "scripts": {
34
- "build": "npm run build:js && npm run build:bundle && npm run build:docs",
35
- "build:bundle": "./scripts/esbuild.js",
36
- "build:docs": "typedoc src/index.ts",
37
- "build:js": "tsc",
38
- "clean": "rm -rf .nyc_output coverage dist",
39
- "coverage": "nyc --reporter html --report-dir coverage npm test && open coverage/index.html",
40
- "lint": "npm run lint:js && npm run lint:ts",
41
- "lint:js": "eslint .",
42
- "lint:ts": "tsc --noEmit",
43
- "prepublishOnly": "npm run clean && npm run build",
44
- "test": "npm run build:js && nyc --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 mocha",
45
- "test:watch": "npm run build:js && concurrently --kill-others-on-fail --names build,mocha 'npm run build:js -- --watch' 'mocha --watch'",
46
- "test:browser": "npm run build:js && npm run build:bundle && concurrently --kill-others-on-fail --names build:bundle,build:js,webpack 'npm run build:bundle -- --watch' 'npm run build:js -- --watch' 'webpack serve --config tests/webpack.config.js'"
47
- },
48
33
  "devDependencies": {
49
34
  "@rgrove/eslint-config": "^5.0.0",
50
35
  "@types/node": "^18.7.21",
@@ -62,5 +47,19 @@
62
47
  "webpack": "^5.65.0",
63
48
  "webpack-cli": "^4.9.1",
64
49
  "webpack-dev-server": "^4.11.1"
50
+ },
51
+ "scripts": {
52
+ "build": "npm run build:js && npm run build:bundle && npm run build:docs",
53
+ "build:bundle": "./scripts/esbuild.js",
54
+ "build:docs": "typedoc src/index.ts",
55
+ "build:js": "tsc",
56
+ "clean": "rm -rf .nyc_output coverage dist",
57
+ "coverage": "nyc --reporter html --report-dir coverage npm test && open coverage/index.html",
58
+ "lint": "npm run lint:js && npm run lint:ts",
59
+ "lint:js": "eslint .",
60
+ "lint:ts": "tsc --noEmit",
61
+ "test": "npm run build:js && nyc --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 mocha",
62
+ "test:watch": "npm run build:js && concurrently --kill-others-on-fail --names build,mocha 'npm run build:js -- --watch' 'mocha --watch'",
63
+ "test:browser": "npm run build:js && npm run build:bundle && concurrently --kill-others-on-fail --names build:bundle,build:js,webpack 'npm run build:bundle -- --watch' 'npm run build:js -- --watch' 'webpack serve --config tests/webpack.config.js'"
65
64
  }
66
- }
65
+ }
package/src/index.ts CHANGED
@@ -25,6 +25,6 @@ export type { ParserOptions } from './lib/Parser.js';
25
25
  * @param xml XML string to parse.
26
26
  * @param options Parser options.
27
27
  */
28
- export function parseXml(xml: string, options: ParserOptions) {
28
+ export function parseXml(xml: string, options?: ParserOptions) {
29
29
  return (new Parser(xml, options)).document;
30
30
  }