xml-tokenizer 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  > Status: Experimental
21
21
 
22
- `xml-tokenizer` is a straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism.
22
+ `xml-tokenizer` is a straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism.
23
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 as WASM.
24
24
 
25
25
  - **XML Token Stream**: Processes XML documents as a stream, emitting tokens on the fly similar to the [`SAX`](https://www.baeldung.com/java-sax-parser) approach
@@ -46,38 +46,42 @@ My goal was to develop an efficient & flexible alternative by porting [roxmltree
46
46
  ## 📖 Usage
47
47
 
48
48
  ```ts
49
- import { xmlToObject, xmlToSimplifiedObject, tokenize, select } from 'xml-tokenizer';
49
+ import { select, tokenize, xmlToObject, xmlToSimplifiedObject } from 'xml-tokenizer';
50
50
 
51
51
  // Parse XML to Javascript object without information lost (uses `tokenize` under the hood)
52
- const xmlObject = xmlToObject("<p>Hello World</p>");
52
+ const xmlObject = xmlToObject('<p>Hello World</p>');
53
53
 
54
54
  // Or, parse XML to easy to queryable Javascript object
55
- const simplifiedXmlObject = xmlToSimplifiedObject("<p>Hello World</p>");
56
-
57
- // Or, parse XML to a stream of tokens
58
- tokenize("<p>Hello World</p>", false, (token) => {
59
- switch (token.type) {
60
- case 'ElementStart':
61
- console.log('Start of element:', token);
62
- break;
63
- case 'Text':
64
- console.log('Text content:', token.text);
65
- break;
66
- // Handle other token types as needed
67
- default:
68
- console.log('Token:', token);
69
- }
55
+ const simplifiedXmlObject = xmlToSimplifiedObject('<p>Hello World</p>');
56
+
57
+ // Or, parse XML to a stream of tokens
58
+ tokenize('<p>Hello World</p>', (token) => {
59
+ switch (token.type) {
60
+ case 'ElementStart':
61
+ console.log('Start of element:', token);
62
+ break;
63
+ case 'Text':
64
+ console.log('Text content:', token.text);
65
+ break;
66
+ // Handle other token types as needed
67
+ default:
68
+ console.log('Token:', token);
69
+ }
70
70
  });
71
71
 
72
72
  // Or, stream only a selection of tokens
73
- select(xml, [
74
- [
75
- { axis: 'child', local: 'bookstore' },
76
- { axis: 'child', local: 'book', attributes: [{ local: 'category', value: 'COOKING' }] }
77
- ]
78
- ], (selectedToken) => {
79
- // Handle selected token
80
- });
73
+ select(
74
+ xml,
75
+ [
76
+ [
77
+ { axis: 'child', local: 'bookstore' },
78
+ { axis: 'child', local: 'book', attributes: [{ local: 'category', value: 'COOKING' }] }
79
+ ]
80
+ ],
81
+ (selectedToken) => {
82
+ // Handle selected token
83
+ }
84
+ );
81
85
  ```
82
86
 
83
87
  ### Token Types
@@ -100,35 +104,37 @@ The following token types are supported:
100
104
 
101
105
  - **Attribute Value Handling:**
102
106
  - **XML 1.0:** Attributes must be explicitly assigned a value in the format `Name="Value"`. An attribute without a value is not valid XML.
103
- - **Parser Behavior:** Attributes without an explicit value are interpreted as `true` (e.g., `<element attribute/>` is parsed as `attribute="true"`).
107
+ - **Parser Behavior:** Attributes without an explicit value are interpreted as `true` (e.g., `<element attribute/>` is parsed as `attribute="true"`).
104
108
  - **Reason**: This behavior aligns with HTML-style parsing, which was necessary to handle HTML attributes without explicit values.
105
109
 
106
110
  ## 🚀 Benchmark
107
111
 
108
- The performance of `xml-tokenizer` was benchmarked against other popular XML parsers. These tests focus on XML to object conversion and node counting. Interestingly, the version of `xml-tokenizer` imported directly from npm performed significantly better. The reason for this discrepancy is unclear, but the results seem accurate based on external testing.
112
+ The performance of `xml-tokenizer` was benchmarked against other popular XML parsers. These tests focus on XML to object conversion and node counting. Interestingly, the version of `xml-tokenizer` imported directly from npm performed significantly better. The reason for this discrepancy is unclear, but the results seem accurate based on external testing.
109
113
 
110
114
  ### XML to Object Conversion
111
115
 
112
- | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
113
- |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
114
- | xml-tokenizer | 46.87 | 19.47 | 24.57 | 21.33 | ±2.06% |
115
- | xml-tokenizer (dist)| 53.70 | 17.31 | 25.20 | 18.62 | ±3.28% |
116
- | xml-tokenizer (npm) | 163.00 | 5.03 | 8.50 | 6.13 | ±2.32% |
117
- | fast-xml-parser | 66.00 | 14.01 | 20.73 | 15.15 | ±3.34% |
118
- | txml | 234.52 | 3.38 | 7.61 | 4.26 | ±4.00% |
119
- | xml2js | 36.21 | 25.58 | 37.28 | 27.61 | ±4.39% |
116
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
117
+ | -------------------- | ------------------------------- | ------------- | ------------- | -------------- | ------------------------------ |
118
+ | xml-tokenizer | 46.87 | 19.47 | 24.57 | 21.33 | ±2.06% |
119
+ | xml-tokenizer (dist) | 53.70 | 17.31 | 25.20 | 18.62 | ±3.28% |
120
+ | xml-tokenizer (npm) | 163.00 | 5.03 | 8.50 | 6.13 | ±2.32% |
121
+ | fast-xml-parser | 66.00 | 14.01 | 20.73 | 15.15 | ±3.34% |
122
+ | txml | 234.52 | 3.38 | 7.61 | 4.26 | ±4.00% |
123
+ | xml2js | 36.21 | 25.58 | 37.28 | 27.61 | ±4.39% |
120
124
 
121
125
  ### Node Counting
122
126
 
123
127
  | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
124
- |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
128
+ | ------------------- | ------------------------------- | ------------- | ------------- | -------------- | ------------------------------ |
125
129
  | xml-tokenizer | 53.03 | 18.30 | 19.45 | 18.86 | ±0.81% |
126
130
  | xml-tokenizer (npm) | 166.61 | 5.62 | 7.16 | 6.00 | ±0.88% |
127
131
  | saxen | 500.99 | 1.83 | 4.79 | 2.00 | ±1.52% |
128
132
  | sax | 64.44 | 14.96 | 16.34 | 15.52 | ±0.67% |
129
133
 
130
134
  ### Running the Benchmarks
135
+
131
136
  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:
137
+
132
138
  ```bash
133
139
  pnpm run bench
134
140
  ```
@@ -143,11 +149,11 @@ Calling a TypeScript function from Rust on every token event (`wasmMix` benchmar
143
149
 
144
150
  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)).
145
151
 
146
- | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
147
- |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
148
- | roxmltree:text | 67.12 | 14.33 | 83.29 | 80.08 | ±1.27% |
149
- | roxmltree:wasmMix | 28.17 | 34.83 | 36.71 | 35.49 | ±0.91% |
150
- | roxmltree:wasm | 109.30 | 8.30 | 13.16 | 9.15 | ±3.31% |
152
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
153
+ | ----------------- | ------------------------------- | ------------- | ------------- | -------------- | ------------------------------ |
154
+ | roxmltree:text | 67.12 | 14.33 | 83.29 | 80.08 | ±1.27% |
155
+ | roxmltree:wasmMix | 28.17 | 34.83 | 36.71 | 35.49 | ±0.91% |
156
+ | roxmltree:wasm | 109.30 | 8.30 | 13.16 | 9.15 | ±3.31% |
151
157
 
152
158
  ### Why ported `tokenizer.rs` to TypeScript?
153
159
 
@@ -159,16 +165,16 @@ We removed the byte-based implementation to enhance maintainability and because
159
165
 
160
166
  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.
161
167
 
162
- | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
163
- |---------------------|---------------------------------|---------------|---------------|----------------|--------------------------------|
164
- | roxmltree:text | 67.12 | 14.33 | 83.29 | 80.08 | ±1.27% |
165
- | roxmltree:byte | 12.48 | 78.65 | 16.45 | 14.90 | ±1.15% |
168
+ | Parser | Operations per Second (ops/sec) | Min Time (ms) | Max Time (ms) | Mean Time (ms) | Relative Margin of Error (rme) |
169
+ | -------------- | ------------------------------- | ------------- | ------------- | -------------- | ------------------------------ |
170
+ | roxmltree:text | 67.12 | 14.33 | 83.29 | 80.08 | ±1.27% |
171
+ | roxmltree:byte | 12.48 | 78.65 | 16.45 | 14.90 | ±1.15% |
166
172
 
167
173
  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)).
168
174
 
169
175
  ### Why not use a Generator?
170
176
 
