xml-tokenizer 0.0.2

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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +146 -0
  3. package/dist/cjs/index.js +1 -0
  4. package/dist/cjs/parse-string.js +1 -0
  5. package/dist/cjs/tokenizer/XmlError.js +1 -0
  6. package/dist/cjs/tokenizer/XmlStream.js +1 -0
  7. package/dist/cjs/tokenizer/tokenizer.js +1 -0
  8. package/dist/cjs/tokenizer/utils.js +1 -0
  9. package/dist/cjs/xml-to-object.js +1 -0
  10. package/dist/esm/index.js +1 -0
  11. package/dist/esm/parse-string.js +1 -0
  12. package/dist/esm/tokenizer/XmlError.js +1 -0
  13. package/dist/esm/tokenizer/XmlStream.js +1 -0
  14. package/dist/esm/tokenizer/tokenizer.js +1 -0
  15. package/dist/esm/tokenizer/utils.js +1 -0
  16. package/dist/esm/xml-to-object.js +1 -0
  17. package/dist/types/index.d.ts +4 -0
  18. package/dist/types/index.d.ts.map +1 -0
  19. package/dist/types/parse-string.d.ts +3 -0
  20. package/dist/types/parse-string.d.ts.map +1 -0
  21. package/dist/types/tokenizer/XmlError.d.ts +231 -0
  22. package/dist/types/tokenizer/XmlError.d.ts.map +1 -0
  23. package/dist/types/tokenizer/XmlStream.d.ts +208 -0
  24. package/dist/types/tokenizer/XmlStream.d.ts.map +1 -0
  25. package/dist/types/tokenizer/index.d.ts +6 -0
  26. package/dist/types/tokenizer/index.d.ts.map +1 -0
  27. package/dist/types/tokenizer/tokenizer.d.ts +11 -0
  28. package/dist/types/tokenizer/tokenizer.d.ts.map +1 -0
  29. package/dist/types/tokenizer/types.d.ts +126 -0
  30. package/dist/types/tokenizer/types.d.ts.map +1 -0
  31. package/dist/types/tokenizer/utils.d.ts +69 -0
  32. package/dist/types/tokenizer/utils.d.ts.map +1 -0
  33. package/dist/types/xml-to-object.d.ts +8 -0
  34. package/dist/types/xml-to-object.d.ts.map +1 -0
  35. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 @bennobuilder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ <h1 align="center">
