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 +55 -49
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/selector/select.js +1 -1
- package/dist/cjs/tokenizer/XmlStream.js +1 -1
- package/dist/cjs/tokenizer/ascii-constants.js +1 -1
- package/dist/cjs/tokenizer/tokenize.js +1 -1
- package/dist/cjs/xml-to-object.js +1 -1
- package/dist/cjs/xml-to-simplified-object.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/selector/select.js +1 -1
- package/dist/esm/tokenizer/XmlStream.js +1 -1
- package/dist/esm/tokenizer/ascii-constants.js +1 -1
- package/dist/esm/tokenizer/tokenize.js +1 -1
- package/dist/esm/xml-to-object.js +1 -1
- package/dist/esm/xml-to-simplified-object.js +1 -1
- package/dist/types/tokenizer/XmlStream.d.ts +31 -38
- package/dist/types/tokenizer/XmlStream.d.ts.map +1 -1
- package/dist/types/tokenizer/ascii-constants.d.ts +4 -1
- package/dist/types/tokenizer/ascii-constants.d.ts.map +1 -1
- package/dist/types/tokenizer/tokenize.d.ts +3 -3
- package/dist/types/tokenizer/tokenize.d.ts.map +1 -1
- package/dist/types/xml-to-object.d.ts +2 -2
- package/dist/types/xml-to-object.d.ts.map +1 -1
- package/dist/types/xml-to-simplified-object.d.ts +2 -2
- package/dist/types/xml-to-simplified-object.d.ts.map +1 -1
- package/package.json +3 -3
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 {
|
|
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(
|
|
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(
|
|
56
|
-
|
|
57
|
-
// Or, parse XML to a stream of tokens
|
|
58
|
-
tokenize(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
113
|
-
|
|
114
|
-
| xml-tokenizer
|
|
115
|
-
| xml-tokenizer (dist)| 53.70 | 17.31 | 25.20 | 18.62 | ±3.28% |
|
|
116
|
-
| xml-tokenizer (npm)
|
|
117
|
-
| fast-xml-parser
|
|
118
|
-
| txml
|
|
119
|
-
| xml2js
|
|
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
|
|
147
|
-
|
|
148
|
-
| roxmltree:text
|
|
149
|
-
| roxmltree:wasmMix
|
|
150
|
-
| roxmltree:wasm
|
|
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
|
|
163
|
-
|
|
164
|
-
| roxmltree:text
|
|
165
|
-
| roxmltree:byte
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
+
"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
|
+
"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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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
|
+
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
|
+
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
|
-
|
|
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
|
-
*
|
|
82
|
+
* Advances the stream position by the specified number of characters.
|
|
108
83
|
*
|
|
109
|
-
* @param
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
99
|
+
startsWith(text: string): boolean;
|
|
114
100
|
/**
|
|
115
|
-
* Skips
|
|
101
|
+
* Skips a specific string in the stream.
|
|
116
102
|
*
|
|
117
|
-
* @param
|
|
118
|
-
* @throws XmlError if
|
|
103
|
+
* @param text - The string to skip.
|
|
104
|
+
* @throws XmlError if the stream doesn't start with the given string.
|
|
119
105
|
*/
|
|
120
|
-
|
|
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;
|
|
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
|
|
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,
|
|
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,
|
|
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,
|
|
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":"
|
|
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,
|
|
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;
|
|
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,
|
|
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;
|
|
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.
|
|
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.
|
|
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/",
|