171
- While generators can improve developer experience, they introduce significant performance overhead. Our benchmarks show that using a generator dramatically increases the execution time compared to the callback approach. Given our focus on performance, we chose to maintain the callback implementation.
177
+ While generators can improve developer experience, they introduce significant performance overhead. Our benchmarks show that using a generator dramatically increases the execution time compared to the callback approach. Given our focus on performance, we chose to maintain the callback implementation.
172
178
 
173
179
  See [Generator vs Iterator vs Callback](https://observablehq.com/@domoritz/yield-vs-iterator-vs-callback) for more details.
174
180
 
@@ -190,8 +196,8 @@ See [Generator vs Iterator vs Callback](https://observablehq.com/@domoritz/yield
190
196
 
191
197
  [Benchmark implementation in Vanilla Profiler](https://github.com/builder-group/monorepo/tree/develop/examples/xml-tokenizer/vanilla/profiler)
192
198
 
193
-
194
199
  ## 💡 Resources
200
+
195
201
  - [How I developed the fastest XML parser](https://tnickel.de/2020/08/30/2020-08-how-the-fastest-xml-parser-is-build/)
196
202
  - [txml](https://github.com/TobiasNickel/tXml)
197
- - [roxmltree](https://github.com/RazrFalcon/roxmltree)
203
+ - [roxmltree](https://github.com/RazrFalcon/roxmltree)
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var A=require("./selector/select.js"),o=require("./selector/TokenSelector.js"),r=require("./selector/TokenSelectState.js"),T=require("./selector/TokenSelectStateMachine.js"),R=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),S=require("./tokenizer/tokenize.js"),E=require("./tokenizer/utils.js"),l=require("./tokenizer/XmlError.js"),O=require("./tokenizer/XmlStream.js"),a=require("./tokens-to-xml.js"),t=require("./xml-to-object.js"),i=require("./xml-to-simplified-object.js");exports.select=A.select,exports.TokenSelector=o.TokenSelector,exports.EToCacheNodeProps=r.EToCacheNodeProps,exports.ETokenMatchCriteria=r.ETokenMatchCriteria,exports.TokenSelectState=r.TokenSelectState,exports.TokenSelectStateMachine=T.TokenSelectStateMachine,exports.tokenToXml=R.tokenToXml,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.tokenize=S.tokenize,exports.tokenizeXmlStream=S.tokenizeXmlStream,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=l.XmlError,exports.XmlStream=O.XmlStream,exports.tokensToXml=a.tokensToXml,exports.processTokenForObject=t.processTokenForObject,exports.xmlToObject=t.xmlToObject,exports.processTokenForSimplifiedObject=i.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=i.xmlToSimplifiedObject;
1
+ "use strict";var i=require("./selector/select.js"),R=require("./selector/TokenSelector.js"),S=require("./selector/TokenSelectState.js"),o=require("./selector/TokenSelectStateMachine.js"),T=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),r=require("./tokenizer/tokenize.js"),E=require("./tokenizer/utils.js"),C=require("./tokenizer/XmlError.js"),O=require("./tokenizer/XmlStream.js"),_=require("./tokens-to-xml.js"),A=require("./xml-to-object.js"),t=require("./xml-to-simplified-object.js");exports.select=i.select,exports.TokenSelector=R.TokenSelector,exports.EToCacheNodeProps=S.EToCacheNodeProps,exports.ETokenMatchCriteria=S.ETokenMatchCriteria,exports.TokenSelectState=S.TokenSelectState,exports.TokenSelectStateMachine=o.TokenSelectStateMachine,exports.tokenToXml=T.tokenToXml,exports.AMPERSAND=e.AMPERSAND,exports.CARRIAGE_RETURN=e.CARRIAGE_RETURN,exports.CLOSE_CURLY_BRACKET=e.CLOSE_CURLY_BRACKET,exports.CLOSE_SQUARE_BRACKET=e.CLOSE_SQUARE_BRACKET,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_CURLY_BRACKET=e.OPEN_CURLY_BRACKET,exports.OPEN_SQUARE_BRACKET=e.OPEN_SQUARE_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.tokenize=r.tokenize,exports.tokenizeXmlStream=r.tokenizeXmlStream,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=C.XmlError,exports.XmlStream=O.XmlStream,exports.tokensToXml=_.tokensToXml,exports.processTokenForObject=A.processTokenForObject,exports.xmlToObject=A.xmlToObject,exports.processTokenForSimplifiedObject=t.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=t.xmlToSimplifiedObject;
@@ -1 +1 @@
1
- "use strict";var i=require("../tokenizer/tokenize.js"),k=require("./TokenSelector.js");function l(e,t,n){const o=new k.TokenSelector(t);i.tokenize(e,!1,r=>{o.pipeToken(r,c=>{n(c)})})}exports.select=l;
1
+ "use strict";var i=require("../tokenizer/tokenize.js"),k=require("./TokenSelector.js");function s(e,n,t){const o=new k.TokenSelector(n);i.tokenize(e,r=>{o.pipeToken(r,c=>{t(c)})})}exports.select=s;
@@ -1 +1 @@
1
- "use strict";var r=require("./ascii-constants.js"),h=require("./utils.js"),o=require("./XmlError.js"),m=Object.defineProperty,d=(a,t,e)=>t in a?m(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,c=(a,t,e)=>d(a,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 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}goTo(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||!h.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&&h.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(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(r.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(r.HASH)){let e,i;this.tryConsumeCodeUnit(r.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(s=>s>=r.ZERO&&s<=r.NINE||s>=r.UPPERCASE_A&&s<=r.UPPERCASE_F||s>=r.LOWERCASE_A&&s<=r.LOWERCASE_F),i=16):(e=this.consumeCodeUnitsWhile(s=>h.isAsciiDigit(s)),i=10);const n=parseInt(e,i);isNaN(n)||!h.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(r.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(!h.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!h.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let n=null;for(;this._pos<this._end;){const u=this.currCodeUnitUnchecked();if(u===r.COLON)if(n==null)n=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i));else if(h.isXmlName(u))this._pos+=1;else break}let s,l;if(n!=null?(s=this._text.slice(i,n),l=this.sliceBack(n+1)):(s="",l=this.sliceBack(i)),s.length>0&&!h.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i));if(l.length>0){if(!h.isXmlNameStart((e=l[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i));return[s,l]}consumeQuote(){const t=this.currCodeUnit();if(t===r.SINGLE_QUOTE||t===r.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 i=1,n=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===r.LINE_FEED?(i++,n=1):n++;return{row:i,col:n}}}exports.XmlStream=p;
1
+ "use strict";var o=require("./ascii-constants.js"),a=require("./utils.js"),n=require("./XmlError.js"),_=Object.defineProperty,m=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,p=(h,t,e)=>t in h?_(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,E=(h,t)=>{for(var e in t||(t={}))C.call(t,e)&&p(h,e,t[e]);if(m)for(var e of m(t))f.call(t,e)&&p(h,e,t[e]);return h},l=(h,t,e)=>p(h,typeof t!="symbol"?t+"":t,e);class u{constructor(t,e={}){l(this,"_text"),l(this,"_pos"),l(this,"_end"),l(this,"config");const{pos:i=0,strict:r=!0,allowDtd:s=!0}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strict:r,allowDtd:s}}clone(){return new u(this._text,E({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new n.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 n.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new n.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!a.isXmlChar(this.currCodeUnitUnchecked()))throw new n.XmlError({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}skipString(t){if(!this.startsWith(t))throw new n.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}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&&a.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new n.XmlError({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(o.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(o.HASH)){let e,i;this.tryConsumeCodeUnit(o.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(s=>s>=o.ZERO&&s<=o.NINE||s>=o.UPPERCASE_A&&s<=o.UPPERCASE_F||s>=o.LOWERCASE_A&&s<=o.LOWERCASE_F),i=16):(e=this.consumeCodeUnitsWhile(s=>a.isAsciiDigit(s)),i=10);const r=parseInt(e,i);isNaN(r)||!a.isXmlChar(r)?t=null:t={type:"Char",value:String.fromCodePoint(r)}}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(o.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new n.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(!a.isXmlNameStart(e))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!a.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let r=null;for(;this._pos<this._end;){const d=this.currCodeUnitUnchecked();if(d===o.COLON)if(r==null)r=this._pos,this._pos+=1;else throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));else if(a.isXmlName(d))this._pos+=1;else break}let s,c;if(r!=null?(s=this._text.slice(i,r),c=this.sliceBack(r+1)):(s="",c=this.sliceBack(i)),s.length>0&&!a.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));if(c.length>0){if(!a.isXmlNameStart((e=c[0])==null?void 0:e.codePointAt(0)))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i))}else throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));return[s,c]}consumeQuote(){const t=this.currCodeUnit();if(t===o.SINGLE_QUOTE||t===o.DOUBLE_QUOTE)return this._pos+=1,t;throw new n.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 i=1,r=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===o.LINE_FEED?(i++,r=1):r++;return{row:i,col:r}}}exports.XmlStream=u;
@@ -1 +1 @@
1
- "use strict";const E=9,A=10,R=13,S=32,O=33,_=34,C=35,N=37,P=38,L=39,T=45,U=46,I=47,H=48,D=57,M=58,Q=59,W=60,Z=61,B=62,F=63,G=65,K=70,X=80,s=83,t=90,Y=91,c=95,e=97,i=102,n=120,o=122;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;
1
+ "use strict";const E=9,A=10,R=13,S=32,_=33,C=34,O=35,L=37,N=38,P=39,U=45,T=46,I=47,H=48,B=57,K=58,Q=59,D=60,M=61,W=62,Z=63,F=65,G=70,Y=80,X=83,s=90,t=91,c=93,e=95,i=97,n=102,o=120,r=122,u=123,a=125;exports.AMPERSAND=38,exports.CARRIAGE_RETURN=13,exports.CLOSE_CURLY_BRACKET=125,exports.CLOSE_SQUARE_BRACKET=93,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_CURLY_BRACKET=123,exports.OPEN_SQUARE_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;
@@ -1 +1 @@
1
- "use strict";var r=require("./ascii-constants.js"),i=require("./XmlError.js"),N=require("./XmlStream.js");const R="\uFEFF",g="<?xml ",S="?>",X="<!ENTITY",I="<!ELEMENT",_="<!ATTLIST",F="<!NOTATION",H="<!DOCTYPE",C="<?",k="?>",u="<!--",U="-->",L="<![CDATA[",E="]]>",G="NDATA",w="PUBLIC",Q="SYSTEM",D="version",O="encoding",b="standalone";function B(t,n,s){A(new N.XmlStream(t),n,s)}function A(t,n,s){if(t.startsWith(R)&&t.advance(1),t.startsWith(g)&&M(t),h(t,s),t.skipSpaces(),t.startsWith(H)){if(!n)throw new i.XmlError({type:"DtdDetected"});q(t,s),h(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===r.LESS_THAN&&W(t,s),h(t,s),!t.atEnd())throw new i.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function h(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(u))f(t,n);else if(t.startsWith(C))T(t,n);else break}function M(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(S)&&!s.atEnd())throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(D))throw new i.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());m(t),n(t),t.startsWith(O)&&(m(t),n(t)),t.startsWith(b)&&m(t),t.skipSpaces(),t.skipString(S)}function f(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCharsWhile((o,a)=>!(a==="-"&&o.startsWith(U)));if(t.skipString(U),e.includes("--")||e.endsWith("-"))throw new i.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)})}function T(t,n){if(t.startsWith(g))throw new i.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const o=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith(k)));t.skipString(k),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)})}function q(t,n){const s=t.getPos();if(z(t),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(X))Y(t,n);else if(t.startsWith(u))f(t,n);else if(t.startsWith(C))T(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(I)||t.startsWith(_)||t.startsWith(F))try{j(t)}catch(e){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 z(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),P(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 P(t){if(t.startsWith(Q)||t.startsWith(w)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const e=t.consumeQuote();if(t.consumeCodeUnitsWhile(o=>o!==e),t.consumeCodeUnit(e),s===w){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==o),t.consumeCodeUnit(o)}return!0}return!1}function Y(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(r.PERCENT);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=K(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o}),t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN)}function K(t,n){const s=t.currCodeUnit();if(s===r.DOUBLE_QUOTE||s===r.SINGLE_QUOTE){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const a=t.sliceBack(o);return t.consumeCodeUnit(e),a}else if(s===r.UPPERCASE_S||s===r.UPPERCASE_P){if(P(t))return n&&(t.skipSpaces(),t.startsWith(G)&&(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 j(t){t.skipCodeUnitsWhile(n=>n!==r.GREATER_THAN),t.consumeCodeUnit(r.GREATER_THAN)}function W(t,n){const s=t.getPos();t.advance(1);const[e,o]=t.consumeQName();n({type:"ElementStart",prefix:e,local:o,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,y,v]=m(t),x=t.getPos();n({type:"Attribute",range:{start:d,end:x},prefix:p,local:y,value:v})}}a&&J(t,n)}function m(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(r.EQUALS)){t.skipSpaces();const a=t.consumeQuote(),c=String.fromCharCode(a);e=t.consumeCharsWhile((d,l)=>l!==c&&l!=="<"),t.consumeCodeUnit(a)}else t.goTo(o),e="true";return[n,s,e]}function J(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===r.LESS_THAN){const s=t.nextCodeUnit();if(s===r.EXCLAMATION_MARK)if(t.startsWith(u))f(t,n);else if(t.startsWith(L))V(t,n);else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===r.QUESTION_MARK)T(t,n);else if(s===r.SLASH){Z(t,n);break}else W(t,n)}else $(t,n)}function V(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith(E)));t.skipString(E);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o})}function Z(t,n){const s=t.getPos();t.advance(2);const[e,o]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:o},range:a})}function $(t,n){const s=t.getPos(),e=t.consumeCharsWhile((o,a)=>a!=="<");if(e.includes(E))throw new i.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:e,range:t.rangeFrom(s)})}exports.tokenize=B,exports.tokenizeXmlStream=A;
1
+ "use strict";var o=require("./ascii-constants.js"),a=require("./XmlError.js"),R=require("./XmlStream.js");const _="\uFEFF",g="<?xml ",C="?>",I="<!ENTITY",X="<!ELEMENT",H="<!ATTLIST",L="<!NOTATION",F="<!DOCTYPE",U="<?",k="?>",m="<!--",A="-->",Q="<![CDATA[",E="]]>",D="NDATA",w="PUBLIC",O="SYSTEM",G="version",b="encoding",B="standalone";function M(t,n,s={}){P(new R.XmlStream(t,s),n)}function P(t,n){if(t.startsWith(_)&&t.advance(1),t.startsWith(g)&&K(t),l(t,n),t.skipSpaces(),t.startsWith(F)){if(!t.config.allowDtd)throw new a.XmlError({type:"DtdDetected"});z(t,n),l(t,n)}if(t.skipSpaces(),t.config.strict){if(!t.atEnd()&&t.currCodeUnit()===o.LESS_THAN&&S(t,n),l(t,n),!t.atEnd())throw new a.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===o.LESS_THAN?S(t,n):y(t,n),l(t,n)}function l(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(m))f(t,n);else if(t.startsWith(U))h(t,n);else break}function K(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(C)&&!s.atEnd())throw new a.XmlError({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(G))throw new a.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());p(t),n(t),t.startsWith(b)&&(p(t),n(t)),t.startsWith(B)&&p(t),t.skipSpaces(),t.skipString(C)}function f(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCodeUnitsWhile((r,i)=>!(r===o.HYPHEN&&i.startsWith(A)));if(t.skipString(A),e.includes("--")||e.endsWith("-"))throw new a.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)})}function h(t,n){if(t.startsWith(g))throw new a.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const r=t.consumeCodeUnitsWhile((i,c)=>!(i===o.QUESTION_MARK&&c.startsWith(k)));t.skipString(k),n({type:"ProcessingInstruction",target:e,content:r.length===0?void 0:r,range:t.rangeFrom(s)})}function z(t,n){const s=t.getPos();if(Y(t),t.skipSpaces(),t.currCodeUnit()===o.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(I))q(t,n);else if(t.startsWith(m))f(t,n);else if(t.startsWith(U))h(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===o.GREATER_THAN){t.advance(1);break}else throw new a.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(X)||t.startsWith(H)||t.startsWith(L))try{J(t)}catch(e){throw new a.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new a.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function Y(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),W(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==o.OPEN_SQUARE_BRACKET&&n!==o.GREATER_THAN)throw new a.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function W(t){if(t.startsWith(O)||t.startsWith(w)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const e=t.consumeQuote();if(t.consumeCodeUnitsWhile(r=>r!==e),t.consumeCodeUnit(e),s===w){t.consumeSpaces();const r=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==r),t.consumeCodeUnit(r)}return!0}return!1}function q(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(o.PERCENT);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const r=j(t,s);r!==null&&n({type:"EntityDeclaration",name:e,definition:r}),t.skipSpaces(),t.consumeCodeUnit(o.GREATER_THAN)}function j(t,n){const s=t.currCodeUnit();if(s===o.DOUBLE_QUOTE||s===o.SINGLE_QUOTE){const e=t.consumeQuote(),r=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const i=t.sliceBack(r);return t.consumeCodeUnit(e),i}else if(s===o.UPPERCASE_S||s===o.UPPERCASE_P){if(W(t))return n&&(t.skipSpaces(),t.startsWith(D)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new a.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function J(t){t.skipCodeUnitsWhile(n=>n!==o.GREATER_THAN),t.consumeCodeUnit(o.GREATER_THAN)}function S(t,n){const s=t.getPos();t.advance(1);const[e,r]=t.consumeQName();n({type:"ElementStart",prefix:e,local:r,start:s});let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const u=t.getPos(),T=t.currCodeUnit();if(T===o.SLASH){t.advance(1),t.consumeCodeUnit(o.GREATER_THAN);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Empty"},range:d});break}else if(T===o.GREATER_THAN){t.advance(1);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Open"},range:d}),i=!0;break}else{if(!c)throw new a.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[d,v,N]=p(t),x=t.getPos();n({type:"Attribute",range:{start:u,end:x},prefix:d,local:v,value:N})}}i&&V(t,n)}function p(t){const[n,s]=t.consumeQName();let e;const r=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(o.EQUALS)){t.skipSpaces();const i=t.consumeQuote();e=t.consumeCodeUnitsWhile(c=>c!==i&&c!==o.LESS_THAN),t.consumeCodeUnit(i)}else{if(t.config.strict)throw new a.XmlError({type:"InvalidChar",expected:o.EQUALS,actual:t.currCodeUnit()},t.genTextPos());t.goTo(r),e="true"}return[n,s,e]}function V(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===o.LESS_THAN){const s=t.nextCodeUnit();if(s===o.EXCLAMATION_MARK)if(t.startsWith(m))f(t,n);else if(t.startsWith(Q))Z(t,n);else throw new a.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===o.QUESTION_MARK)h(t,n);else if(s===o.SLASH){$(t,n);break}else S(t,n)}else y(t,n)}function Z(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCodeUnitsWhile((i,c)=>!(i===o.CLOSE_SQUARE_BRACKET&&c.startsWith(E)));t.skipString(E);const r=t.rangeFrom(s);n({type:"Cdata",text:e,range:r})}function $(t,n){const s=t.getPos();t.advance(2);const[e,r]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(o.GREATER_THAN);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:r},range:i})}function y(t,n){const s=t.getPos(),e=t.consumeCodeUnitsWhile(r=>r!==o.LESS_THAN);if(e.includes(E))throw new a.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:e,range:t.rangeFrom(s)})}exports.tokenize=M,exports.tokenizeXmlStream=P;
@@ -1 +1 @@
1
- "use strict";var r=require("./tokenizer/tokenize.js");function s(t,o=!1){const e={local:"root",attributes:[],content:[]},n=[e];return r.tokenize(t,o,l=>{c(l,n)}),e.content[0]}function c(t,o){switch(t.type){case"ElementStart":{const e={local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,attributes:[],content:[]},n=o[o.length-1];n!=null&&n.content.push(e),o.push(e);break}case"ElementEnd":{(t.end.type==="Close"||t.end.type==="Empty")&&o.pop();break}case"Attribute":{const e=o[o.length-1];e!=null&&e.attributes.push({local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,value:t.value});break}case"Text":case"Cdata":{const e=o[o.length-1];e!=null&&t.text.trim().length>0&&e.content.push(t.text);break}}}exports.processTokenForObject=c,exports.xmlToObject=s;
1
+ "use strict";var r=require("./tokenizer/tokenize.js");function s(t,o={}){const e={local:"root",attributes:[],content:[]},n=[e];return r.tokenize(t,l=>{c(l,n)},o),e.content[0]}function c(t,o){switch(t.type){case"ElementStart":{const e={local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,attributes:[],content:[]},n=o[o.length-1];n!=null&&n.content.push(e),o.push(e);break}case"ElementEnd":{(t.end.type==="Close"||t.end.type==="Empty")&&o.pop();break}case"Attribute":{const e=o[o.length-1];e!=null&&e.attributes.push({local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,value:t.value});break}case"Text":case"Cdata":{const e=o[o.length-1];e!=null&&t.text.trim().length>0&&e.content.push(t.text);break}}}exports.processTokenForObject=c,exports.xmlToObject=s;
@@ -1 +1 @@
1
- "use strict";var c=require("./get-q-name.js"),o=require("./tokenizer/tokenize.js");function s(i,l=!1){const e={},t=[e];return o.tokenize(i,l,r=>{a(r,t)}),e}function a(i,l){switch(i.type){case"ElementStart":{const e=c.getQName(i.local,i.prefix),t=`_${e}`,r={},n=l[l.length-1];n!=null&&(n.content!=null?(r.tag=e,n.content.push(r)):n.text!=null?(r.tag=e,n.content=[n.text,r],delete n.text):n[t]==null?n[t]=[r]:Array.isArray(n[t])?n[t].push(r):n[t]=[n[t],r]),l.push(r);break}case"ElementEnd":{(i.end.type==="Close"||i.end.type==="Empty")&&l.pop();break}case"Attribute":{const e=l[l.length-1];if(e!=null){const t=c.getQName(i.local,i.prefix);e.attributes!=null?e.attributes[t]=i.value:e.attributes={[t]:i.value}}break}case"Text":case"Cdata":{const e=l[l.length-1];if(e!=null){const t=i.text.trim();t.length>0&&(e.content!=null?e.content.push(t):e.text!=null?(e.content=[e.text,t],delete e.text):e.text=t)}break}}}exports.processTokenForSimplifiedObject=a,exports.xmlToSimplifiedObject=s;
1
+ "use strict";var c=require("./get-q-name.js"),o=require("./tokenizer/tokenize.js");function s(i,l={}){const e={},t=[e];return o.tokenize(i,r=>{a(r,t)},l),e}function a(i,l){switch(i.type){case"ElementStart":{const e=c.getQName(i.local,i.prefix),t=`_${e}`,r={},n=l[l.length-1];n!=null&&(n.content!=null?(r.tag=e,n.content.push(r)):n.text!=null?(r.tag=e,n.content=[n.text,r],delete n.text):n[t]==null?n[t]=[r]:Array.isArray(n[t])?n[t].push(r):n[t]=[n[t],r]),l.push(r);break}case"ElementEnd":{(i.end.type==="Close"||i.end.type==="Empty")&&l.pop();break}case"Attribute":{const e=l[l.length-1];if(e!=null){const t=c.getQName(i.local,i.prefix);e.attributes!=null?e.attributes[t]=i.value:e.attributes={[t]:i.value}}break}case"Text":case"Cdata":{const e=l[l.length-1];if(e!=null){const t=i.text.trim();t.length>0&&(e.content!=null?e.content.push(t):e.text!=null?(e.content=[e.text,t],delete e.text):e.text=t)}break}}}exports.processTokenForSimplifiedObject=a,exports.xmlToSimplifiedObject=s;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{select as E}from"./selector/select.js";import{TokenSelector as t}from"./selector/TokenSelector.js";import{EToCacheNodeProps as m,ETokenMatchCriteria as A,TokenSelectState as R}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as T}from"./selector/TokenSelectStateMachine.js";import{tokenToXml as N}from"./token-to-xml.js";import{AMPERSAND as p,CARRIAGE_RETURN as _,COLON as l,DOUBLE_QUOTE as P,EQUALS as c,EXCLAMATION_MARK as f,GREATER_THAN as x,HASH as a,HORIZONTAL_TAB as s,HYPHEN as L,LESS_THAN as U,LINE_FEED as X,LOWERCASE_A as n,LOWERCASE_F as k,LOWERCASE_X as I,LOWERCASE_Z as H,NINE as M,OPEN_BRACKET as D,PERCENT as B,PERIOD as F,QUESTION_MARK as b,SEMICOLON as h,SINGLE_QUOTE as j,SLASH as Q,SPACE as W,UNDERSCORE as Z,UPPERCASE_A as d,UPPERCASE_F as G,UPPERCASE_P as K,UPPERCASE_S as y,UPPERCASE_Z as z,ZERO as g}from"./tokenizer/ascii-constants.js";import{tokenize as q,tokenizeXmlStream as u}from"./tokenizer/tokenize.js";import{isAsciiDigit as w,isXmlChar as J,isXmlName as V,isXmlNameByte as $,isXmlNameStart as ee,isXmlSpaceByte as oe}from"./tokenizer/utils.js";import{XmlError as re}from"./tokenizer/XmlError.js";import{XmlStream as Se}from"./tokenizer/XmlStream.js";import{tokensToXml as Ae}from"./tokens-to-xml.js";import{processTokenForObject as Oe,xmlToObject as Te}from"./xml-to-object.js";import{processTokenForSimplifiedObject as Ne,xmlToSimplifiedObject as Ce}from"./xml-to-simplified-object.js";export{p as AMPERSAND,_ as CARRIAGE_RETURN,l as COLON,P as DOUBLE_QUOTE,c as EQUALS,m as EToCacheNodeProps,A as ETokenMatchCriteria,f as EXCLAMATION_MARK,x as GREATER_THAN,a as HASH,s as HORIZONTAL_TAB,L as HYPHEN,U as LESS_THAN,X as LINE_FEED,n as LOWERCASE_A,k as LOWERCASE_F,I as LOWERCASE_X,H as LOWERCASE_Z,M as NINE,D as OPEN_BRACKET,B as PERCENT,F as PERIOD,b as QUESTION_MARK,h as SEMICOLON,j as SINGLE_QUOTE,Q as SLASH,W as SPACE,R as TokenSelectState,T as TokenSelectStateMachine,t as TokenSelector,Z as UNDERSCORE,d as UPPERCASE_A,G as UPPERCASE_F,K as UPPERCASE_P,y as UPPERCASE_S,z as UPPERCASE_Z,re as XmlError,Se as XmlStream,g as ZERO,w as isAsciiDigit,J as isXmlChar,V as isXmlName,$ as isXmlNameByte,ee as isXmlNameStart,oe as isXmlSpaceByte,Oe as processTokenForObject,Ne as processTokenForSimplifiedObject,E as select,N as tokenToXml,q as tokenize,u as tokenizeXmlStream,Ae as tokensToXml,Te as xmlToObject,Ce as xmlToSimplifiedObject};
1
+ import{select as o}from"./selector/select.js";import{TokenSelector as t}from"./selector/TokenSelector.js";import{EToCacheNodeProps as A,ETokenMatchCriteria as m,TokenSelectState as R}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as O}from"./selector/TokenSelectStateMachine.js";import{tokenToXml as _}from"./token-to-xml.js";import{AMPERSAND as i,CARRIAGE_RETURN as p,CLOSE_CURLY_BRACKET as P,CLOSE_SQUARE_BRACKET as l,COLON as L,DOUBLE_QUOTE as U,EQUALS as c,EXCLAMATION_MARK as f,GREATER_THAN as x,HASH as a,HORIZONTAL_TAB as s,HYPHEN as X,LESS_THAN as n,LINE_FEED as k,LOWERCASE_A as I,LOWERCASE_F as B,LOWERCASE_X as H,LOWERCASE_Z as M,NINE as D,OPEN_CURLY_BRACKET as K,OPEN_SQUARE_BRACKET as Q,PERCENT as F,PERIOD as b,QUESTION_MARK as h,SEMICOLON as j,SINGLE_QUOTE as W,SLASH as Z,SPACE as d,UNDERSCORE as G,UPPERCASE_A as Y,UPPERCASE_F as y,UPPERCASE_P as z,UPPERCASE_S as g,UPPERCASE_Z as q,ZERO as u}from"./tokenizer/ascii-constants.js";import{tokenize as w,tokenizeXmlStream as J}from"./tokenizer/tokenize.js";import{isAsciiDigit as $,isXmlChar as EE,isXmlName as eE,isXmlNameByte as oE,isXmlNameStart as rE,isXmlSpaceByte as tE}from"./tokenizer/utils.js";import{XmlError as AE}from"./tokenizer/XmlError.js";import{XmlStream as RE}from"./tokenizer/XmlStream.js";import{tokensToXml as OE}from"./tokens-to-xml.js";import{processTokenForObject as _E,xmlToObject as NE}from"./xml-to-object.js";import{processTokenForSimplifiedObject as pE,xmlToSimplifiedObject as PE}from"./xml-to-simplified-object.js";export{i as AMPERSAND,p as CARRIAGE_RETURN,P as CLOSE_CURLY_BRACKET,l as CLOSE_SQUARE_BRACKET,L as COLON,U as DOUBLE_QUOTE,c as EQUALS,A as EToCacheNodeProps,m as ETokenMatchCriteria,f as EXCLAMATION_MARK,x as GREATER_THAN,a as HASH,s as HORIZONTAL_TAB,X as HYPHEN,n as LESS_THAN,k as LINE_FEED,I as LOWERCASE_A,B as LOWERCASE_F,H as LOWERCASE_X,M as LOWERCASE_Z,D as NINE,K as OPEN_CURLY_BRACKET,Q as OPEN_SQUARE_BRACKET,F as PERCENT,b as PERIOD,h as QUESTION_MARK,j as SEMICOLON,W as SINGLE_QUOTE,Z as SLASH,d as SPACE,R as TokenSelectState,O as TokenSelectStateMachine,t as TokenSelector,G as UNDERSCORE,Y as UPPERCASE_A,y as UPPERCASE_F,z as UPPERCASE_P,g as UPPERCASE_S,q as UPPERCASE_Z,AE as XmlError,RE as XmlStream,u as ZERO,$ as isAsciiDigit,EE as isXmlChar,eE as isXmlName,oE as isXmlNameByte,rE as isXmlNameStart,tE as isXmlSpaceByte,_E as processTokenForObject,pE as processTokenForSimplifiedObject,o as select,_ as tokenToXml,w as tokenize,J as tokenizeXmlStream,OE as tokensToXml,NE as xmlToObject,PE as xmlToSimplifiedObject};
@@ -1 +1 @@
1
- import{tokenize as p}from"../tokenizer/tokenize.js";import{TokenSelector as c}from"./TokenSelector.js";function m(e,o,t){const n=new c(o);p(e,!1,r=>{n.pipeToken(r,i=>{t(i)})})}export{m as select};
1
+ import{tokenize as p}from"../tokenizer/tokenize.js";import{TokenSelector as c}from"./TokenSelector.js";function m(e,o,n){const t=new c(o);p(e,r=>{t.pipeToken(r,i=>{n(i)})})}export{m as select};
@@ -1 +1 @@
1
- import{AMPERSAND as _,HASH as m,LOWERCASE_X as C,ZERO as f,NINE as x,UPPERCASE_A as U,UPPERCASE_F as w,LOWERCASE_A as y,LOWERCASE_F as g,SEMICOLON as k,COLON as E,SINGLE_QUOTE as P,DOUBLE_QUOTE as v,LINE_FEED as N}from"./ascii-constants.js";import{isXmlChar as u,isXmlSpaceByte as S,isAsciiDigit as A,isXmlNameStart as a,isXmlName as d}from"./utils.js";import{XmlError as n}from"./XmlError.js";var T=Object.defineProperty,W=(h,t,e)=>t in h?T(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,c=(h,t,e)=>W(h,typeof t!="symbol"?t+"":t,e);class l{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 l(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}goTo(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&&S(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(_))return null;let t;if(this.tryConsumeCodeUnit(m)){let e,i;this.tryConsumeCodeUnit(C)?(e=this.consumeCodeUnitsWhile(s=>s>=f&&s<=x||s>=U&&s<=w||s>=y&&s<=g),i=16):(e=this.consumeCodeUnitsWhile(s=>A(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(k)?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 p=this.currCodeUnitUnchecked();if(p===E)if(o==null)o=this._pos,this._pos+=1;else throw new n({type:"InvalidName"},this.genTextPosFrom(i));else if(d(p))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]}consumeQuote(){const t=this.currCodeUnit();if(t===P||t===v)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)===N?(i++,o=1):o++;return{row:i,col:o}}}export{l as XmlStream};
1
+ import{AMPERSAND as C,HASH as f,LOWERCASE_X as U,ZERO as y,NINE as w,UPPERCASE_A as g,UPPERCASE_F as x,LOWERCASE_A as v,LOWERCASE_F as P,SEMICOLON as E,COLON as k,SINGLE_QUOTE as S,DOUBLE_QUOTE as N,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as u,isXmlSpaceByte as b,isAsciiDigit as T,isXmlNameStart as c,isXmlName as _}from"./utils.js";import{XmlError as o}from"./XmlError.js";var A=Object.defineProperty,m=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,p=(r,t,e)=>t in r?A(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,F=(r,t)=>{for(var e in t||(t={}))I.call(t,e)&&p(r,e,t[e]);if(m)for(var e of m(t))W.call(t,e)&&p(r,e,t[e]);return r},a=(r,t,e)=>p(r,typeof t!="symbol"?t+"":t,e);class l{constructor(t,e={}){a(this,"_text"),a(this,"_pos"),a(this,"_end"),a(this,"config");const{pos:i=0,strict:n=!0,allowDtd:s=!0}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strict:n,allowDtd:s}}clone(){return new l(this._text,F({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o({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({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!u(this.currCodeUnitUnchecked()))throw new o({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}skipString(t){if(!this.startsWith(t))throw new o({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}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&&b(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o({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(C))return null;let t;if(this.tryConsumeCodeUnit(f)){let e,i;this.tryConsumeCodeUnit(U)?(e=this.consumeCodeUnitsWhile(s=>s>=y&&s<=w||s>=g&&s<=x||s>=v&&s<=P),i=16):(e=this.consumeCodeUnitsWhile(s=>T(s)),i=10);const n=parseInt(e,i);isNaN(n)||!u(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(E)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o({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(!c(e))throw new o({type:"InvalidName"},this.genTextPosFrom(t))}else if(!_(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let n=null;for(;this._pos<this._end;){const d=this.currCodeUnitUnchecked();if(d===k)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(i));else if(_(d))this._pos+=1;else break}let s,h;if(n!=null?(s=this._text.slice(i,n),h=this.sliceBack(n+1)):(s="",h=this.sliceBack(i)),s.length>0&&!c((t=s[0])==null?void 0:t.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(i));if(h.length>0){if(!c((e=h[0])==null?void 0:e.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(i))}else throw new o({type:"InvalidName"},this.genTextPosFrom(i));return[s,h]}consumeQuote(){const t=this.currCodeUnit();if(t===S||t===N)return this._pos+=1,t;throw new o({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,n=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===O?(i++,n=1):n++;return{row:i,col:n}}}export{l as XmlStream};
@@ -1 +1 @@
1
- const E=9,A=10,R=13,S=32,O=33,_=34,C=35,N=37,P=38,L=39,T=45,U=46,I=47,H=48,D=57,M=58,Q=59,W=60,Z=61,B=62,F=63,G=65,K=70,o=80,t=83,X=90,c=91,e=95,n=97,p=102,r=120,s=122;export{P as AMPERSAND,R as CARRIAGE_RETURN,M as COLON,_ as DOUBLE_QUOTE,Z as EQUALS,O as EXCLAMATION_MARK,B as GREATER_THAN,C as HASH,E as HORIZONTAL_TAB,T as HYPHEN,W as LESS_THAN,A as LINE_FEED,n as LOWERCASE_A,p as LOWERCASE_F,r as LOWERCASE_X,s as LOWERCASE_Z,D as NINE,c as OPEN_BRACKET,N as PERCENT,U as PERIOD,F as QUESTION_MARK,Q as SEMICOLON,L as SINGLE_QUOTE,I as SLASH,S as SPACE,e as UNDERSCORE,G as UPPERCASE_A,K as UPPERCASE_F,o as UPPERCASE_P,t as UPPERCASE_S,X as UPPERCASE_Z,H as ZERO};
1
+ const E=9,A=10,R=13,S=32,_=33,C=34,O=35,L=37,N=38,P=39,U=45,T=46,I=47,H=48,B=57,K=58,Q=59,D=60,M=61,W=62,Z=63,F=65,G=70,Y=80,o=83,t=90,X=91,c=93,e=95,n=97,p=102,r=120,s=122,x=123,a=125;export{N as AMPERSAND,R as CARRIAGE_RETURN,a as CLOSE_CURLY_BRACKET,c as CLOSE_SQUARE_BRACKET,K as COLON,C as DOUBLE_QUOTE,M as EQUALS,_ as EXCLAMATION_MARK,W as GREATER_THAN,O as HASH,E as HORIZONTAL_TAB,U as HYPHEN,D as LESS_THAN,A as LINE_FEED,n as LOWERCASE_A,p as LOWERCASE_F,r as LOWERCASE_X,s as LOWERCASE_Z,B as NINE,x as OPEN_CURLY_BRACKET,X as OPEN_SQUARE_BRACKET,L as PERCENT,T as PERIOD,Z as QUESTION_MARK,Q as SEMICOLON,P as SINGLE_QUOTE,I as SLASH,S as SPACE,e as UNDERSCORE,F as UPPERCASE_A,G as UPPERCASE_F,Y as UPPERCASE_P,o as UPPERCASE_S,t as UPPERCASE_Z,H as ZERO};
@@ -1 +1 @@
1
- import{LESS_THAN as S,GREATER_THAN as r,OPEN_BRACKET as F,PERCENT as Q,DOUBLE_QUOTE as D,SINGLE_QUOTE as L,UPPERCASE_S as O,UPPERCASE_P as _,SLASH as k,EQUALS as R,EXCLAMATION_MARK as b,QUESTION_MARK as B}from"./ascii-constants.js";import{XmlError as i}from"./XmlError.js";import{XmlStream as M}from"./XmlStream.js";const Y="\uFEFF",E="<?xml ",T="?>",H="<!ENTITY",K="<!ELEMENT",X="<!ATTLIST",z="<!NOTATION",G="<!DOCTYPE",U="<?",w="?>",l="<!--",P="-->",q="<![CDATA[",h="]]>",j="NDATA",W="PUBLIC",J="SYSTEM",V="version",Z="encoding",$="standalone";function tt(t,n,s){y(new M(t),n,s)}function y(t,n,s){if(t.startsWith(Y)&&t.advance(1),t.startsWith(E)&&nt(t),f(t,s),t.skipSpaces(),t.startsWith(G)){if(!n)throw new i({type:"DtdDetected"});st(t,s),f(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===S&&v(t,s),f(t,s),!t.atEnd())throw new i({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function f(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(l))g(t,n);else if(t.startsWith(U))C(t,n);else break}function nt(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(T)&&!s.atEnd())throw new i({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(V))throw new i({type:"InvalidString",expected:"version"},t.genTextPos());m(t),n(t),t.startsWith(Z)&&(m(t),n(t)),t.startsWith($)&&m(t),t.skipSpaces(),t.skipString(T)}function g(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCharsWhile((o,a)=>!(a==="-"&&o.startsWith(P)));if(t.skipString(P),e.includes("--")||e.endsWith("-"))throw new i({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)})}function C(t,n){if(t.startsWith(E))throw new i({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const o=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith(w)));t.skipString(w),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)})}function st(t,n){const s=t.getPos();if(et(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(H))ot(t,n);else if(t.startsWith(l))g(t,n);else if(t.startsWith(U))C(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(K)||t.startsWith(X)||t.startsWith(z))try{it(t)}catch(e){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 et(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),x(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==F&&n!==r)throw new i({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function x(t){if(t.startsWith(J)||t.startsWith(W)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const e=t.consumeQuote();if(t.consumeCodeUnitsWhile(o=>o!==e),t.consumeCodeUnit(e),s===W){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==o),t.consumeCodeUnit(o)}return!0}return!1}function ot(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(Q);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=at(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o}),t.skipSpaces(),t.consumeCodeUnit(r)}function at(t,n){const s=t.currCodeUnit();if(s===D||s===L){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const a=t.sliceBack(o);return t.consumeCodeUnit(e),a}else if(s===O||s===_){if(x(t))return n&&(t.skipSpaces(),t.startsWith(j)&&(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 it(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function v(t,n){const s=t.getPos();t.advance(1);const[e,o]=t.consumeQName();n({type:"ElementStart",prefix:e,local:o,start:s});let a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const u=t.getPos(),p=t.currCodeUnit();if(p===k){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,N,A]=m(t),I=t.getPos();n({type:"Attribute",range:{start:u,end:I},prefix:d,local:N,value:A})}}a&&ct(t,n)}function m(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(R)){t.skipSpaces();const a=t.consumeQuote(),c=String.fromCharCode(a);e=t.consumeCharsWhile((u,p)=>p!==c&&p!=="<"),t.consumeCodeUnit(a)}else t.goTo(o),e="true";return[n,s,e]}function ct(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===S){const s=t.nextCodeUnit();if(s===b)if(t.startsWith(l))g(t,n);else if(t.startsWith(q))rt(t,n);else throw new i({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===B)C(t,n);else if(s===k){pt(t,n);break}else v(t,n)}else dt(t,n)}function rt(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith(h)));t.skipString(h);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o})}function pt(t,n){const s=t.getPos();t.advance(2);const[e,o]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:o},range:a})}function dt(t,n){const s=t.getPos(),e=t.consumeCharsWhile((o,a)=>a!=="<");if(e.includes(h))throw new i({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:e,range:t.rangeFrom(s)})}export{tt as tokenize,y as tokenizeXmlStream};
1
+ import{LESS_THAN as d,HYPHEN as D,QUESTION_MARK as U,GREATER_THAN as r,OPEN_SQUARE_BRACKET as L,PERCENT as O,DOUBLE_QUOTE as R,SINGLE_QUOTE as b,UPPERCASE_S as B,UPPERCASE_P as H,SLASH as k,EQUALS as T,EXCLAMATION_MARK as M,CLOSE_SQUARE_BRACKET as K}from"./ascii-constants.js";import{XmlError as a}from"./XmlError.js";import{XmlStream as Y}from"./XmlStream.js";const X="\uFEFF",w="<?xml ",P="?>",z="<!ENTITY",G="<!ELEMENT",j="<!ATTLIST",q="<!NOTATION",J="<!DOCTYPE",W="<?",y="?>",f="<!--",x="-->",V="<![CDATA[",h="]]>",Z="NDATA",v="PUBLIC",$="SYSTEM",tt="version",nt="encoding",st="standalone";function ot(t,n,s={}){A(new Y(t,s),n)}function A(t,n){if(t.startsWith(X)&&t.advance(1),t.startsWith(w)&&et(t),u(t,n),t.skipSpaces(),t.startsWith(J)){if(!t.config.allowDtd)throw new a({type:"DtdDetected"});it(t,n),u(t,n)}if(t.skipSpaces(),t.config.strict){if(!t.atEnd()&&t.currCodeUnit()===d&&S(t,n),u(t,n),!t.atEnd())throw new a({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===d?S(t,n):I(t,n),u(t,n)}function u(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(f))g(t,n);else if(t.startsWith(W))C(t,n);else break}function et(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(P)&&!s.atEnd())throw new a({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(tt))throw new a({type:"InvalidString",expected:"version"},t.genTextPos());l(t),n(t),t.startsWith(nt)&&(l(t),n(t)),t.startsWith(st)&&l(t),t.skipSpaces(),t.skipString(P)}function g(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCodeUnitsWhile((e,i)=>!(e===D&&i.startsWith(x)));if(t.skipString(x),o.includes("--")||o.endsWith("-"))throw new a({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function C(t,n){if(t.startsWith(w))throw new a({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCodeUnitsWhile((i,c)=>!(i===U&&c.startsWith(y)));t.skipString(y),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function it(t,n){const s=t.getPos();if(at(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(z))ct(t,n);else if(t.startsWith(f))g(t,n);else if(t.startsWith(W))C(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new a({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(G)||t.startsWith(j)||t.startsWith(q))try{pt(t)}catch(o){throw new a({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new a({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function at(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),N(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==L&&n!==r)throw new a({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function N(t){if(t.startsWith($)||t.startsWith(v)){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===v){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==e),t.consumeCodeUnit(e)}return!0}return!1}function ct(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(O);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=rt(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r)}function rt(t,n){const s=t.currCodeUnit();if(s===R||s===b){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const i=t.sliceBack(e);return t.consumeCodeUnit(o),i}else if(s===B||s===H){if(N(t))return n&&(t.skipSpaces(),t.startsWith(Z)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a({type:"InvalidExternalID"},t.genTextPos())}else throw new a({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function pt(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function S(t,n){const s=t.getPos();t.advance(1);const[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s});let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const m=t.getPos(),E=t.currCodeUnit();if(E===k){t.advance(1),t.consumeCodeUnit(r);const p=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(E===r){t.advance(1);const p=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Open"},range:p}),i=!0;break}else{if(!c)throw new a({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[p,F,Q]=l(t),_=t.getPos();n({type:"Attribute",range:{start:m,end:_},prefix:p,local:F,value:Q})}}i&&dt(t,n)}function l(t){const[n,s]=t.consumeQName();let o;const e=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(T)){t.skipSpaces();const i=t.consumeQuote();o=t.consumeCodeUnitsWhile(c=>c!==i&&c!==d),t.consumeCodeUnit(i)}else{if(t.config.strict)throw new a({type:"InvalidChar",expected:T,actual:t.currCodeUnit()},t.genTextPos());t.goTo(e),o="true"}return[n,s,o]}function dt(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===d){const s=t.nextCodeUnit();if(s===M)if(t.startsWith(f))g(t,n);else if(t.startsWith(V))ut(t,n);else throw new a({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===U)C(t,n);else if(s===k){lt(t,n);break}else S(t,n)}else I(t,n)}function ut(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((i,c)=>!(i===K&&c.startsWith(h)));t.skipString(h);const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function lt(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:i})}function I(t,n){const s=t.getPos(),o=t.consumeCodeUnitsWhile(e=>e!==d);if(o.includes(h))throw new a({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}export{ot as tokenize,A as tokenizeXmlStream};
@@ -1 +1 @@
1
- import{tokenize as c}from"./tokenizer/tokenize.js";function a(t,o=!1){const e={local:"root",attributes:[],content:[]},l=[e];return c(t,o,r=>{n(r,l)}),e.content[0]}function n(t,o){switch(t.type){case"ElementStart":{const e={local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,attributes:[],content:[]},l=o[o.length-1];l!=null&&l.content.push(e),o.push(e);break}case"ElementEnd":{(t.end.type==="Close"||t.end.type==="Empty")&&o.pop();break}case"Attribute":{const e=o[o.length-1];e!=null&&e.attributes.push({local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,value:t.value});break}case"Text":case"Cdata":{const e=o[o.length-1];e!=null&&t.text.trim().length>0&&e.content.push(t.text);break}}}export{n as processTokenForObject,a as xmlToObject};
1
+ import{tokenize as c}from"./tokenizer/tokenize.js";function a(t,o={}){const e={local:"root",attributes:[],content:[]},l=[e];return c(t,r=>{n(r,l)},o),e.content[0]}function n(t,o){switch(t.type){case"ElementStart":{const e={local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,attributes:[],content:[]},l=o[o.length-1];l!=null&&l.content.push(e),o.push(e);break}case"ElementEnd":{(t.end.type==="Close"||t.end.type==="Empty")&&o.pop();break}case"Attribute":{const e=o[o.length-1];e!=null&&e.attributes.push({local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,value:t.value});break}case"Text":case"Cdata":{const e=o[o.length-1];e!=null&&t.text.trim().length>0&&e.content.push(t.text);break}}}export{n as processTokenForObject,a as xmlToObject};
@@ -1 +1 @@
1
- import{getQName as c}from"./get-q-name.js";import{tokenize as i}from"./tokenizer/tokenize.js";function s(o,l=!1){const t={},e=[t];return i(o,l,r=>{a(r,e)}),t}function a(o,l){switch(o.type){case"ElementStart":{const t=c(o.local,o.prefix),e=`_${t}`,r={},n=l[l.length-1];n!=null&&(n.content!=null?(r.tag=t,n.content.push(r)):n.text!=null?(r.tag=t,n.content=[n.text,r],delete n.text):n[e]==null?n[e]=[r]:Array.isArray(n[e])?n[e].push(r):n[e]=[n[e],r]),l.push(r);break}case"ElementEnd":{(o.end.type==="Close"||o.end.type==="Empty")&&l.pop();break}case"Attribute":{const t=l[l.length-1];if(t!=null){const e=c(o.local,o.prefix);t.attributes!=null?t.attributes[e]=o.value:t.attributes={[e]:o.value}}break}case"Text":case"Cdata":{const t=l[l.length-1];if(t!=null){const e=o.text.trim();e.length>0&&(t.content!=null?t.content.push(e):t.text!=null?(t.content=[t.text,e],delete t.text):t.text=e)}break}}}export{a as processTokenForSimplifiedObject,s as xmlToSimplifiedObject};
1
+ import{getQName as c}from"./get-q-name.js";import{tokenize as i}from"./tokenizer/tokenize.js";function s(o,l={}){const t={},e=[t];return i(o,r=>{a(r,e)},l),t}function a(o,l){switch(o.type){case"ElementStart":{const t=c(o.local,o.prefix),e=`_${t}`,r={},n=l[l.length-1];n!=null&&(n.content!=null?(r.tag=t,n.content.push(r)):n.text!=null?(r.tag=t,n.content=[n.text,r],delete n.text):n[e]==null?n[e]=[r]:Array.isArray(n[e])?n[e].push(r):n[e]=[n[e],r]),l.push(r);break}case"ElementEnd":{(o.end.type==="Close"||o.end.type==="Empty")&&l.pop();break}case"Attribute":{const t=l[l.length-1];if(t!=null){const e=c(o.local,o.prefix);t.attributes!=null?t.attributes[e]=o.value:t.attributes={[e]:o.value}}break}case"Text":case"Cdata":{const t=l[l.length-1];if(t!=null){const e=o.text.trim();e.length>0&&(t.content!=null?t.content.push(e):t.text!=null?(t.content=[t.text,e],delete t.text):t.text=e)}break}}}export{a as processTokenForSimplifiedObject,s as xmlToSimplifiedObject};
@@ -10,7 +10,8 @@ export declare class XmlStream {
10
10
  private _text;
11
11
  private _pos;
12
12
  private _end;
13
- constructor(text: string, pos?: number);
13
+ readonly config: TXmlStreamConfig;
14
+ constructor(text: string, options?: TXmlStreamOptions);
14
15
  /**
15
16
  * Creates a clone of the current stream.
16
17
  *
@@ -49,25 +50,6 @@ export declare class XmlStream {
49
50
  * @throws XmlError if at the end of the stream.
50
51
  */
51
52
  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
- * Go to a new position in the stream.
60
- *
61
- * @param pos - The new position.
62
- */
63
- goTo(pos: number): void;
64
- /**
65
- * Checks if the stream starts with the given text.
66
- *
67
- * @param text - The text to check.
68
- * @returns True if the stream starts with the text, false otherwise.
69
- */
70
- startsWith(text: string): boolean;
71
53
  /**
72
54
  * Consumes a specific code unit (character) from the stream.
73
55
  *
@@ -83,41 +65,45 @@ export declare class XmlStream {
83
65
  * @returns True if the code unit was consumed, false otherwise.
84
66
  */
85
67
  tryConsumeCodeUnit(codeUnit: number): boolean;
86
- /**
87
- * Skips a specific string in the stream.
88
- *
89
- * @param text - The string to skip.
90
- * @throws XmlError if the stream doesn't start with the given string.
91
- */
92
- skipString(text: string): void;
93
68
  /**
94
69
  * Consumes code units that satisfy a predicate function.
95
70
  *
96
71
  * @param predicate - The function to test each code unit.
97
72
  * @returns The consumed string.
98
73
  */
99
- consumeCodeUnitsWhile(predicate: (codeUnit: number) => boolean): string;
74
+ consumeCodeUnitsWhile(predicate: (codeUnit: number, stream: XmlStream) => boolean): string;
100
75
  /**
101
76
  * Skips code units that satisfy a predicate function.
102
77
  *
103
78
  * @param predicate - The function to test each code unit.
104
79
  */
105
- skipCodeUnitsWhile(predicate: (codeUnit: number) => boolean): void;
80
+ skipCodeUnitsWhile(predicate: (codeUnit: number, stream: XmlStream) => boolean): void;
106
81
  /**
107
- * Consumes characters that satisfy a predicate function.
82
+ * Advances the stream position by the specified number of characters.
108
83
  *
109
- * @param predicate - The function to test each character.
110
- * @returns The consumed string.
111
- * @throws XmlError if a non-XML character is encountered.
84
+ * @param n - The number of characters to advance.
85
+ */
86
+ advance(n: number): void;
87
+ /**
88
+ * Go to a new position in the stream.
89
+ *
90
+ * @param pos - The new position.
91
+ */
92
+ goTo(pos: number): void;
93
+ /**
94
+ * Checks if the stream starts with the given text.
95
+ *
96
+ * @param text - The text to check.
97
+ * @returns True if the stream starts with the text, false otherwise.
112
98
  */
113
- consumeCharsWhile(predicate: (stream: XmlStream, char: string) => boolean): string;
99
+ startsWith(text: string): boolean;
114
100
  /**
115
- * Skips characters that satisfy a predicate function.
101
+ * Skips a specific string in the stream.
116
102
  *
117
- * @param predicate - The function to test each character.
118
- * @throws XmlError if a non-XML character is encountered.
103
+ * @param text - The string to skip.
104
+ * @throws XmlError if the stream doesn't start with the given string.
119
105
  */
120
- skipCharsWhile(predicate: (stream: XmlStream, char: string) => boolean): void;
106
+ skipString(text: string): void;
121
107
  /**
122
108
  * Slices the text from the given position to the current position.
123
109
  *
@@ -207,4 +193,11 @@ export declare class XmlStream {
207
193
  */
208
194
  genTextPosFrom(pos: number): TTextPos;
209
195
  }
196
+ export interface TXmlStreamConfig {
197
+ strict: boolean;
198
+ allowDtd: boolean;
199
+ }
200
+ export type TXmlStreamOptions = {
201
+ pos?: number;
202
+ } & Partial<TXmlStreamConfig>;
210
203
  //# sourceMappingURL=XmlStream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XmlStream.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/XmlStream.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAItE;;;;;;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;;;;OAIG;IACI,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI9B;;;;;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;IA8BzE;;;;;;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;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAY7B;;;;;OAKG;IACI,UAAU,IAAI,QAAQ;IAI7B;;;;;;OAMG;IACI,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;CAc5C"}
1
+ {"version":3,"file":"XmlStream.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/XmlStream.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAItE;;;;;;GAMG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;IAErB,SAAgB,MAAM,EAAE,gBAAgB,CAAC;gBAEtB,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAQhE;;;;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;;;;;OAKG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAW9C;;;;;;OAMG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQpD;;;;;OAKG;IACI,qBAAqB,CAC3B,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,KAAK,OAAO,GACzD,MAAM;IAMT;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,KAAK,OAAO,GAAG,IAAI;IAe5F;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;OAIG;IACI,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI9B;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOrC;;;;;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;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAY7B;;;;;OAKG;IACI,UAAU,IAAI,QAAQ;IAI7B;;;;;;OAMG;IACI,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;CAc5C;AAGD,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC"}
@@ -24,10 +24,13 @@ export declare const UPPERCASE_F = 70;
24
24
  export declare const UPPERCASE_P = 80;
25
25
  export declare const UPPERCASE_S = 83;
26
26
  export declare const UPPERCASE_Z = 90;
27
- export declare const OPEN_BRACKET = 91;
27
+ export declare const OPEN_SQUARE_BRACKET = 91;
28
+ export declare const CLOSE_SQUARE_BRACKET = 93;
28
29
  export declare const UNDERSCORE = 95;
29
30
  export declare const LOWERCASE_A = 97;
30
31
  export declare const LOWERCASE_F = 102;
31
32
  export declare const LOWERCASE_X = 120;
32
33
  export declare const LOWERCASE_Z = 122;
34
+ export declare const OPEN_CURLY_BRACKET = 123;
35
+ export declare const CLOSE_CURLY_BRACKET = 125;
33
36
  //# sourceMappingURL=ascii-constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ascii-constants.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/ascii-constants.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"}
1
+ {"version":3,"file":"ascii-constants.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/ascii-constants.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,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,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;AAC/B,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { type TTokenCallback } from './types';
2
- import { XmlStream } from './XmlStream';
3
- export declare function tokenize(xmlString: string, allowDtd: boolean, tokenCallback: TTokenCallback): void;
2
+ import { XmlStream, type TXmlStreamOptions } from './XmlStream';
3
+ export declare function tokenize(xmlString: string, tokenCallback: TTokenCallback, options?: TXmlStreamOptions): void;
4
4
  /**
5
5
  * Parses an XML document.
6
6
  *
@@ -8,5 +8,5 @@ export declare function tokenize(xmlString: string, allowDtd: boolean, tokenCall
8
8
  *
9
9
  * https://www.w3.org/TR/xml/#NT-document
10
10
  */
11
- export declare function tokenizeXmlStream(s: XmlStream, allowDtd: boolean, tokenCallback: TTokenCallback): void;
11
+ export declare function tokenizeXmlStream(s: XmlStream, tokenCallback: TTokenCallback): void;
12
12
  //# sourceMappingURL=tokenize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/tokenize.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAuBxC,wBAAgB,QAAQ,CACvB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,CAAC,EAAE,SAAS,EACZ,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAgCN"}
1
+ {"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/tokenize.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAuBhE,wBAAgB,QAAQ,CACvB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,cAAc,EAC7B,OAAO,GAAE,iBAAsB,GAC7B,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,GAAG,IAAI,CA4CnF"}
@@ -1,5 +1,5 @@
1
- import { type TXmlToken } from './tokenizer';
2
- export declare function xmlToObject(xmlString: string, allowDtd?: boolean): TXmlNode;
1
+ import { type TXmlStreamOptions, type TXmlToken } from './tokenizer';
2
+ export declare function xmlToObject(xmlString: string, options?: TXmlStreamOptions): TXmlNode;
3
3
  export declare function processTokenForObject(token: TXmlToken, stack: TXmlNode[]): void;
4
4
  export interface TXmlNode {
5
5
  local: string;
@@ -1 +1 @@
1
- {"version":3,"file":"xml-to-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,QAAQ,CAazE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAkD/E;AAED,MAAM,WAAW,QAAQ;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAChE,OAAO,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;CAC/B"}
1
+ {"version":3,"file":"xml-to-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/E,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,QAAQ,CAiBxF;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAkD/E;AAED,MAAM,WAAW,QAAQ;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAChE,OAAO,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;CAC/B"}
@@ -1,5 +1,5 @@
1
- import { type TXmlToken } from './tokenizer';
2
- export declare function xmlToSimplifiedObject(xmlString: string, allowDtd?: boolean): TSimplifiedXmlNode;
1
+ import { type TXmlStreamOptions, type TXmlToken } from './tokenizer';
2
+ export declare function xmlToSimplifiedObject(xmlString: string, options?: TXmlStreamOptions): TSimplifiedXmlNode;
3
3
  export declare function processTokenForSimplifiedObject(token: TXmlToken, stack: TSimplifiedXmlNode[]): void;
4
4
  export interface TSimplifiedXmlNode {
5
5
  tag?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"xml-to-simplified-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-simplified-object.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,kBAAkB,CAS7F;AAED,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,kBAAkB,EAAE,GACzB,IAAI,CAsEN;AAED,MAAM,WAAW,kBAAkB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAE1C,CAAC,GAAG,EAAE,yBAAyB,GAAG,kBAAkB,EAAE,CAAC;CACvD;AAED,MAAM,MAAM,yBAAyB,GAAG,IAAI,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"xml-to-simplified-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-simplified-object.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/E,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,iBAAsB,GAC7B,kBAAkB,CAapB;AAED,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,kBAAkB,EAAE,GACzB,IAAI,CAsEN;AAED,MAAM,WAAW,kBAAkB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAE1C,CAAC,GAAG,EAAE,yBAAyB,GAAG,kBAAkB,EAAE,CAAC;CACvD;AAED,MAAM,MAAM,yBAAyB,GAAG,IAAI,MAAM,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-tokenizer",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -28,7 +28,7 @@
28
28
  "saxen": "^10.0.0",
29
29
  "txml": "^5.1.1",
30
30
  "xml2js": "^0.6.2",
31
- "@blgc/config": "0.0.22"
31
+ "@blgc/config": "0.0.23"
32
32
  },
33
33
  "files": [
34
34
  "dist",
@@ -40,7 +40,7 @@
40
40
  }
41
41
  ],
42
42
  "scripts": {
43
- "build": "shx rm -rf dist && ../../scripts/cli.sh bundle",
43
+ "build": "shx rm -rf dist && chmod +x ../../scripts/cli.sh && ../../scripts/cli.sh bundle",
44
44
  "build:dev": "shx rm -rf dist && ../../scripts/cli.sh bundle --target=dev",
45
45
  "start:dev": "tsc -w",
46
46
  "lint": "eslint --ext .js,.ts src/",