2
+ <img src="https://raw.githubusercontent.com/builder-group/monorepo/develop/packages/roxmltree/.github/banner.svg" alt="roxmltree banner">
3
+ </h1>
4
+
5
+ <p align="left">
6
+ <a href="https://github.com/builder-group/monorepo/blob/develop/LICENSE">
7
+ <img src="https://img.shields.io/github/license/builder-group/monorepo.svg?label=license&style=flat&colorA=293140&colorB=FDE200" alt="GitHub License"/>
8
+ </a>
9
+ <a href="https://www.npmjs.com/package/roxmltree">
10
+ <img src="https://img.shields.io/bundlephobia/minzip/roxmltree.svg?label=minzipped%20size&style=flat&colorA=293140&colorB=FDE200" alt="NPM bundle minzipped size"/>
11
+ </a>
12
+ <a href="https://www.npmjs.com/package/roxmltree">
13
+ <img src="https://img.shields.io/npm/dt/roxmltree.svg?label=downloads&style=flat&colorA=293140&colorB=FDE200" alt="NPM total downloads"/>
14
+ </a>
15
+ <a href="https://discord.gg/w4xE3bSjhQ">
16
+ <img src="https://img.shields.io/discord/795291052897992724.svg?label=&logo=discord&logoColor=000000&color=293140&labelColor=FDE200" alt="Join Discord"/>
17
+ </a>
18
+ </p>
19
+
20
+ > Status: Experimental
21
+
22
+ `xml-tokenizer` is a straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism.
23
+ The implementation is based on the [roxmltree](https://github.com/RazrFalcon/roxmltree) [`tokenizer.rs`](https://github.com/RazrFalcon/roxmltree/blob/master/src/tokenizer.rs). See the [FAQ](#-faq) why we did not embed the [roxmltree](https://github.com/RazrFalcon/roxmltree) crate via WASM.
24
+
25
+ - **Streaming XML Tokenization**: Processes XML documents as a stream, emitting tokens on the fly
26
+ - **Wide Range of Tokens**: Handles processing instructions, comments, entity declarations, element starts/ends, attributes, text, and CDATA sections
27
+ - **Typesafe**: Build with TypeScript for strong type safety
28
+
29
+ ### 📚 Examples
30
+
31
+ - [Vanilla Profiler](https://github.com/builder-group/monorepo/tree/develop/examples/xml-tokenizer/vanilla/profiler)
32
+
33
+ ### 🌟 Motivation
34
+
35
+ Create a typesafe, straightforward, and lightweight [XML](https://de.wikipedia.org/wiki/Extensible_Markup_Language) parser. Many existing parsers either lack TypeScript support, aren't actively maintained, or exceed 20kB gzipped.
36
+
37
+ My goal was to develop an efficient & flexible alternative by porting [roxmltree](https://github.com/RazrFalcon/roxmltree) to TypeScript or integrating it via WASM. While it functions well and is quite flexible due to its streaming approach, it's not as fast as I hoped.
38
+
39
+ ### ⚖️ Alternatives
40
+
41
+ - [txml](https://github.com/TobiasNickel/tXml)
42
+ - [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser)
43
+ - [saxen](https://github.com/nikku/saxen)
44
+
45
+ ## 📖 Usage
46
+
47
+ ```ts
48
+ import { xmlToObject, parseString } from 'roxmltree';
49
+
50
+ // Parse XML to Javascript object (uses `parseString` under the hood)
51
+ const xmlObject = xmlToObject("<p>Hello World</p>");
52
+
53
+ // Or, parse XML to a stream of tokens
54
+ parseString("<p>Hello World</p>", false, (token) => {
55
+ switch (token.type) {
56
+ case 'ElementStart':
57
+ console.log('Start of element:', token);
58
+ break;
59
+ case 'Text':
60
+ console.log('Text content:', token.text);
61
+ break;
62
+ // Handle other token types as needed
63
+ default:
64
+ console.log('Token:', token);
65
+ }
66
+ });
67
+ ```
68
+
69
+ ### Token Types
70
+
71
+ The following token types are supported:
72
+
73
+ - **ProcessingInstruction**: `<?target content?>`
74
+ - **Comment**: `<!-- text -->`
75
+ - **EntityDeclaration**: `<!ENTITY ns_extend "http://test.com">`
76
+ - **ElementStart**: `<ns:elem`
77
+ - **Attribute**: `ns:attr="value"`
78
+ - **ElementEnd**:
79
+ - Open: `>`
80
+ - Close: `</ns:name>`
81
+ - Empty: `/>`
82
+ - **Text**: Text content between elements, including whitespace.
83
+ - **Cdata**: `<![CDATA[text]]>`
84
+
85
+ ## 🚀 Benchmark
86
+
87
+ The performance of `roxmltree` was benchmarked against other popular XML parsers. These tests focus on XML to object conversion and node counting. Interestingly, the version of `roxmltree` imported directly from npm performed significantly better. The reason for this discrepancy is unclear, but the results seem accurate based on external testing.
88
+
89
+ ### XML to Object Conversion
90
+
91
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
92
+ |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
93
+ | roxmltree | 46.87 | 19.47 | 24.57 | 21.33 | ±2.06% |
94
+ | roxmltree (dist) | 53.70 | 17.31 | 25.20 | 18.62 | ±3.28% |
95
+ | roxmltree (npm) | 163.00 | 5.03 | 8.50 | 6.13 | ±2.32% |
96
+ | fast-xml-parser | 66.00 | 14.01 | 20.73 | 15.15 | ±3.34% |
97
+ | txml | 234.52 | 3.38 | 7.61 | 4.26 | ±4.00% |
98
+ | xml2js | 36.21 | 25.58 | 37.28 | 27.61 | ±4.39% |
99
+
100
+ ### Node Counting
101
+
102
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
103
+ |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
104
+ | roxmltree | 53.03 | 18.30 | 19.45 | 18.86 | ±0.81% |
105
+ | roxmltree (npm) | 166.61 | 5.62 | 7.16 | 6.00 | ±0.88% |
106
+ | saxen | 500.99 | 1.83 | 4.79 | 2.00 | ±1.52% |
107
+ | sax | 64.44 | 14.96 | 16.34 | 15.52 | ±0.67% |
108
+
109
+ ### Running the Benchmarks
110
+ The benchmarks can be found in the [`__tests__`](https://github.com/builder-group/community/tree/develop/packages/xml-tokenizer/src/__tests__) directory and can be executed by running:
111
+ ```bash
112
+ pnpm run bench
113
+ ```
114
+
115
+ ## ❓ FAQ
116
+
117
+ ### Why removed Rust implementation (WASM)?
118
+
119
+ We removed the Rust implementation to improve maintainability and because it didn't provide the expected performance boost.
120
+
121
+ Calling a TypeScript function from Rust on every token event (`wasmMix` benchmark) results in slow communication, negating Rust's performance benefits. Parsing XML entirely on the Rust site (`wasm` benchmark) avoids frequent communication but is still too slow due to the overhead of serializing and deserializing data between JavaScript and Rust (mainly the resulting XML-Object). While Rust parsing without returning results is faster than any JavaScript XML parser, needing results in the JavaScript layer makes this approach impractical.
122
+
123
+ The `roxmltree` package with the Rust implementation can be found in the `_deprecated` folder ([`packages/_deprecated/roxmltree_wasm`](https://github.com/builder-group/community/tree/develop/packages/_deprecated/roxmltree_wasm)).
124
+
125
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
126
+ |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
127
+ | roxmltree:text | 67.12 | 14.33 | 83.29 | 80.08 | ±1.27% |
128
+ | roxmltree:wasmMix | 28.17 | 34.83 | 36.71 | 35.49 | ±0.91% |
129
+ | roxmltree:wasm | 109.30 | 8.30 | 13.16 | 9.15 | ±3.31% |
130
+
131
+ ### Why Port `tokenizer.rs` to TypeScript?
132
+
133
+ We ported [`tokenizer.rs`](https://github.com/RazrFalcon/roxmltree/blob/master/src/tokenizer.rs) to TypeScript because frequent communication between Rust and TypeScript negated Rust's performance benefits. The stream architecture required constant interaction between Rust and TypeScript via the `tokenCallback`, reducing overall efficiency.
134
+
135
+ ### Why removed Byte-Based implementation?
136
+
137
+ We removed the byte-based implementation to enhance maintainability and because it didn't provide the expected performance improvement.
138
+
139
+ Decoding `Uint8Array` snippets to JavaScript strings is frequently necessary, nearly on every token event. This decoding process is slow, making this approach less efficient than working directly with strings.
140
+
141
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
142
+ |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
143
+ | roxmltree:text | 67.12 | 14.33 | 83.29 | 80.08 | ±1.27% |
144
+ | roxmltree:byte | 12.48 | 78.65 | 16.45 | 14.90 | ±1.15% |
145
+
146
+ The `roxmltree` package with the Byte-Based implementation can be found in the `_deprecated` folder ([`packages/_deprecated/roxmltree_byte-only`](https://github.com/builder-group/community/tree/develop/packages/_deprecated/roxmltree_byte-only)).
@@ -0,0 +1 @@
1
+ "use strict";var S=require("./parse-string.js"),R=require("./tokenizer/tokenizer.js"),E=require("./tokenizer/utils.js"),r=require("./tokenizer/XmlError.js"),e=require("./tokenizer/XmlStream.js"),A=require("./xml-to-object.js");exports.parseString=S.parseString,exports.parseXmlStream=R.parseXmlStream,exports.AMPERSAND=E.AMPERSAND,exports.CARRIAGE_RETURN=E.CARRIAGE_RETURN,exports.COLON=E.COLON,exports.DOUBLE_QUOTE=E.DOUBLE_QUOTE,exports.EQUALS=E.EQUALS,exports.EXCLAMATION_MARK=E.EXCLAMATION_MARK,exports.GREATER_THAN=E.GREATER_THAN,exports.HASH=E.HASH,exports.HORIZONTAL_TAB=E.HORIZONTAL_TAB,exports.HYPHEN=E.HYPHEN,exports.LESS_THAN=E.LESS_THAN,exports.LINE_FEED=E.LINE_FEED,exports.LOWERCASE_A=E.LOWERCASE_A,exports.LOWERCASE_F=E.LOWERCASE_F,exports.LOWERCASE_X=E.LOWERCASE_X,exports.LOWERCASE_Z=E.LOWERCASE_Z,exports.NINE=E.NINE,exports.OPEN_BRACKET=E.OPEN_BRACKET,exports.PERCENT=E.PERCENT,exports.PERIOD=E.PERIOD,exports.QUESTION_MARK=E.QUESTION_MARK,exports.SEMICOLON=E.SEMICOLON,exports.SINGLE_QUOTE=E.SINGLE_QUOTE,exports.SLASH=E.SLASH,exports.SPACE=E.SPACE,exports.UNDERSCORE=E.UNDERSCORE,exports.UPPERCASE_A=E.UPPERCASE_A,exports.UPPERCASE_F=E.UPPERCASE_F,exports.UPPERCASE_P=E.UPPERCASE_P,exports.UPPERCASE_S=E.UPPERCASE_S,exports.UPPERCASE_Z=E.UPPERCASE_Z,exports.ZERO=E.ZERO,exports.isAsciiDigit=E.isAsciiDigit,exports.isXmlChar=E.isXmlChar,exports.isXmlName=E.isXmlName,exports.isXmlNameByte=E.isXmlNameByte,exports.isXmlNameStart=E.isXmlNameStart,exports.isXmlSpaceByte=E.isXmlSpaceByte,exports.XmlError=r.XmlError,exports.XmlStream=e.XmlStream,exports.getTagName=A.getTagName,exports.xmlToObject=A.xmlToObject;
@@ -0,0 +1 @@
1
+ "use strict";var a=require("./tokenizer/tokenizer.js"),i=require("./tokenizer/XmlStream.js");function m(r,e,t){a.parseXmlStream(new i.XmlStream(r),e,t)}exports.parseString=m;
@@ -0,0 +1 @@
1
+ "use strict";var i=Object.defineProperty,d=(n,t,e)=>t in n?i(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,s=(n,t,e)=>d(n,typeof t!="symbol"?t+"":t,e);class c extends Error{constructor(t,e={col:1,row:1},o){super(o!=null?o:c.toMessage(t,e)),s(this,"variant"),s(this,"pos"),this.variant=t,this.pos=e}static toMessage(t,e){switch(t.type){case"InvalidXmlPrefixUri":return`'xml' namespace prefix mapped to wrong URI at ${a(e)}`;case"UnexpectedXmlUri":return`the 'xml' namespace URI is used for not 'xml' prefix at ${a(e)}`;case"UnexpectedXmlnsUri":return`the 'xmlns' URI is used at ${a(e)}, but it must not be declared`;case"InvalidElementNamePrefix":return`the 'xmlns' prefix is used at ${a(e)}, but it must not be`;case"DuplicatedNamespace":return`namespace '${t.name}' at ${a(e)} is already defined`;case"UnknownNamespace":return`an unknown namespace prefix '${t.name}' at ${a(e)}`;case"UnexpectedCloseTag":return`expected '${t.expected}' tag, not '${t.actual}' at ${a(e)}`;case"UnexpectedEntityCloseTag":return`unexpected close tag at ${a(e)}`;case"MalformedEntityReference":return`malformed entity reference at ${a(e)}`;case"UnknownEntityReference":return`unknown entity reference '${t.name}' at ${a(e)}`;case"EntityReferenceLoop":return`a possible entity reference loop is detected at ${a(e)}`;case"InvalidAttributeValue":return`unescaped '<' found at ${a(e)}`;case"DuplicatedAttribute":return`attribute '${t.attribute}' at ${a(e)} is already defined`;case"NoRootNode":return"the document does not have a root node";case"UnclosedRootNode":return"the root node was opened but never closed";case"UnexpectedDeclaration":return`unexpected XML declaration at ${a(e)}`;case"DtdDetected":return"XML with DTD detected";case"NodesLimitReached":return"nodes limit reached";case"AttributesLimitReached":return"more than 2^32 attributes were parsed";case"NamespacesLimitReached":return"more than 2^16 unique namespaces were parsed";case"InvalidName":return`invalid name token at ${a(e)}`;case"NonXmlChar":return`a non-XML character '${r(t.char)}' found at ${a(e)}`;case"InvalidChar":return`expected ${typeof t.expected=="string"?t.expected:`'${r(t.expected)}'`} not '${r(t.actual)}' at ${a(e)}`;case"InvalidString":return`expected '${t.expected}' at ${a(e)}`;case"InvalidExternalID":return`invalid ExternalID at ${a(e)}`;case"InvalidComment":return`comment at ${a(e)} contains '--'`;case"InvalidCharacterData":return`']]>' at ${a(e)} is not allowed inside a character data`;case"UnknownToken":return`unknown token at ${a(e)}`;case"UnexpectedEndOfStream":return"unexpected end of stream";default:return"unknown error type"}}}function a(n){return`${n.row.toString()}:${n.col.toString()}`}function r(n){const t=typeof n=="string"?n.charCodeAt(0):n;if(t<0||t>1114111)throw new Error("Code point out of range");let e=t.toString(16).toUpperCase();return t<=65535?e=e.padStart(4,"0"):e=e.padStart(6,"0"),`\\u{${e}}`}exports.XmlError=c;
@@ -0,0 +1 @@
1
+ "use strict";var s=require("./utils.js"),o=require("./XmlError.js"),u=Object.defineProperty,m=(h,t,e)=>t in h?u(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,l=(h,t,e)=>m(h,typeof t!="symbol"?t+"":t,e);class c{constructor(t,e=0){l(this,"_text"),l(this,"_pos"),l(this,"_end"),this._text=t,this._pos=e,this._end=this._text.length}clone(){return new c(this._text,this._pos)}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}advance(t){this._pos+=t}startsWith(t){return this._text.startsWith(t,this._pos)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}skipString(t){if(!this.startsWith(t))throw new o.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked());)this._pos+=1}consumeCharsWhile(t){const e=this._pos;return this.skipCharsWhile(t),this.sliceBack(e)}skipCharsWhile(t){for(;this._pos<this._end;){const e=this._text[this._pos];if(e==null||!s.isXmlChar(e.codePointAt(0)))throw new o.XmlError({type:"NonXmlChar",char:e!=null?e:"\uFFFD"},this.genTextPos());if(t(this,e))this._pos+=e.length;else break}}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&s.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),r=e.consumeReference();return r!=null?(this._pos+=e.getPos()-t,r):null}consumeReference(){if(!this.tryConsumeCodeUnit(s.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(s.HASH)){let e,r;this.tryConsumeCodeUnit(s.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(i=>i>=s.ZERO&&i<=s.NINE||i>=s.UPPERCASE_A&&i<=s.UPPERCASE_F||i>=s.LOWERCASE_A&&i<=s.LOWERCASE_F),r=16):(e=this.consumeCodeUnitsWhile(i=>s.isAsciiDigit(i)),r=10);const n=parseInt(e,r);isNaN(n)||!s.isXmlChar(n)?t=null:t={type:"Char",value:String.fromCodePoint(n)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(s.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!s.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!s.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const r=this._pos;let n=null;for(;this._pos<this._end;){const p=this.currCodeUnitUnchecked();if(p===s.COLON)if(n==null)n=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));else if(s.isXmlName(p))this._pos+=1;else break}let i,a;if(n!=null?(i=this._text.slice(r,n),a=this.sliceBack(n+1)):(i="",a=this.sliceBack(r)),i.length>0&&!s.isXmlNameStart((t=i[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));if(a.length>0){if(!s.isXmlNameStart((e=a[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));return[i,a]}consumeEq(){this.skipSpaces(),this.consumeCodeUnit(s.EQUALS),this.skipSpaces()}consumeQuote(){const t=this.currCodeUnit();if(t===s.SINGLE_QUOTE||t===s.DOUBLE_QUOTE)return this._pos+=1,t;throw new o.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let r=1,n=1;for(let i=0;i<e;i++)this._text.charCodeAt(i)===s.LINE_FEED?(r++,n=1):n++;return{row:r,col:n}}}exports.XmlStream=c;
@@ -0,0 +1 @@
1
+ "use strict";var r=require("./utils.js"),i=require("./XmlError.js");function U(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&P(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i.XmlError({type:"DtdDetected"});w(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===r.LESS_THAN&&g(t,s),m(t,s),!t.atEnd())throw new i.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!--"))h(t,n);else if(t.startsWith("<?"))f(t,n);else break}function P(t){if(t.advance(5),E(t),!t.startsWith("version"))throw new i.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());u(t),E(t),t.startsWith("encoding")&&(u(t),E(t)),t.startsWith("standalone")&&u(t),t.skipSpaces(),t.skipString("?>")}function E(t){if(t.startsWithSpace())t.skipSpaces();else if(!t.startsWith("?>")&&!t.atEnd())throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos())}function h(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCharsWhile((e,a)=>!(a==="-"&&e.startsWith("-->")));if(t.skipString("-->"),o.includes("--")||o.endsWith("-"))throw new i.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function f(t,n){if(t.startsWith("<?xml "))throw new i.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith("?>")));t.skipString("?>"),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function w(t,n){const s=t.getPos();if(A(t),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!ENTITY"))W(t,n);else if(t.startsWith("<!--"))h(t,n);else if(t.startsWith("<?"))f(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);break}else throw new i.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith("<!ELEMENT")||t.startsWith("<!ATTLIST")||t.startsWith("<!NOTATION"))try{y(t)}catch(o){throw new i.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function A(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),T(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==r.OPEN_BRACKET&&n!==r.GREATER_THAN)throw new i.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function T(t){if(t.startsWith("SYSTEM")||t.startsWith("PUBLIC")){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s==="PUBLIC"){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==e),t.consumeCodeUnit(e)}return!0}return!1}function W(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(r.PERCENT);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=v(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN)}function v(t,n){const s=t.currCodeUnit();if(s===r.DOUBLE_QUOTE||s===r.SINGLE_QUOTE){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const a=t.sliceBack(e);return t.consumeCodeUnit(o),a}else if(s===r.UPPERCASE_S||s===r.UPPERCASE_P){if(T(t))return n&&(t.skipSpaces(),t.startsWith("NDATA")&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new i.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new i.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function y(t){t.skipCodeUnitsWhile(n=>n!==r.GREATER_THAN),t.consumeCodeUnit(r.GREATER_THAN)}function g(t,n){const s=t.getPos();t.advance(1);const[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s});let a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const d=t.getPos(),l=t.currCodeUnit();if(l===r.SLASH){t.advance(1),t.consumeCodeUnit(r.GREATER_THAN);const p=t.rangeFrom(d);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(l===r.GREATER_THAN){t.advance(1);const p=t.rangeFrom(d);n({type:"ElementEnd",end:{type:"Open"},range:p}),a=!0;break}else{if(!c)throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[p,C,S]=u(t),k=t.getPos();n({type:"Attribute",range:{start:d,end:k},prefix:p,local:C,value:S})}}a&&x(t,n)}function u(t){const[n,s]=t.consumeQName();t.consumeEq();const o=t.consumeQuote(),e=String.fromCharCode(o),a=t.getPos();t.skipCharsWhile((d,l)=>l!==e&&l!=="<");const c=t.sliceBack(a);return t.consumeCodeUnit(o),[n,s,c]}function x(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===r.LESS_THAN){const s=t.nextCodeUnit();if(s===r.EXCLAMATION_MARK)if(t.startsWith("<!--"))h(t,n);else if(t.startsWith("<![CDATA["))N(t,n);else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===r.QUESTION_MARK)f(t,n);else if(s===r.SLASH){R(t,n);break}else g(t,n)}else I(t,n)}function N(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith("]]>")));t.skipString("]]>");const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function R(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:a})}function I(t,n){const s=t.getPos(),o=t.consumeCharsWhile((e,a)=>a!=="<");if(o.includes(">")&&o.includes("]]>"))throw new i.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}exports.parseXmlStream=U;
@@ -0,0 +1 @@
1
+ "use strict";const C=9,P=10,L=13,T=32,U=33,i=34,I=35,t=37,H=38,n=39,e=45,r=46,s=47,D=48,l=57,m=58,u=59,X=60,M=61,B=62,a=63,c=65,Q=70,W=80,Z=83,F=90,G=91,K=95,o=97,f=102,y=120,Y=122;function S(E){return E>=48&&E<=57}function N(E){return E==null?!1:E<=128?E>=65&&E<=90||E>=97&&E<=122||E===58||E===95:E>=192&&E<=214||E>=216&&E<=246||E>=248&&E<=767||E>=880&&E<=893||E>=895&&E<=8191||E>=8204&&E<=8205||E>=8304&&E<=8591||E>=11264&&E<=12271||E>=12289&&E<=55295||E>=63744&&E<=64975||E>=65008&&E<=65533||E>=65536&&E<=983039}function O(E){return E==null?!1:E<=128?R(E):E===183||E>=192&&E<=214||E>=216&&E<=246||E>=248&&E<=767||E>=768&&E<=879||E>=880&&E<=893||E>=895&&E<=8191||E>=8204&&E<=8205||E>=8255&&E<=8256||E>=8304&&E<=8591||E>=11264&&E<=12271||E>=12289&&E<=55295||E>=63744&&E<=64975||E>=65008&&E<=65533||E>=65536&&E<=983039}function _(E){return E==null?!1:E<32?A(E):E!==65535&&E!==65534}function A(E){return E===32||E===9||E===10||E===13}function R(E){return E>=48&&E<=57||E>=65&&E<=90||E>=97&&E<=122||E===58||E===95||E===45||E===46}exports.AMPERSAND=38,exports.CARRIAGE_RETURN=13,exports.COLON=58,exports.DOUBLE_QUOTE=34,exports.EQUALS=61,exports.EXCLAMATION_MARK=33,exports.GREATER_THAN=62,exports.HASH=35,exports.HORIZONTAL_TAB=9,exports.HYPHEN=45,exports.LESS_THAN=60,exports.LINE_FEED=10,exports.LOWERCASE_A=97,exports.LOWERCASE_F=102,exports.LOWERCASE_X=120,exports.LOWERCASE_Z=122,exports.NINE=57,exports.OPEN_BRACKET=91,exports.PERCENT=37,exports.PERIOD=46,exports.QUESTION_MARK=63,exports.SEMICOLON=59,exports.SINGLE_QUOTE=39,exports.SLASH=47,exports.SPACE=32,exports.UNDERSCORE=95,exports.UPPERCASE_A=65,exports.UPPERCASE_F=70,exports.UPPERCASE_P=80,exports.UPPERCASE_S=83,exports.UPPERCASE_Z=90,exports.ZERO=48,exports.isAsciiDigit=S,exports.isXmlChar=_,exports.isXmlName=O,exports.isXmlNameByte=R,exports.isXmlNameStart=N,exports.isXmlSpaceByte=A;
@@ -0,0 +1 @@
1
+ "use strict";var s=require("./tokenizer/tokenizer.js"),m=require("./tokenizer/XmlStream.js");function u(a,l=!1){const c={tagName:"root",attributes:{},children:[]},n=[c];let r=c;return s.parseXmlStream(new m.XmlStream(a),l,t=>{switch(t.type){case"ElementStart":{const e={tagName:i(t.local,t.prefix),attributes:{},children:[]};r.children.push(e),n.push(e),r=e;break}case"ElementEnd":{if(t.end.type==="Close"||t.end.type==="Empty"){n.pop();const e=n[n.length-1];e!=null&&(r=e)}break}case"Attribute":{r.attributes[i(t.local,t.prefix)]=t.value;break}case"Text":case"Cdata":{t.text.trim().length>0&&r.children.push(t.text);break}}}),c.children[0]}function i(a,l){return l.length>0?`${l}:${a}`:a}exports.getTagName=i,exports.xmlToObject=u;
@@ -0,0 +1 @@
1
+ import{parseString as S}from"./parse-string.js";import{parseXmlStream as r}from"./tokenizer/tokenizer.js";import{AMPERSAND as N,CARRIAGE_RETURN as O,COLON as e,DOUBLE_QUOTE as _,EQUALS as C,EXCLAMATION_MARK as P,GREATER_THAN as t,HASH as o,HORIZONTAL_TAB as L,HYPHEN as T,LESS_THAN as a,LINE_FEED as U,LOWERCASE_A as i,LOWERCASE_F as X,LOWERCASE_X as l,LOWERCASE_Z as p,NINE as s,OPEN_BRACKET as I,PERCENT as H,PERIOD as x,QUESTION_MARK as f,SEMICOLON as D,SINGLE_QUOTE as B,SLASH as M,SPACE as g,UNDERSCORE as Q,UPPERCASE_A as W,UPPERCASE_F as Z,UPPERCASE_P as c,UPPERCASE_S as F,UPPERCASE_Z as G,ZERO as K,isAsciiDigit as y,isXmlChar as b,isXmlName as h,isXmlNameByte as j,isXmlNameStart as n,isXmlSpaceByte as Y}from"./tokenizer/utils.js";import{XmlError as k}from"./tokenizer/XmlError.js";import{XmlStream as u}from"./tokenizer/XmlStream.js";import{getTagName as w,xmlToObject as z}from"./xml-to-object.js";export{N as AMPERSAND,O as CARRIAGE_RETURN,e as COLON,_ as DOUBLE_QUOTE,C as EQUALS,P as EXCLAMATION_MARK,t as GREATER_THAN,o as HASH,L as HORIZONTAL_TAB,T as HYPHEN,a as LESS_THAN,U as LINE_FEED,i as LOWERCASE_A,X as LOWERCASE_F,l as LOWERCASE_X,p as LOWERCASE_Z,s as NINE,I as OPEN_BRACKET,H as PERCENT,x as PERIOD,f as QUESTION_MARK,D as SEMICOLON,B as SINGLE_QUOTE,M as SLASH,g as SPACE,Q as UNDERSCORE,W as UPPERCASE_A,Z as UPPERCASE_F,c as UPPERCASE_P,F as UPPERCASE_S,G as UPPERCASE_Z,k as XmlError,u as XmlStream,K as ZERO,w as getTagName,y as isAsciiDigit,b as isXmlChar,h as isXmlName,j as isXmlNameByte,n as isXmlNameStart,Y as isXmlSpaceByte,S as parseString,r as parseXmlStream,z as xmlToObject};
@@ -0,0 +1 @@
1
+ import{parseXmlStream as e}from"./tokenizer/tokenizer.js";import{XmlStream as o}from"./tokenizer/XmlStream.js";function p(r,m,t){e(new o(r),m,t)}export{p as parseString};
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty,d=(n,t,e)=>t in n?i(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,s=(n,t,e)=>d(n,typeof t!="symbol"?t+"":t,e);class c extends Error{constructor(t,e={col:1,row:1},o){super(o!=null?o:c.toMessage(t,e)),s(this,"variant"),s(this,"pos"),this.variant=t,this.pos=e}static toMessage(t,e){switch(t.type){case"InvalidXmlPrefixUri":return`'xml' namespace prefix mapped to wrong URI at ${a(e)}`;case"UnexpectedXmlUri":return`the 'xml' namespace URI is used for not 'xml' prefix at ${a(e)}`;case"UnexpectedXmlnsUri":return`the 'xmlns' URI is used at ${a(e)}, but it must not be declared`;case"InvalidElementNamePrefix":return`the 'xmlns' prefix is used at ${a(e)}, but it must not be`;case"DuplicatedNamespace":return`namespace '${t.name}' at ${a(e)} is already defined`;case"UnknownNamespace":return`an unknown namespace prefix '${t.name}' at ${a(e)}`;case"UnexpectedCloseTag":return`expected '${t.expected}' tag, not '${t.actual}' at ${a(e)}`;case"UnexpectedEntityCloseTag":return`unexpected close tag at ${a(e)}`;case"MalformedEntityReference":return`malformed entity reference at ${a(e)}`;case"UnknownEntityReference":return`unknown entity reference '${t.name}' at ${a(e)}`;case"EntityReferenceLoop":return`a possible entity reference loop is detected at ${a(e)}`;case"InvalidAttributeValue":return`unescaped '<' found at ${a(e)}`;case"DuplicatedAttribute":return`attribute '${t.attribute}' at ${a(e)} is already defined`;case"NoRootNode":return"the document does not have a root node";case"UnclosedRootNode":return"the root node was opened but never closed";case"UnexpectedDeclaration":return`unexpected XML declaration at ${a(e)}`;case"DtdDetected":return"XML with DTD detected";case"NodesLimitReached":return"nodes limit reached";case"AttributesLimitReached":return"more than 2^32 attributes were parsed";case"NamespacesLimitReached":return"more than 2^16 unique namespaces were parsed";case"InvalidName":return`invalid name token at ${a(e)}`;case"NonXmlChar":return`a non-XML character '${r(t.char)}' found at ${a(e)}`;case"InvalidChar":return`expected ${typeof t.expected=="string"?t.expected:`'${r(t.expected)}'`} not '${r(t.actual)}' at ${a(e)}`;case"InvalidString":return`expected '${t.expected}' at ${a(e)}`;case"InvalidExternalID":return`invalid ExternalID at ${a(e)}`;case"InvalidComment":return`comment at ${a(e)} contains '--'`;case"InvalidCharacterData":return`']]>' at ${a(e)} is not allowed inside a character data`;case"UnknownToken":return`unknown token at ${a(e)}`;case"UnexpectedEndOfStream":return"unexpected end of stream";default:return"unknown error type"}}}function a(n){return`${n.row.toString()}:${n.col.toString()}`}function r(n){const t=typeof n=="string"?n.charCodeAt(0):n;if(t<0||t>1114111)throw new Error("Code point out of range");let e=t.toString(16).toUpperCase();return t<=65535?e=e.padStart(4,"0"):e=e.padStart(6,"0"),`\\u{${e}}`}export{c as XmlError};
@@ -0,0 +1 @@
1
+ import{isXmlChar as u,isXmlSpaceByte as _,AMPERSAND as m,HASH as C,LOWERCASE_X as f,ZERO as U,NINE as x,UPPERCASE_A as w,UPPERCASE_F as y,LOWERCASE_A as k,LOWERCASE_F as g,isAsciiDigit as E,SEMICOLON as P,isXmlNameStart as a,isXmlName as d,COLON as S,EQUALS as v,SINGLE_QUOTE as N,DOUBLE_QUOTE as A,LINE_FEED as T}from"./utils.js";import{XmlError as n}from"./XmlError.js";var W=Object.defineProperty,F=(h,t,e)=>t in h?W(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,c=(h,t,e)=>F(h,typeof t!="symbol"?t+"":t,e);class p{constructor(t,e=0){c(this,"_text"),c(this,"_pos"),c(this,"_end"),this._text=t,this._pos=e,this._end=this._text.length}clone(){return new p(this._text,this._pos)}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new n({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new n({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}advance(t){this._pos+=t}startsWith(t){return this._text.startsWith(t,this._pos)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new n({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}skipString(t){if(!this.startsWith(t))throw new n({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked());)this._pos+=1}consumeCharsWhile(t){const e=this._pos;return this.skipCharsWhile(t),this.sliceBack(e)}skipCharsWhile(t){for(;this._pos<this._end;){const e=this._text[this._pos];if(e==null||!u(e.codePointAt(0)))throw new n({type:"NonXmlChar",char:e!=null?e:"\uFFFD"},this.genTextPos());if(t(this,e))this._pos+=e.length;else break}}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&_(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new n({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new n({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(m))return null;let t;if(this.tryConsumeCodeUnit(C)){let e,i;this.tryConsumeCodeUnit(f)?(e=this.consumeCodeUnitsWhile(s=>s>=U&&s<=x||s>=w&&s<=y||s>=k&&s<=g),i=16):(e=this.consumeCodeUnitsWhile(s=>E(s)),i=10);const o=parseInt(e,i);isNaN(o)||!u(o)?t=null:t={type:"Char",value:String.fromCodePoint(o)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(P)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new n({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!a(e))throw new n({type:"InvalidName"},this.genTextPosFrom(t))}else if(!d(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let o=null;for(;this._pos<this._end;){const l=this.currCodeUnitUnchecked();if(l===S)if(o==null)o=this._pos,this._pos+=1;else throw new n({type:"InvalidName"},this.genTextPosFrom(i));else if(d(l))this._pos+=1;else break}let s,r;if(o!=null?(s=this._text.slice(i,o),r=this.sliceBack(o+1)):(s="",r=this.sliceBack(i)),s.length>0&&!a((t=s[0])==null?void 0:t.codePointAt(0)))throw new n({type:"InvalidName"},this.genTextPosFrom(i));if(r.length>0){if(!a((e=r[0])==null?void 0:e.codePointAt(0)))throw new n({type:"InvalidName"},this.genTextPosFrom(i))}else throw new n({type:"InvalidName"},this.genTextPosFrom(i));return[s,r]}consumeEq(){this.skipSpaces(),this.consumeCodeUnit(v),this.skipSpaces()}consumeQuote(){const t=this.currCodeUnit();if(t===N||t===A)return this._pos+=1,t;throw new n({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let i=1,o=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===T?(i++,o=1):o++;return{row:i,col:o}}}export{p as XmlStream};
@@ -0,0 +1 @@
1
+ import{LESS_THAN as C,GREATER_THAN as r,OPEN_BRACKET as w,PERCENT as W,DOUBLE_QUOTE as x,SINGLE_QUOTE as y,UPPERCASE_S as v,UPPERCASE_P as I,SLASH as S,EXCLAMATION_MARK as N,QUESTION_MARK as A}from"./utils.js";import{XmlError as i}from"./XmlError.js";function F(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&D(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i({type:"DtdDetected"});L(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===C&&k(t,s),m(t,s),!t.atEnd())throw new i({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!--"))f(t,n);else if(t.startsWith("<?"))g(t,n);else break}function D(t){if(t.advance(5),h(t),!t.startsWith("version"))throw new i({type:"InvalidString",expected:"version"},t.genTextPos());l(t),h(t),t.startsWith("encoding")&&(l(t),h(t)),t.startsWith("standalone")&&l(t),t.skipSpaces(),t.skipString("?>")}function h(t){if(t.startsWithSpace())t.skipSpaces();else if(!t.startsWith("?>")&&!t.atEnd())throw new i({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos())}function f(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCharsWhile((e,a)=>!(a==="-"&&e.startsWith("-->")));if(t.skipString("-->"),o.includes("--")||o.endsWith("-"))throw new i({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function g(t,n){if(t.startsWith("<?xml "))throw new i({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith("?>")));t.skipString("?>"),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function L(t,n){const s=t.getPos();if(O(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!ENTITY"))Q(t,n);else if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<?"))g(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new i({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith("<!ELEMENT")||t.startsWith("<!ATTLIST")||t.startsWith("<!NOTATION"))try{B(t)}catch(o){throw new i({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new i({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function O(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),E(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==w&&n!==r)throw new i({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function E(t){if(t.startsWith("SYSTEM")||t.startsWith("PUBLIC")){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s==="PUBLIC"){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==e),t.consumeCodeUnit(e)}return!0}return!1}function Q(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(W);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=_(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r)}function _(t,n){const s=t.currCodeUnit();if(s===x||s===y){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const a=t.sliceBack(e);return t.consumeCodeUnit(o),a}else if(s===v||s===I){if(E(t))return n&&(t.skipSpaces(),t.startsWith("NDATA")&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new i({type:"InvalidExternalID"},t.genTextPos())}else throw new i({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function B(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function k(t,n){const s=t.getPos();t.advance(1);const[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s});let a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const u=t.getPos(),p=t.currCodeUnit();if(p===S){t.advance(1),t.consumeCodeUnit(r);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Empty"},range:d});break}else if(p===r){t.advance(1);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Open"},range:d}),a=!0;break}else{if(!c)throw new i({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[d,U,T]=l(t),P=t.getPos();n({type:"Attribute",range:{start:u,end:P},prefix:d,local:U,value:T})}}a&&R(t,n)}function l(t){const[n,s]=t.consumeQName();t.consumeEq();const o=t.consumeQuote(),e=String.fromCharCode(o),a=t.getPos();t.skipCharsWhile((u,p)=>p!==e&&p!=="<");const c=t.sliceBack(a);return t.consumeCodeUnit(o),[n,s,c]}function R(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===C){const s=t.nextCodeUnit();if(s===N)if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<![CDATA["))b(t,n);else throw new i({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===A)g(t,n);else if(s===S){M(t,n);break}else k(t,n)}else Y(t,n)}function b(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith("]]>")));t.skipString("]]>");const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function M(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:a})}function Y(t,n){const s=t.getPos(),o=t.consumeCharsWhile((e,a)=>a!=="<");if(o.includes(">")&&o.includes("]]>"))throw new i({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}export{F as parseXmlStream};
@@ -0,0 +1 @@
1
+ const S=9,n=10,N=13,t=32,O=33,_=34,C=35,P=37,i=38,r=39,u=45,L=46,e=47,T=48,U=57,l=58,c=59,I=60,m=61,o=62,s=63,H=65,X=70,a=80,f=83,D=90,B=91,M=95,Q=97,W=102,Z=120,F=122;function G(E){return E>=48&&E<=57}function K(E){return E==null?!1:E<=128?E>=65&&E<=90||E>=97&&E<=122||E===58||E===95:E>=192&&E<=214||E>=216&&E<=246||E>=248&&E<=767||E>=880&&E<=893||E>=895&&E<=8191||E>=8204&&E<=8205||E>=8304&&E<=8591||E>=11264&&E<=12271||E>=12289&&E<=55295||E>=63744&&E<=64975||E>=65008&&E<=65533||E>=65536&&E<=983039}function p(E){return E==null?!1:E<=128?R(E):E===183||E>=192&&E<=214||E>=216&&E<=246||E>=248&&E<=767||E>=768&&E<=879||E>=880&&E<=893||E>=895&&E<=8191||E>=8204&&E<=8205||E>=8255&&E<=8256||E>=8304&&E<=8591||E>=11264&&E<=12271||E>=12289&&E<=55295||E>=63744&&E<=64975||E>=65008&&E<=65533||E>=65536&&E<=983039}function y(E){return E==null?!1:E<32?A(E):E!==65535&&E!==65534}function A(E){return E===32||E===9||E===10||E===13}function R(E){return E>=48&&E<=57||E>=65&&E<=90||E>=97&&E<=122||E===58||E===95||E===45||E===46}export{i as AMPERSAND,N as CARRIAGE_RETURN,l as COLON,_ as DOUBLE_QUOTE,m as EQUALS,O as EXCLAMATION_MARK,o as GREATER_THAN,C as HASH,S as HORIZONTAL_TAB,u as HYPHEN,I as LESS_THAN,n as LINE_FEED,Q as LOWERCASE_A,W as LOWERCASE_F,Z as LOWERCASE_X,F as LOWERCASE_Z,U as NINE,B as OPEN_BRACKET,P as PERCENT,L as PERIOD,s as QUESTION_MARK,c as SEMICOLON,r as SINGLE_QUOTE,e as SLASH,t as SPACE,M as UNDERSCORE,H as UPPERCASE_A,X as UPPERCASE_F,a as UPPERCASE_P,f as UPPERCASE_S,D as UPPERCASE_Z,T as ZERO,G as isAsciiDigit,y as isXmlChar,p as isXmlName,R as isXmlNameByte,K as isXmlNameStart,A as isXmlSpaceByte};
@@ -0,0 +1 @@
1
+ import{parseXmlStream as s}from"./tokenizer/tokenizer.js";import{XmlStream as o}from"./tokenizer/XmlStream.js";function m(a,n=!1){const c={tagName:"root",attributes:{},children:[]},l=[c];let r=c;return s(new o(a),n,t=>{switch(t.type){case"ElementStart":{const e={tagName:i(t.local,t.prefix),attributes:{},children:[]};r.children.push(e),l.push(e),r=e;break}case"ElementEnd":{if(t.end.type==="Close"||t.end.type==="Empty"){l.pop();const e=l[l.length-1];e!=null&&(r=e)}break}case"Attribute":{r.attributes[i(t.local,t.prefix)]=t.value;break}case"Text":case"Cdata":{t.text.trim().length>0&&r.children.push(t.text);break}}}),c.children[0]}function i(a,n){return n.length>0?`${n}:${a}`:a}export{i as getTagName,m as xmlToObject};
@@ -0,0 +1,4 @@
1
+ export * from './parse-string';
2
+ export * from './tokenizer';
3
+ export * from './xml-to-object';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type TTokenCallback } from './tokenizer';
2
+ export declare function parseString(xmlString: string, allowDtd: boolean, tokenCallback: TTokenCallback): void;
3
+ //# sourceMappingURL=parse-string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-string.d.ts","sourceRoot":"","sources":["../../src/parse-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7E,wBAAgB,WAAW,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAEN"}
@@ -0,0 +1,231 @@
1
+ import { type TTextPos } from './types';
2
+ export declare class XmlError extends Error {
3
+ readonly variant: TXMLErrorVariant;
4
+ readonly pos: TTextPos;
5
+ constructor(variant: TXMLErrorVariant, pos?: TTextPos, message?: string);
6
+ static toMessage(variant: TXMLErrorVariant, pos: TTextPos): string;
7
+ }
8
+ type TXMLErrorVariant = TInvalidXmlPrefixUri | TUnexpectedXmlUri | TUnexpectedXmlnsUri | TInvalidElementNamePrefix | TDuplicatedNamespace | TUnknownNamespace | TUnexpectedCloseTag | TUnexpectedEntityCloseTag | TUnknownEntityReference | TMalformedEntityReference | TEntityReferenceLoop | TInvalidAttributeValue | TDuplicatedAttribute | TNoRootNode | TUnclosedRootNode | TUnexpectedDeclaration | TDtdDetected | TNodesLimitReached | TAttributesLimitReached | TNamespacesLimitReached | TInvalidName | TNonXmlChar | TInvalidChar | TInvalidString | TInvalidExternalID | TInvalidComment | TInvalidCharacterData | TUnknownToken | TUnexpectedEndOfStream;
9
+ /**
10
+ * The `xmlns:xml` attribute must have an \<http://www.w3.org/XML/1998/namespace\> URI.
11
+ */
12
+ interface TInvalidXmlPrefixUri {
13
+ type: 'InvalidXmlPrefixUri';
14
+ }
15
+ /**
16
+ * Only the `xmlns:xml` attribute can have the \<http://www.w3.org/XML/1998/namespace\> URI.
17
+ */
18
+ interface TUnexpectedXmlUri {
19
+ type: 'UnexpectedXmlUri';
20
+ }
21
+ /**
22
+ * The \<http://www.w3.org/2000/xmlns/\> URI must not be declared.
23
+ */
24
+ interface TUnexpectedXmlnsUri {
25
+ type: 'UnexpectedXmlnsUri';
26
+ }
27
+ /**
28
+ * `xmlns` can't be used as an element prefix.
29
+ */
30
+ interface TInvalidElementNamePrefix {
31
+ type: 'InvalidElementNamePrefix';
32
+ }
33
+ /**
34
+ * A namespace was already defined on this element.
35
+ */
36
+ interface TDuplicatedNamespace {
37
+ type: 'DuplicatedNamespace';
38
+ name: string;
39
+ }
40
+ /**
41
+ * An unknown namespace.
42
+ *
43
+ * Indicates that an element or an attribute has an unknown qualified name prefix.
44
+ *
45
+ * The first value is a prefix.
46
+ */
47
+ interface TUnknownNamespace {
48
+ type: 'UnknownNamespace';
49
+ name: string;
50
+ }
51
+ /**
52
+ * Incorrect tree structure.
53
+ *
54
+ * expected, actual, position
55
+ */
56
+ interface TUnexpectedCloseTag {
57
+ type: 'UnexpectedCloseTag';
58
+ expected: string;
59
+ actual: string;
60
+ }
61
+ /**
62
+ * Entity value starts with a close tag.
63
+ *
64
+ * Example:
65
+ * ```xml
66
+ * <!DOCTYPE test [ <!ENTITY p '</p>'> ]>
67
+ * <root>&p;</root>
68
+ * ```
69
+ */
70
+ interface TUnexpectedEntityCloseTag {
71
+ type: 'UnexpectedEntityCloseTag';
72
+ }
73
+ /**
74
+ * A reference to an entity that was not defined in the DTD.
75
+ */
76
+ interface TUnknownEntityReference {
77
+ type: 'UnknownEntityReference';
78
+ name: string;
79
+ }
80
+ /**
81
+ * A malformed entity reference.
82
+ *
83
+ * A `&` character inside an attribute value or text indicates an entity reference.
84
+ * Otherwise, the document is not well-formed.
85
+ */
86
+ interface TMalformedEntityReference {
87
+ type: 'MalformedEntityReference';
88
+ }
89
+ /**
90
+ * A possible entity reference loop.
91
+ *
92
+ * The current depth limit is 10. The max number of references per reference is 255.
93
+ */
94
+ interface TEntityReferenceLoop {
95
+ type: 'EntityReferenceLoop';
96
+ }
97
+ /**
98
+ * Attribute value cannot have a `<` character.
99
+ */
100
+ interface TInvalidAttributeValue {
101
+ type: 'InvalidAttributeValue';
102
+ }
103
+ /**
104
+ * An element has duplicated attributes.
105
+ *
106
+ * This also includes namespaces resolving.
107
+ * So an element like this will lead to an error.
108
+ * ```xml
109
+ * <e xmlns:n1='http://www.w3.org' xmlns:n2='http://www.w3.org' n1:a='b1' n2:a='b2'/>
110
+ * ```
111
+ */
112
+ interface TDuplicatedAttribute {
113
+ type: 'DuplicatedAttribute';
114
+ attribute: string;
115
+ }
116
+ /**
117
+ * The XML document must have at least one element.
118
+ */
119
+ interface TNoRootNode {
120
+ type: 'NoRootNode';
121
+ }
122
+ /**
123
+ * The root node was opened but never closed.
124
+ */
125
+ interface TUnclosedRootNode {
126
+ type: 'UnclosedRootNode';
127
+ }
128
+ /**
129
+ * An XML document can have only one XML declaration
130
+ * and it must be at the start of the document.
131
+ */
132
+ interface TUnexpectedDeclaration {
133
+ type: 'UnexpectedDeclaration';
134
+ }
135
+ /**
136
+ * An XML with DTD detected.
137
+ *
138
+ * This error will be emitted only when `ParsingOptions::allow_dtd` is set to `false`.
139
+ */
140
+ interface TDtdDetected {
141
+ type: 'DtdDetected';
142
+ }
143
+ /**
144
+ * Indicates that the `ParsingOptions::nodes_limit` was reached.
145
+ */
146
+ interface TNodesLimitReached {
147
+ type: 'NodesLimitReached';
148
+ }
149
+ /**
150
+ * Indicates that too many attributes were parsed.
151
+ */
152
+ interface TAttributesLimitReached {
153
+ type: 'AttributesLimitReached';
154
+ }
155
+ /**
156
+ * Indicates that too many namespaces were parsed.
157
+ */
158
+ interface TNamespacesLimitReached {
159
+ type: 'NamespacesLimitReached';
160
+ }
161
+ /**
162
+ * An invalid name.
163
+ */
164
+ interface TInvalidName {
165
+ type: 'InvalidName';
166
+ }
167
+ /**
168
+ * A non-XML character has occurred.
169
+ *
170
+ * Valid characters are: \<https://www.w3.org/TR/xml/#char32\>
171
+ */
172
+ interface TNonXmlChar {
173
+ type: 'NonXmlChar';
174
+ char: string;
175
+ }
176
+ /**
177
+ * An invalid/unexpected character.
178
+ *
179
+ * expected, actual, position
180
+ */
181
+ interface TInvalidChar {
182
+ type: 'InvalidChar';
183
+ expected: string | number;
184
+ actual: number;
185
+ }
186
+ /**
187
+ * An unexpected string.
188
+ *
189
+ * Contains what string was expected.
190
+ */
191
+ interface TInvalidString {
192
+ type: 'InvalidString';
193
+ expected: string;
194
+ }
195
+ /**
196
+ * An invalid ExternalID in the DTD.
197
+ */
198
+ interface TInvalidExternalID {
199
+ type: 'InvalidExternalID';
200
+ }
201
+ /**
202
+ * A comment cannot contain `--` or end with `-`.
203
+ */
204
+ interface TInvalidComment {
205
+ type: 'InvalidComment';
206
+ }
207
+ /**
208
+ * A Character Data node contains invalid data.
209
+ *
210
+ * Currently, only `]]>` is not allowed.
211
+ */
212
+ interface TInvalidCharacterData {
213
+ type: 'InvalidCharacterData';
214
+ }
215
+ /**
216
+ * An unknown token.
217
+ */
218
+ interface TUnknownToken {
219
+ type: 'UnknownToken';
220
+ message?: string;
221
+ }
222
+ /**
223
+ * The stream ended earlier than we expected.
224
+ *
225
+ * Should only appear on invalid input data.
226
+ */
227
+ interface TUnexpectedEndOfStream {
228
+ type: 'UnexpectedEndOfStream';
229
+ }
230
+ export {};
231
+ //# sourceMappingURL=XmlError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlError.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/XmlError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,QAAS,SAAQ,KAAK;IAClC,SAAgB,OAAO,EAAE,gBAAgB,CAAC;IAC1C,SAAgB,GAAG,EAAE,QAAQ,CAAC;gBAElB,OAAO,EAAE,gBAAgB,EAAE,GAAG,GAAE,QAA6B,EAAE,OAAO,CAAC,EAAE,MAAM;IAM3F,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM;CAgElE;AAwBD,KAAK,gBAAgB,GAClB,oBAAoB,GACpB,iBAAiB,GACjB,mBAAmB,GACnB,yBAAyB,GACzB,oBAAoB,GACpB,iBAAiB,GACjB,mBAAmB,GACnB,yBAAyB,GACzB,uBAAuB,GACvB,yBAAyB,GACzB,oBAAoB,GACpB,sBAAsB,GACtB,oBAAoB,GACpB,WAAW,GACX,iBAAiB,GACjB,sBAAsB,GACtB,YAAY,GACZ,kBAAkB,GAClB,uBAAuB,GACvB,uBAAuB,GACvB,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,cAAc,GACd,kBAAkB,GAClB,eAAe,GACf,qBAAqB,GACrB,aAAa,GACb,sBAAsB,CAAC;AAE1B;;GAEG;AACH,UAAU,oBAAoB;IAC7B,IAAI,EAAE,qBAAqB,CAAC;CAC5B;AAED;;GAEG;AACH,UAAU,iBAAiB;IAC1B,IAAI,EAAE,kBAAkB,CAAC;CACzB;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC5B,IAAI,EAAE,oBAAoB,CAAC;CAC3B;AAED;;GAEG;AACH,UAAU,yBAAyB;IAClC,IAAI,EAAE,0BAA0B,CAAC;CACjC;AAED;;GAEG;AACH,UAAU,oBAAoB;IAC7B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;;;GAMG;AACH,UAAU,iBAAiB;IAC1B,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,UAAU,mBAAmB;IAC5B,IAAI,EAAE,oBAAoB,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,UAAU,yBAAyB;IAClC,IAAI,EAAE,0BAA0B,CAAC;CACjC;AAED;;GAEG;AACH,UAAU,uBAAuB;IAChC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,UAAU,yBAAyB;IAClC,IAAI,EAAE,0BAA0B,CAAC;CACjC;AAED;;;;GAIG;AACH,UAAU,oBAAoB;IAC7B,IAAI,EAAE,qBAAqB,CAAC;CAC5B;AAED;;GAEG;AACH,UAAU,sBAAsB;IAC/B,IAAI,EAAE,uBAAuB,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,UAAU,oBAAoB;IAC7B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,UAAU,WAAW;IACpB,IAAI,EAAE,YAAY,CAAC;CACnB;AAED;;GAEG;AACH,UAAU,iBAAiB;IAC1B,IAAI,EAAE,kBAAkB,CAAC;CACzB;AAED;;;GAGG;AACH,UAAU,sBAAsB;IAC/B,IAAI,EAAE,uBAAuB,CAAC;CAC9B;AAED;;;;GAIG;AACH,UAAU,YAAY;IACrB,IAAI,EAAE,aAAa,CAAC;CACpB;AAED;;GAEG;AACH,UAAU,kBAAkB;IAC3B,IAAI,EAAE,mBAAmB,CAAC;CAC1B;AAED;;GAEG;AACH,UAAU,uBAAuB;IAChC,IAAI,EAAE,wBAAwB,CAAC;CAC/B;AAED;;GAEG;AACH,UAAU,uBAAuB;IAChC,IAAI,EAAE,wBAAwB,CAAC;CAC/B;AAED;;GAEG;AACH,UAAU,YAAY;IACrB,IAAI,EAAE,aAAa,CAAC;CACpB;AAED;;;;GAIG;AACH,UAAU,WAAW;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,UAAU,YAAY;IACrB,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,UAAU,cAAc;IACvB,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,UAAU,kBAAkB;IAC3B,IAAI,EAAE,mBAAmB,CAAC;CAC1B;AAED;;GAEG;AACH,UAAU,eAAe;IACxB,IAAI,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;GAIG;AACH,UAAU,qBAAqB;IAC9B,IAAI,EAAE,sBAAsB,CAAC;CAC7B;AAED;;GAEG;AACH,UAAU,aAAa;IACtB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,UAAU,sBAAsB;IAC/B,IAAI,EAAE,uBAAuB,CAAC;CAC9B"}
@@ -0,0 +1,208 @@
1
+ import { type TRange, type TReference, type TTextPos } from './types';
2
+ /**
3
+ * Represents a stream of characters for parsing XML-like content.
4
+ *
5
+ * This implementation uses UTF-16 code units, whereas the Rust implementation is based on bytes (UTF-8).
6
+ * This difference in encoding affects how characters are handled and parsed.
7
+ * For more details, refer to the FAQ.
8
+ */
9
+ export declare class XmlStream {
10
+ private _text;
11
+ private _pos;
12
+ private _end;
13
+ constructor(text: string, pos?: number);
14
+ /**
15
+ * Creates a clone of the current stream.
16
+ *
17
+ * @returns A new instance of XmlStream with the same state.
18
+ */
19
+ clone(): XmlStream;
20
+ /**
21
+ * Gets the current position in the stream.
22
+ *
23
+ * @returns The current position.
24
+ */
25
+ getPos(): number;
26
+ /**
27
+ * Checks if the stream is at the end.
28
+ *
29
+ * @returns True if at the end, false otherwise.
30
+ */
31
+ atEnd(): boolean;
32
+ /**
33
+ * Gets the current code unit in the stream.
34
+ *
35
+ * @returns The current code unit.
36
+ * @throws XmlError if at the end of the stream.
37
+ */
38
+ currCodeUnit(): number;
39
+ /**
40
+ * Gets the current code unit without checking for the end.
41
+ *
42
+ * @returns The current code unit.
43
+ */
44
+ currCodeUnitUnchecked(): number;
45
+ /**
46
+ * Gets the next code unit in the stream.
47
+ *
48
+ * @returns The next code unit.
49
+ * @throws XmlError if at the end of the stream.
50
+ */
51
+ nextCodeUnit(): number;
52
+ /**
53
+ * Advances the stream position by the specified number of characters.
54
+ *
55
+ * @param n - The number of characters to advance.
56
+ */
57
+ advance(n: number): void;
58
+ /**
59
+ * Checks if the stream starts with the given text.
60
+ *
61
+ * @param text - The text to check.
62
+ * @returns True if the stream starts with the text, false otherwise.
63
+ */
64
+ startsWith(text: string): boolean;
65
+ /**
66
+ * Consumes a specific code unit (character) from the stream.
67
+ *
68
+ * @param codeUnit - The code unit to consume.
69
+ * @throws XmlError if the current code unit doesn't match or if at the end.
70
+ */
71
+ consumeCodeUnit(codeUnit: number): void;
72
+ /**
73
+ * Tries to consume a specific code unit (character) from the stream.
74
+ * Unlike `consumeCodeUnit`, it will not throw any errors.
75
+ *
76
+ * @param codeUnit - The code unit to consume.
77
+ * @returns True if the code unit was consumed, false otherwise.
78
+ */
79
+ tryConsumeCodeUnit(codeUnit: number): boolean;
80
+ /**
81
+ * Skips a specific string in the stream.
82
+ *
83
+ * @param text - The string to skip.
84
+ * @throws XmlError if the stream doesn't start with the given string.
85
+ */
86
+ skipString(text: string): void;
87
+ /**
88
+ * Consumes code units that satisfy a predicate function.
89
+ *
90
+ * @param predicate - The function to test each code unit.
91
+ * @returns The consumed string.
92
+ */
93
+ consumeCodeUnitsWhile(predicate: (codeUnit: number) => boolean): string;
94
+ /**
95
+ * Skips code units that satisfy a predicate function.
96
+ *
97
+ * @param predicate - The function to test each code unit.
98
+ */
99
+ skipCodeUnitsWhile(predicate: (codeUnit: number) => boolean): void;
100
+ /**
101
+ * Consumes characters that satisfy a predicate function.
102
+ *
103
+ * @param predicate - The function to test each character.
104
+ * @returns The consumed string.
105
+ * @throws XmlError if a non-XML character is encountered.
106
+ */
107
+ consumeCharsWhile(predicate: (stream: XmlStream, char: string) => boolean): string;
108
+ /**
109
+ * Skips characters that satisfy a predicate function.
110
+ *
111
+ * @param predicate - The function to test each character.
112
+ * @throws XmlError if a non-XML character is encountered.
113
+ */
114
+ skipCharsWhile(predicate: (stream: XmlStream, char: string) => boolean): void;
115
+ /**
116
+ * Slices the text from the given position to the current position.
117
+ *
118
+ * @param pos - The start position.
119
+ * @returns The sliced string.
120
+ */
121
+ sliceBack(pos: number): string;
122
+ /**
123
+ * Creates a range from the given start position to the current position.
124
+ *
125
+ * @param start - The start position.
126
+ * @returns The range object.
127
+ */
128
+ rangeFrom(start: number): TRange;
129
+ /**
130
+ * Skips whitespace characters in the stream.
131
+ */
132
+ skipSpaces(): void;
133
+ /**
134
+ * Checks if the stream starts with a whitespace character.
135
+ *
136
+ * @returns True if it starts with a whitespace, false otherwise.
137
+ */
138
+ startsWithSpace(): boolean;
139
+ /**
140
+ * Consumes whitespace characters in the stream.
141
+ * Like `skipSpaces`, but checks that the first char is actually a space.
142
+ *
143
+ * @throws XmlError if the stream doesn't start with a whitespace or is at the end.
144
+ */
145
+ consumeSpaces(): void;
146
+ /**
147
+ * Tries to consume a reference (entity or character reference).
148
+ * Consumes according to: https://www.w3.org/TR/xml/#NT-Reference
149
+ *
150
+ * @returns The consumed reference or null if not a reference.
151
+ */
152
+ tryConsumeReference(): TReference | null;
153
+ /**
154
+ * Consumes a reference (entity or character reference).
155
+ *
156
+ * @returns The consumed reference or null if not a reference.
157
+ */
158
+ consumeReference(): TReference | null;
159
+ /**
160
+ * Consumes a XML name.
161
+ * Consumes according to: https://www.w3.org/TR/xml/#NT-Name
162
+ *
163
+ * @returns The consumed name.
164
+ * @throws XmlError if an invalid name is encountered.
165
+ */
166
+ consumeName(): string;
167
+ /**
168
+ * Skips a XML name.
169
+ * The same as `consumeName`, but does not return the consumed name.
170
+ * @throws XmlError if an invalid name is encountered.
171
+ */
172
+ skipName(): void;
173
+ /**
174
+ * Consumes a qualified XML name and returns it.
175
+ * Consumes according to: https://www.w3.org/TR/xml-names/#ns-qualnames
176
+ *
177
+ * @returns The prefix and local name as a tuple.
178
+ * @throws XmlError if an invalid qualified XML name is encountered.
179
+ */
180
+ consumeQName(): [string, string];
181
+ /**
182
+ * Consumes an equal sign, surrounded by optional whitespace.
183
+ */
184
+ consumeEq(): void;
185
+ /**
186
+ * Consumes a quote character.
187
+ *
188
+ * @returns The consumed quote character.
189
+ * @throws XmlError if an invalid quote character is encountered.
190
+ */
191
+ consumeQuote(): number;
192
+ /**
193
+ * Calculates the current absolute position.
194
+ * This operation is very expensive. Use only for errors.
195
+ *
196
+ * @returns The current text position.
197
+ */
198
+ genTextPos(): TTextPos;
199
+ /**
200
+ * Calculates an absolute position at the specified position.
201
+ * This operation is very expensive. Use only for errors.
202
+ *
203
+ * @param pos - The position to calculate from.
204
+ * @returns The calculated text position.
205
+ */
206
+ genTextPosFrom(pos: number): TTextPos;
207
+ }
208
+ //# sourceMappingURL=XmlStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlStream.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/XmlStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAyBtE;;;;;;GAMG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;gBAEF,IAAI,EAAE,MAAM,EAAE,GAAG,SAAI;IAMxC;;;;OAIG;IACI,KAAK,IAAI,SAAS;IAIzB;;;;OAIG;IACI,MAAM,IAAI,MAAM;IAIvB;;;;OAIG;IACI,KAAK,IAAI,OAAO;IAIvB;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAO7B;;;;OAIG;IACI,qBAAqB,IAAI,MAAM;IAItC;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAO7B;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;;OAKG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAW9C;;;;;;OAMG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQpD;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOrC;;;;;OAKG;IACI,qBAAqB,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM;IAM9E;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI;IAMzE;;;;;;OAMG;IACI,iBAAiB,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM;IAMzF;;;;;OAKG;IACI,cAAc,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI;IAapF;;;;;OAKG;IACI,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIrC;;;;;OAKG;IACI,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,UAAU,IAAI,IAAI;IAMzB;;;;OAIG;IACI,eAAe,IAAI,OAAO;IAIjC;;;;;OAKG;IACI,aAAa,IAAI,IAAI;IAe5B;;;;;OAKG;IACI,mBAAmB,IAAI,UAAU,GAAG,IAAI;IAiB/C;;;;OAIG;IACI,gBAAgB,IAAI,UAAU,GAAG,IAAI;IA4D5C;;;;;;OAMG;IACI,WAAW,IAAI,MAAM;IAY5B;;;;OAIG;IACI,QAAQ,IAAI,IAAI;IAgBvB;;;;;;OAMG;IACI,YAAY,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAiDvC;;OAEG;IACI,SAAS,IAAI,IAAI;IAMxB;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAY7B;;;;;OAKG;IACI,UAAU,IAAI,QAAQ;IAI7B;;;;;;OAMG;IACI,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;CAc5C"}
@@ -0,0 +1,6 @@
1
+ export * from './tokenizer';
2
+ export * from './types';
3
+ export * from './utils';
4
+ export * from './XmlError';
5
+ export * from './XmlStream';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type TTokenCallback } from './types';
2
+ import { type XmlStream } from './XmlStream';
3
+ /**
4
+ * Parses an XML document.
5
+ *
6
+ * document ::= prolog element Misc*
7
+ *
8
+ * https://www.w3.org/TR/xml/#NT-document
9
+ */
10
+ export declare function parseXmlStream(s: XmlStream, allowDtd: boolean, tokenCallback: TTokenCallback): void;
11
+ //# sourceMappingURL=tokenizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/tokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAe9C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC7B,CAAC,EAAE,SAAS,EACZ,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAgCN"}
@@ -0,0 +1,126 @@
1
+ export type TTokenCallback = (token: TXMLToken) => void;
2
+ /**
3
+ * A Processing Instruction token.
4
+ *
5
+ * \<?target content?\>
6
+ */
7
+ export interface TProcessingInstructionToken {
8
+ type: 'ProcessingInstruction';
9
+ target: string;
10
+ content?: string;
11
+ range: TRange;
12
+ }
13
+ /**
14
+ * A Comment token.
15
+ *
16
+ * \<!-- text --\>
17
+ */
18
+ export interface TCommentToken {
19
+ type: 'Comment';
20
+ text: string;
21
+ range: TRange;
22
+ }
23
+ /**
24
+ * An Entity Declaration token.
25
+ *
26
+ * \<!ENTITY ns_extend "http://test.com"\>
27
+ */
28
+ export interface TEntityDeclarationToken {
29
+ type: 'EntityDeclaration';
30
+ name: string;
31
+ definition: string;
32
+ }
33
+ /**
34
+ * An Element Start token.
35
+ *
36
+ * \<ns:elem
37
+ */
38
+ export interface TElementStartToken {
39
+ type: 'ElementStart';
40
+ prefix: string;
41
+ local: string;
42
+ start: number;
43
+ }
44
+ /**
45
+ * An Attribute token.
46
+ *
47
+ * ns:attr="value"
48
+ */
49
+ export interface TAttributeToken {
50
+ type: 'Attribute';
51
+ range: TRange;
52
+ prefix: string;
53
+ local: string;
54
+ value: string;
55
+ }
56
+ /**
57
+ * An Element End token.
58
+ */
59
+ export interface TElementEndToken {
60
+ type: 'ElementEnd';
61
+ end: TElementEndVariant;
62
+ range: TRange;
63
+ }
64
+ export type TElementEndVariant = {
65
+ type: 'Open';
66
+ } | {
67
+ type: 'Close';
68
+ prefix: string;
69
+ local: string;
70
+ } | {
71
+ type: 'Empty';
72
+ };
73
+ /**
74
+ * A Text token.
75
+ *
76
+ * Contains text between elements including whitespaces.
77
+ * Basically everything between `>` and `<`.
78
+ * Except `]]>`, which is not allowed and will lead to an error.
79
+ */
80
+ export interface TTextToken {
81
+ type: 'Text';
82
+ text: string;
83
+ range: TRange;
84
+ }
85
+ /**
86
+ * A CDATA Section token.
87
+ *
88
+ * \<![CDATA[text]]\>
89
+ */
90
+ export interface TCdataToken {
91
+ type: 'Cdata';
92
+ text: string;
93
+ range: TRange;
94
+ }
95
+ export type TXMLToken = TProcessingInstructionToken | TCommentToken | TEntityDeclarationToken | TElementStartToken | TAttributeToken | TElementEndToken | TTextToken | TCdataToken;
96
+ export interface TRange {
97
+ start: number;
98
+ end: number;
99
+ }
100
+ export interface TTextPos {
101
+ row: number;
102
+ col: number;
103
+ }
104
+ /**
105
+ * Representation of the [Reference](https://www.w3.org/TR/xml/#NT-Reference) value.
106
+ */
107
+ export type TReference =
108
+ /**
109
+ * An entity reference.
110
+ *
111
+ * https://www.w3.org/TR/xml/#NT-EntityRef
112
+ */
113
+ {
114
+ type: 'Char';
115
+ value: string;
116
+ }
117
+ /**
118
+ * A character reference.
119
+ *
120
+ * https://www.w3.org/TR/xml/#NT-CharRef
121
+ */
122
+ | {
123
+ type: 'Entity';
124
+ value: string;
125
+ };
126
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC3C,IAAI,EAAE,uBAAuB,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,cAAc,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,kBAAkB,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,kBAAkB,GAE3B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAEhB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAEhD;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAErB;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,SAAS,GAClB,2BAA2B,GAC3B,aAAa,GACb,uBAAuB,GACvB,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,UAAU,GACV,WAAW,CAAC;AAEf,MAAM,WAAW,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,QAAQ;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,MAAM,UAAU;AACrB;;;;GAIG;AACD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAEjC;;;;GAIG;GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,69 @@
1
+ export declare const HORIZONTAL_TAB = 9;
2
+ export declare const LINE_FEED = 10;
3
+ export declare const CARRIAGE_RETURN = 13;
4
+ export declare const SPACE = 32;
5
+ export declare const EXCLAMATION_MARK = 33;
6
+ export declare const DOUBLE_QUOTE = 34;
7
+ export declare const HASH = 35;
8
+ export declare const PERCENT = 37;
9
+ export declare const AMPERSAND = 38;
10
+ export declare const SINGLE_QUOTE = 39;
11
+ export declare const HYPHEN = 45;
12
+ export declare const PERIOD = 46;
13
+ export declare const SLASH = 47;
14
+ export declare const ZERO = 48;
15
+ export declare const NINE = 57;
16
+ export declare const COLON = 58;
17
+ export declare const SEMICOLON = 59;
18
+ export declare const LESS_THAN = 60;
19
+ export declare const EQUALS = 61;
20
+ export declare const GREATER_THAN = 62;
21
+ export declare const QUESTION_MARK = 63;
22
+ export declare const UPPERCASE_A = 65;
23
+ export declare const UPPERCASE_F = 70;
24
+ export declare const UPPERCASE_P = 80;
25
+ export declare const UPPERCASE_S = 83;
26
+ export declare const UPPERCASE_Z = 90;
27
+ export declare const OPEN_BRACKET = 91;
28
+ export declare const UNDERSCORE = 95;
29
+ export declare const LOWERCASE_A = 97;
30
+ export declare const LOWERCASE_F = 102;
31
+ export declare const LOWERCASE_X = 120;
32
+ export declare const LOWERCASE_Z = 122;
33
+ export declare function isAsciiDigit(byte: number): boolean;
34
+ /**
35
+ * Checks if the unicode code point (character) is within the name start char range.
36
+ *
37
+ * @param codePoint - The character to check.
38
+ * @returns True if the character is a valid XML name start character, false otherwise.
39
+ */
40
+ export declare function isXmlNameStart(codePoint: number | undefined): boolean;
41
+ /**
42
+ * Checks if the unicode code point (character) is within the XML name char range.
43
+ *
44
+ * @param codePoint - The character to check.
45
+ * @returns True if the character is a valid XML name character, false otherwise.
46
+ */
47
+ export declare function isXmlName(codePoint: number | undefined): boolean;
48
+ /**
49
+ * Checks if the unicode code point (character) is within the XML char range.
50
+ *
51
+ * @param codePoint - The character to check.
52
+ * @returns True if the character is a valid XML character, false otherwise.
53
+ */
54
+ export declare function isXmlChar(codePoint: number | undefined): boolean;
55
+ /**
56
+ * Checks if the character is an XML space.
57
+ *
58
+ * @param byte - The byte to check.
59
+ * @returns True if the byte is a valid XML space, false otherwise.
60
+ */
61
+ export declare function isXmlSpaceByte(byte: number): boolean;
62
+ /**
63
+ * Checks if the byte is within the ASCII char range.
64
+ *
65
+ * @param byte - The byte to check.
66
+ * @returns True if the byte is a valid ASCII XML name character, false otherwise.
67
+ */
68
+ export declare function isXmlNameByte(byte: number): boolean;
69
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,KAAK,KAAK,CAAC;AACxB,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,IAAI,KAAK,CAAC;AACvB,eAAO,MAAM,OAAO,KAAK,CAAC;AAC1B,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,KAAK,KAAK,CAAC;AACxB,eAAO,MAAM,IAAI,KAAK,CAAC;AACvB,eAAO,MAAM,IAAI,KAAK,CAAC;AACvB,eAAO,MAAM,KAAK,KAAK,CAAC;AACxB,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CA6BrE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CA2BhE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAUhE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIpD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUnD"}
@@ -0,0 +1,8 @@
1
+ export declare function xmlToObject(xmlString: string, allowDtd?: boolean): TXMLNode;
2
+ export interface TXMLNode {
3
+ tagName: string;
4
+ attributes: Record<string, string>;
5
+ children: (TXMLNode | string)[];
6
+ }
7
+ export declare function getTagName(local: string, prefix: string): string;
8
+ //# sourceMappingURL=xml-to-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-to-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-object.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,QAAQ,CAmDzE;AAED,MAAM,WAAW,QAAQ;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;CAChC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "xml-tokenizer",
3
+ "version": "0.0.2",
4
+ "description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
5
+ "private": false,
6
+ "source": "./src/index.ts",
7
+ "main": "./dist/cjs/index.js",
8
+ "module": "./dist/esm/index.js",
9
+ "types": "./dist/types/index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/builder-group/monorepo.git"
13
+ },
14
+ "keywords": [],
15
+ "author": "@bennobuilder",
16
+ "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/builder-group/monorepo/issues"
19
+ },
20
+ "homepage": "https://builder.group/?source=package-json",
21
+ "devDependencies": {
22
+ "@types/node": "^20.14.10",
23
+ "@types/sax": "^1.2.7",
24
+ "@types/xml2js": "^0.4.14",
25
+ "fast-xml-parser": "^4.4.1",
26
+ "roxmltree": "^0.0.9",
27
+ "sax": "^1.4.1",
28
+ "saxen": "^10.0.0",
29
+ "txml": "^5.1.1",
30
+ "xml2js": "^0.6.2",
31
+ "@blgc/config": "0.0.16"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md"
36
+ ],
37
+ "size-limit": [
38
+ {
39
+ "path": "dist/esm/index.js"
40
+ }
41
+ ],
42
+ "scripts": {
43
+ "build": "shx rm -rf dist && ../../scripts/cli.sh bundle",
44
+ "build:dev": "shx rm -rf dist && ../../scripts/cli.sh bundle --target=dev",
45
+ "start:dev": "tsc -w",
46
+ "lint": "eslint --ext .js,.ts src/",
47
+ "clean": "shx rm -rf dist && shx rm -rf node_modules && shx rm -rf .turbo",
48
+ "install:clean": "pnpm run clean && pnpm install",
49
+ "test": "vitest run",
50
+ "bench": "vitest bench",
51
+ "update:latest": "pnpm update --latest",
52
+ "publish:patch": "pnpm build && pnpm version patch && pnpm publish --no-git-checks --access=public",
53
+ "size": "size-limit --why"
54
+ }
55
+ }