xml-tokenizer 0.0.18 → 0.0.20
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 +6 -6
- package/dist/cjs/selector/TokenSelectState.js +1 -1
- package/dist/cjs/selector/TokenSelectStateMachine.js +1 -1
- package/dist/cjs/selector/TokenSelector.js +1 -1
- package/dist/cjs/selector/match-string.js +1 -1
- package/dist/cjs/selector/select.js +1 -1
- package/dist/cjs/tokenizer/XmlStream.js +1 -1
- package/dist/cjs/tokenizer/tokenize.js +1 -1
- package/dist/cjs/tokenizer/utils.js +1 -1
- package/dist/cjs/xml-to-object.js +1 -1
- package/dist/esm/selector/TokenSelectState.js +1 -1
- package/dist/esm/selector/TokenSelectStateMachine.js +1 -1
- package/dist/esm/selector/TokenSelector.js +1 -1
- package/dist/esm/selector/match-string.js +1 -1
- package/dist/esm/selector/select.js +1 -1
- package/dist/esm/tokenizer/XmlStream.js +1 -1
- package/dist/esm/tokenizer/tokenize.js +1 -1
- package/dist/esm/tokenizer/utils.js +1 -1
- package/dist/esm/xml-to-object.js +1 -1
- package/dist/types/selector/select.d.ts +2 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/builder-group/
|
|
2
|
+
<img src="https://raw.githubusercontent.com/builder-group/community/develop/packages/xml-tokenizer/.github/banner.svg" alt="xml-tokenizer banner">
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
5
|
<p align="left">
|
|
6
|
-
<a href="https://github.com/builder-group/
|
|
7
|
-
<img src="https://img.shields.io/github/license/builder-group/
|
|
6
|
+
<a href="https://github.com/builder-group/community/blob/develop/LICENSE">
|
|
7
|
+
<img src="https://img.shields.io/github/license/builder-group/community.svg?label=license&style=flat&colorA=293140&colorB=FDE200" alt="GitHub License"/>
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://www.npmjs.com/package/xml-tokenizer">
|
|
10
10
|
<img src="https://img.shields.io/bundlephobia/minzip/xml-tokenizer.svg?label=minzipped%20size&style=flat&colorA=293140&colorB=FDE200" alt="NPM bundle minzipped size"/>
|
|
@@ -29,7 +29,7 @@ The implementation is based on the [roxmltree](https://github.com/RazrFalcon/rox
|
|
|
29
29
|
|
|
30
30
|
### 📚 Examples
|
|
31
31
|
|
|
32
|
-
- [Vanilla Profiler](https://github.com/builder-group/
|
|
32
|
+
- [Vanilla Profiler](https://github.com/builder-group/community/tree/develop/examples/xml-tokenizer/vanilla/playground)
|
|
33
33
|
|
|
34
34
|
### 🌟 Motivation
|
|
35
35
|
|
|
@@ -194,9 +194,9 @@ See [Generator vs Iterator vs Callback](https://observablehq.com/@domoritz/yield
|
|
|
194
194
|
[fast-xml-parser] Total Time: 1308.0000 ms | Average Time per Run: 13.0800 ms | Median Time: 13.0000 ms | Runs: 100
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
[Benchmark implementation in Vanilla Profiler](https://github.com/builder-group/
|
|
197
|
+
[Benchmark implementation in Vanilla Profiler](https://github.com/builder-group/community/tree/develop/examples/xml-tokenizer/vanilla/playground)
|
|
198
198
|
|
|
199
|
-
## 💡 Resources
|
|
199
|
+
## 💡 Resources / References
|
|
200
200
|
|
|
201
201
|
- [How I developed the fastest XML parser](https://tnickel.de/2020/08/30/2020-08-how-the-fastest-xml-parser-is-build/)
|
|
202
202
|
- [txml](https://github.com/TobiasNickel/tXml)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=require("./match-string.js"),m=Object.defineProperty,g=(t,
|
|
1
|
+
"use strict";var s=require("./match-string.js"),m=Object.defineProperty,g=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t,r)=>g(e,typeof t!="symbol"?t+"":t,r);class p{constructor(t){a(this,"_segment"),a(this,"_matchCriteria",0),a(this,"_toCacheNodeProps",0),a(this,"_enteredDepth",null),this._segment=t,this.applyLevels()}get matchCriteria(){return this._matchCriteria}get toCacheNodeProps(){return this._toCacheNodeProps}get enteredDepth(){return this._enteredDepth}applyLevels(){let t=0,r=0;(this._segment.local!=null||this._segment.prefix!=null)&&(t|=1),this._segment.attributes!=null&&(t|=2,r|=2),this._segment.text!=null&&(t|=4),this._matchCriteria=t,this._toCacheNodeProps=r}matchesName(t,r){return(this._segment.local==null||s.matchString(t,this._segment.local))&&(this._segment.prefix==null||s.matchString(r,this._segment.prefix))}matchesAttributes(t){if(this._segment.attributes==null)return!0;for(const r of this._segment.attributes){let n=!1;for(const i of t){const u=r.local==null||s.matchString(i.local,r.local),o=r.value==null||i.value!=null&&s.matchString(i.value,r.value),c=r.prefix==null||i.prefix!=null&&s.matchString(i.prefix,r.prefix);if(u&&o&&c){n=!0;break}}if(!n)return!1}return!0}matchesText(t){return this._segment.text==null||s.matchString(t,this._segment.text)}matchesDepth(t,r){switch(this._segment.axis){case"child":return t===r+1;case"self-or-descendant":return t>=r}}match(t){this._enteredDepth=t}unmatch(){this._enteredDepth=null}}var h=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e))(h||{}),l=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e[e.Node=8]="Node",e))(l||{});exports.EToCacheNodeProps=h,exports.ETokenMatchCriteria=l,exports.TokenSelectState=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("./TokenSelectState.js"),d=Object.defineProperty,_=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,
|
|
1
|
+
"use strict";var n=require("./TokenSelectState.js"),d=Object.defineProperty,_=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,o=(i,t,e)=>_(i,typeof t!="symbol"?t+"":t,e);class S{constructor(t){o(this,"_states"),o(this,"_currentState",null),o(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),o(this,"_cachedTokens",[]),o(this,"_toRecordTokens",[]),this._states=t.map(e=>new n.TokenSelectState(e))}getNextState(){var t;const e=this._currentState!=null?this._currentState+1:0;return e<this._states.length&&(t=this._states[e])!=null?t:null}getCurrentState(){var t;return this._currentState!=null&&this._currentState<this._states.length&&(t=this._states[this._currentState])!=null?t:null}record(t){this.getOffsetToFinal()<=1&&this._cachedTokens.push(t)}takeRecordedTokens(){if(this._toRecordTokens.length>0){const t=this._toRecordTokens;return this._toRecordTokens=[],t}return null}transitionIfNameMatch(t,e,r){var s;const a=this.getNextState(),h=this.getCurrentState();return a==null?!1:(a.toCacheNodeProps&n.EToCacheNodeProps.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),a.matchesName(t,e)&&a.matchesDepth(r,(s=h==null?void 0:h.enteredDepth)!=null?s:0)&&!(a.matchCriteria&(n.ETokenMatchCriteria.Attributes|n.ETokenMatchCriteria.Text|n.ETokenMatchCriteria.Node))?(this.transitionForward(r),!0):!1)}transitionIfAttributesMatch(t,e,r,s){var a,h;const c=this.getNextState(),u=this.getCurrentState();if(c==null)return!1;const l=(a=this._cachedNodeProps.attributes)!=null?a:[];return l.push({local:t,prefix:e,value:r}),c.toCacheNodeProps&n.EToCacheNodeProps.Attributes&&(this._cachedNodeProps.attributes=l),c.matchesAttributes(l)&&c.matchesDepth(s,(h=u==null?void 0:u.enteredDepth)!=null?h:0)&&!(c.matchCriteria&(n.ETokenMatchCriteria.Text|n.ETokenMatchCriteria.Node))?(this.transitionForward(s),!0):!1}transitionIfTextMatch(t,e){var r;const s=this.getNextState(),a=this.getCurrentState();return s==null?!1:(s.toCacheNodeProps&n.EToCacheNodeProps.Text&&(this._cachedNodeProps.text=t),s.matchesText(t)&&s.matchesDepth(e,(r=a==null?void 0:a.enteredDepth)!=null?r:0)&&!(s.matchCriteria&n.ETokenMatchCriteria.Node)?(this.transitionForward(e),!0):!1)}transitionForward(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState+1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.isFinalState()&&(this._toRecordTokens=this._cachedTokens),this.resetCurrentStateCache()}transitionBack(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState-1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.resetCurrentStateCache()}isFinalState(){return this._currentState!=null&&this._currentState>=this._states.length-1}getOffsetToFinal(){return this._currentState==null?this._states.length:this._states.length-1-this._currentState}resetCurrentStateCache(){this._cachedNodeProps.prefix=null,this._cachedNodeProps.local=null,this._cachedNodeProps.attributes=null,this._cachedNodeProps.text=null,this._cachedTokens=[]}}exports.TokenSelectStateMachine=S;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var a=require("./TokenSelectState.js"),
|
|
1
|
+
"use strict";var a=require("./TokenSelectState.js"),o=require("./TokenSelectStateMachine.js"),u=Object.defineProperty,f=(r,e,t)=>e in r?u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>f(r,typeof e!="symbol"?e+"":e,t);class S{constructor(e){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=e.map(t=>new o.TokenSelectStateMachine(t))}pipeToken(e,t){let n=!1,i=!1;switch(e.type){case"ElementStart":n=this.handleElementStart(e);break;case"Attribute":n=this.handleAttribute(e);break;case"Text":n=this.handleText(e);break;case"ElementEnd":{i=this.handleElementEnd(e);break}}n&&!this._isRecording&&(this._isRecording=!0,t({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(e);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{t(h)})}this._isRecording&&t(e),i&&(t({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(e){this._currentDepth+=1;let t=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Name)||n.transitionIfNameMatch(e.local,e.prefix,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleAttribute(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Attributes)||n.transitionIfAttributesMatch(e.local,e.prefix,e.value,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleText(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Text)||n.transitionIfTextMatch(e.text,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleElementEnd(e){if(e.end.type==="Close"||e.end.type==="Empty"){this._currentDepth-=1;let t=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),t=t||n.isFinalState())}return!t}return!1}}exports.TokenSelector=S;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function r(t,e){if(typeof e=="string")return t===e;switch(e.matchStrategy){case"ANY":return!0;case"EXACT":return t===e.value;case"CONTAINS":return t.includes(e.value);case"STARTS_WITH":return t.startsWith(e.value);case"ENDS_WITH":return t.endsWith(e.value)}}exports.matchString=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=require("../tokenizer/tokenize.js"),l=require("./TokenSelector.js");function s(e,t,n,o){const r=new l.TokenSelector(t);k.tokenize(e,c=>{r.pipeToken(c,i=>{n(i)})},o)}exports.select=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var n=require("./ascii-constants.js"),a=require("./utils.js"),o=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:r=0,strict:i=!0,allowDtd:s=!0}=e;this._text=t,this._pos=r,this._end=this._text.length,this.config={strict:i,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 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)}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}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 o.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 o.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 o.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),r=e.consumeReference();return r!=null?(this._pos+=e.getPos()-t,r):null}consumeReference(){if(!this.tryConsumeCodeUnit(n.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(n.HASH)){let e,r;this.tryConsumeCodeUnit(n.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(s=>s>=n.ZERO&&s<=n.NINE||s>=n.UPPERCASE_A&&s<=n.UPPERCASE_F||s>=n.LOWERCASE_A&&s<=n.LOWERCASE_F),r=16):(e=this.consumeCodeUnitsWhile(s=>a.isAsciiDigit(s)),r=10);const i=parseInt(e,r);isNaN(i)||!a.isXmlChar(i)?t=null:t={type:"Char",value:String.fromCodePoint(i)}}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(n.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(!a.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!a.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const r=this._pos;let i=null;for(;this._pos<this._end;){const d=this.currCodeUnitUnchecked();if(d===n.COLON)if(i==null)i=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));else if(a.isXmlName(d))this._pos+=1;else break}let s,c;if(i!=null?(s=this._text.slice(r,i),c=this.sliceBack(i+1)):(s="",c=this.sliceBack(r)),s.length>0&&!a.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));if(c.length>0){if(!a.isXmlNameStart((e=c[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));return[s,c]}consumeQuote(){const t=this.currCodeUnit();if(t===n.SINGLE_QUOTE||t===n.DOUBLE_QUOTE)return this._pos+=1,t;throw new o.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let r=1,i=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===n.LINE_FEED?(r++,i=1):i++;return{row:r,col:i}}}exports.XmlStream=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=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()===e.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()===e.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 o=t.consumeCodeUnitsWhile((r,i)=>!(r===e.HYPHEN&&i.startsWith(A)));if(t.skipString(A),o.includes("--")||o.endsWith("-"))throw new a.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,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 o=t.consumeName();t.skipSpaces();const r=t.consumeCodeUnitsWhile((i,c)=>!(i===e.QUESTION_MARK&&c.startsWith(k)));t.skipString(k),n({type:"ProcessingInstruction",target:o,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()===e.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()===e.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(o){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!==e.OPEN_SQUARE_BRACKET&&n!==e.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 o=t.consumeQuote();if(t.consumeCodeUnitsWhile(r=>r!==o),t.consumeCodeUnit(o),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(e.PERCENT);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const r=j(t,s);r!==null&&n({type:"EntityDeclaration",name:o,definition:r}),t.skipSpaces(),t.consumeCodeUnit(e.GREATER_THAN)}function j(t,n){const s=t.currCodeUnit();if(s===e.DOUBLE_QUOTE||s===e.SINGLE_QUOTE){const o=t.consumeQuote(),r=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const i=t.sliceBack(r);return t.consumeCodeUnit(o),i}else if(s===e.UPPERCASE_S||s===e.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!==e.GREATER_THAN),t.consumeCodeUnit(e.GREATER_THAN)}function S(t,n){const s=t.getPos();t.advance(1);const[o,r]=t.consumeQName();n({type:"ElementStart",prefix:o,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===e.SLASH){t.advance(1),t.consumeCodeUnit(e.GREATER_THAN);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Empty"},range:d});break}else if(T===e.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,N,v]=p(t),x=t.getPos();n({type:"Attribute",range:{start:u,end:x},prefix:d,local:N,value:v})}}i&&V(t,n)}function p(t){const[n,s]=t.consumeQName();let o;const r=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(e.EQUALS)){t.skipSpaces();const i=t.consumeQuote();o=t.consumeCodeUnitsWhile(c=>c!==i&&c!==e.LESS_THAN),t.consumeCodeUnit(i)}else{if(t.config.strict)throw new a.XmlError({type:"InvalidChar",expected:e.EQUALS,actual:t.currCodeUnit()},t.genTextPos());t.goTo(r),o="true"}return[n,s,o]}function V(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===e.LESS_THAN){const s=t.nextCodeUnit();if(s===e.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===e.QUESTION_MARK)h(t,n);else if(s===e.SLASH){$(t,n);break}else S(t,n)}else y(t,n)}function Z(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((i,c)=>!(i===e.CLOSE_SQUARE_BRACKET&&c.startsWith(E)));t.skipString(E);const r=t.rangeFrom(s);n({type:"Cdata",text:o,range:r})}function $(t,n){const s=t.getPos();t.advance(2);const[o,r]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(e.GREATER_THAN);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:r},range:i})}function y(t,n){const s=t.getPos(),o=t.consumeCodeUnitsWhile(r=>r!==e.LESS_THAN);if(o.includes(E))throw new a.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}exports.tokenize=M,exports.tokenizeXmlStream=P;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var i=require("./ascii-constants.js");function
|
|
1
|
+
"use strict";var i=require("./ascii-constants.js");function n(E){return E>=i.ZERO&&E<=i.NINE}function s(E){return E==null?!1:E<=128?E>=i.UPPERCASE_A&&E<=i.UPPERCASE_Z||E>=i.LOWERCASE_A&&E<=i.LOWERCASE_Z||E===i.COLON||E===i.UNDERSCORE:E>=192&&E<=214||E>=216&&E<=246||E>=248&&E<=767||E>=880&&E<=893||E>=895&&E<=8191||E>=8204&&E<=8205||E>=8304&&E<=8591||E>=11264&&E<=12271||E>=12289&&E<=55295||E>=63744&&E<=64975||E>=65008&&E<=65533||E>=65536&&E<=983039}function r(E){return E==null?!1:E<=128?e(E):E===183||E>=192&&E<=214||E>=216&&E<=246||E>=248&&E<=767||E>=768&&E<=879||E>=880&&E<=893||E>=895&&E<=8191||E>=8204&&E<=8205||E>=8255&&E<=8256||E>=8304&&E<=8591||E>=11264&&E<=12271||E>=12289&&E<=55295||E>=63744&&E<=64975||E>=65008&&E<=65533||E>=65536&&E<=983039}function R(E){return E==null?!1:E<32?t(E):E!==65535&&E!==65534}function t(E){return E===i.SPACE||E===i.HORIZONTAL_TAB||E===i.LINE_FEED||E===i.CARRIAGE_RETURN}function e(E){return E>=i.ZERO&&E<=i.NINE||E>=i.UPPERCASE_A&&E<=i.UPPERCASE_Z||E>=i.LOWERCASE_A&&E<=i.LOWERCASE_Z||E===i.COLON||E===i.UNDERSCORE||E===i.HYPHEN||E===i.PERIOD}exports.isAsciiDigit=n,exports.isXmlChar=R,exports.isXmlName=r,exports.isXmlNameByte=e,exports.isXmlNameStart=s,exports.isXmlSpaceByte=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=require("./tokenizer/tokenize.js");function s(t,
|
|
1
|
+
"use strict";var r=require("./tokenizer/tokenize.js");function s(t,n={}){const e={local:"root",attributes:[],content:[]},o=[e];return r.tokenize(t,l=>{c(l,o)},n),e.content[0]}function c(t,n){switch(t.type){case"ElementStart":{const e={local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,attributes:[],content:[]},o=n[n.length-1];o!=null&&o.content.push(e),n.push(e);break}case"ElementEnd":{(t.end.type==="Close"||t.end.type==="Empty")&&n.pop();break}case"Attribute":{const e=n[n.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=n[n.length-1];e!=null&&t.text.trim().length>0&&e.content.push(t.text);break}}}exports.processTokenForObject=c,exports.xmlToObject=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{matchString as
|
|
1
|
+
import{matchString as s}from"./match-string.js";var m=Object.defineProperty,p=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t,r)=>p(e,typeof t!="symbol"?t+"":t,r);class _{constructor(t){a(this,"_segment"),a(this,"_matchCriteria",0),a(this,"_toCacheNodeProps",0),a(this,"_enteredDepth",null),this._segment=t,this.applyLevels()}get matchCriteria(){return this._matchCriteria}get toCacheNodeProps(){return this._toCacheNodeProps}get enteredDepth(){return this._enteredDepth}applyLevels(){let t=0,r=0;(this._segment.local!=null||this._segment.prefix!=null)&&(t|=1),this._segment.attributes!=null&&(t|=2,r|=2),this._segment.text!=null&&(t|=4),this._matchCriteria=t,this._toCacheNodeProps=r}matchesName(t,r){return(this._segment.local==null||s(t,this._segment.local))&&(this._segment.prefix==null||s(r,this._segment.prefix))}matchesAttributes(t){if(this._segment.attributes==null)return!0;for(const r of this._segment.attributes){let n=!1;for(const i of t){const u=r.local==null||s(i.local,r.local),o=r.value==null||i.value!=null&&s(i.value,r.value),c=r.prefix==null||i.prefix!=null&&s(i.prefix,r.prefix);if(u&&o&&c){n=!0;break}}if(!n)return!1}return!0}matchesText(t){return this._segment.text==null||s(t,this._segment.text)}matchesDepth(t,r){switch(this._segment.axis){case"child":return t===r+1;case"self-or-descendant":return t>=r}}match(t){this._enteredDepth=t}unmatch(){this._enteredDepth=null}}var l=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e))(l||{}),h=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e[e.Node=8]="Node",e))(h||{});export{l as EToCacheNodeProps,h as ETokenMatchCriteria,_ as TokenSelectState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{TokenSelectState as _,EToCacheNodeProps as u,ETokenMatchCriteria as h}from"./TokenSelectState.js";var S=Object.defineProperty,p=(n,t,e)=>t in n?S(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t,e)=>p(n,typeof t!="symbol"?t+"":t,e);class
|
|
1
|
+
import{TokenSelectState as _,EToCacheNodeProps as u,ETokenMatchCriteria as h}from"./TokenSelectState.js";var S=Object.defineProperty,p=(n,t,e)=>t in n?S(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t,e)=>p(n,typeof t!="symbol"?t+"":t,e);class f{constructor(t){c(this,"_states"),c(this,"_currentState",null),c(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),c(this,"_cachedTokens",[]),c(this,"_toRecordTokens",[]),this._states=t.map(e=>new _(e))}getNextState(){var t;const e=this._currentState!=null?this._currentState+1:0;return e<this._states.length&&(t=this._states[e])!=null?t:null}getCurrentState(){var t;return this._currentState!=null&&this._currentState<this._states.length&&(t=this._states[this._currentState])!=null?t:null}record(t){this.getOffsetToFinal()<=1&&this._cachedTokens.push(t)}takeRecordedTokens(){if(this._toRecordTokens.length>0){const t=this._toRecordTokens;return this._toRecordTokens=[],t}return null}transitionIfNameMatch(t,e,r){var s;const a=this.getNextState(),i=this.getCurrentState();return a==null?!1:(a.toCacheNodeProps&u.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),a.matchesName(t,e)&&a.matchesDepth(r,(s=i==null?void 0:i.enteredDepth)!=null?s:0)&&!(a.matchCriteria&(h.Attributes|h.Text|h.Node))?(this.transitionForward(r),!0):!1)}transitionIfAttributesMatch(t,e,r,s){var a,i;const l=this.getNextState(),d=this.getCurrentState();if(l==null)return!1;const o=(a=this._cachedNodeProps.attributes)!=null?a:[];return o.push({local:t,prefix:e,value:r}),l.toCacheNodeProps&u.Attributes&&(this._cachedNodeProps.attributes=o),l.matchesAttributes(o)&&l.matchesDepth(s,(i=d==null?void 0:d.enteredDepth)!=null?i:0)&&!(l.matchCriteria&(h.Text|h.Node))?(this.transitionForward(s),!0):!1}transitionIfTextMatch(t,e){var r;const s=this.getNextState(),a=this.getCurrentState();return s==null?!1:(s.toCacheNodeProps&u.Text&&(this._cachedNodeProps.text=t),s.matchesText(t)&&s.matchesDepth(e,(r=a==null?void 0:a.enteredDepth)!=null?r:0)&&!(s.matchCriteria&h.Node)?(this.transitionForward(e),!0):!1)}transitionForward(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState+1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.isFinalState()&&(this._toRecordTokens=this._cachedTokens),this.resetCurrentStateCache()}transitionBack(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState-1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.resetCurrentStateCache()}isFinalState(){return this._currentState!=null&&this._currentState>=this._states.length-1}getOffsetToFinal(){return this._currentState==null?this._states.length:this._states.length-1-this._currentState}resetCurrentStateCache(){this._cachedNodeProps.prefix=null,this._cachedNodeProps.local=null,this._cachedNodeProps.attributes=null,this._cachedNodeProps.text=null,this._cachedTokens=[]}}export{f as TokenSelectStateMachine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ETokenMatchCriteria as a}from"./TokenSelectState.js";import{TokenSelectStateMachine as
|
|
1
|
+
import{ETokenMatchCriteria as a}from"./TokenSelectState.js";import{TokenSelectStateMachine as o}from"./TokenSelectStateMachine.js";var u=Object.defineProperty,f=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,s=(r,t,e)=>f(r,typeof t!="symbol"?t+"":t,e);class p{constructor(t){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=t.map(e=>new o(e))}pipeToken(t,e){let n=!1,i=!1;switch(t.type){case"ElementStart":n=this.handleElementStart(t);break;case"Attribute":n=this.handleAttribute(t);break;case"Text":n=this.handleText(t);break;case"ElementEnd":{i=this.handleElementEnd(t);break}}n&&!this._isRecording&&(this._isRecording=!0,e({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(t);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{e(h)})}this._isRecording&&e(t),i&&(e({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(t){this._currentDepth+=1;let e=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Name)||n.transitionIfNameMatch(t.local,t.prefix,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleAttribute(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Attributes)||n.transitionIfAttributesMatch(t.local,t.prefix,t.value,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleText(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Text)||n.transitionIfTextMatch(t.text,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleElementEnd(t){if(t.end.type==="Close"||t.end.type==="Empty"){this._currentDepth-=1;let e=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),e=e||n.isFinalState())}return!e}return!1}}export{p as TokenSelector};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function r(t,e){if(typeof e=="string")return t===e;switch(e.matchStrategy){case"ANY":return!0;case"EXACT":return t===e.value;case"CONTAINS":return t.includes(e.value);case"STARTS_WITH":return t.startsWith(e.value);case"ENDS_WITH":return t.endsWith(e.value)}}export{r as matchString};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tokenize as
|
|
1
|
+
import{tokenize as c}from"../tokenizer/tokenize.js";import{TokenSelector as m}from"./TokenSelector.js";function f(e,o,t,n){const r=new m(o);c(e,i=>{r.pipeToken(i,p=>{t(p)})},n)}export{f as select};
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 P,LOWERCASE_F as E,SEMICOLON as k,COLON as v,SINGLE_QUOTE as S,DOUBLE_QUOTE as N,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as d,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(!d(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>=P&&s<=E),i=16):(e=this.consumeCodeUnitsWhile(s=>T(s)),i=10);const n=parseInt(e,i);isNaN(n)||!d(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(k)?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 u=this.currCodeUnitUnchecked();if(u===v)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(i));else if(_(u))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
|
-
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
|
|
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 et(t,n,s={}){A(new Y(t,s),n)}function A(t,n){if(t.startsWith(X)&&t.advance(1),t.startsWith(w)&&ot(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 ot(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 e=t.consumeCodeUnitsWhile((o,i)=>!(o===D&&i.startsWith(x)));if(t.skipString(x),e.includes("--")||e.endsWith("-"))throw new a({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,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 e=t.consumeName();t.skipSpaces();const o=t.consumeCodeUnitsWhile((i,c)=>!(i===U&&c.startsWith(y)));t.skipString(y),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,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(e){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 e=t.consumeQuote();if(t.consumeCodeUnitsWhile(o=>o!==e),t.consumeCodeUnit(e),s===v){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o)}return!0}return!1}function ct(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(O);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=rt(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o}),t.skipSpaces(),t.consumeCodeUnit(r)}function rt(t,n){const s=t.currCodeUnit();if(s===R||s===b){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const i=t.sliceBack(o);return t.consumeCodeUnit(e),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[e,o]=t.consumeQName();n({type:"ElementStart",prefix:e,local:o,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 e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(T)){t.skipSpaces();const i=t.consumeQuote();e=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(o),e="true"}return[n,s,e]}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 e=t.consumeCodeUnitsWhile((i,c)=>!(i===K&&c.startsWith(h)));t.skipString(h);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o})}function lt(t,n){const s=t.getPos();t.advance(2);const[e,o]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:o},range:i})}function I(t,n){const s=t.getPos(),e=t.consumeCodeUnitsWhile(o=>o!==d);if(e.includes(h))throw new a({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:e,range:t.rangeFrom(s)})}export{et as tokenize,A as tokenizeXmlStream};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ZERO as E,NINE as t,UPPERCASE_A as i,UPPERCASE_Z as r,LOWERCASE_A as
|
|
1
|
+
import{ZERO as E,NINE as t,UPPERCASE_A as i,UPPERCASE_Z as r,LOWERCASE_A as e,LOWERCASE_Z as u,COLON as l,UNDERSCORE as R,SPACE as m,HORIZONTAL_TAB as s,LINE_FEED as a,CARRIAGE_RETURN as o,HYPHEN as C,PERIOD as O}from"./ascii-constants.js";function c(n){return n>=E&&n<=t}function S(n){return n==null?!1:n<=128?n>=i&&n<=r||n>=e&&n<=u||n===l||n===R:n>=192&&n<=214||n>=216&&n<=246||n>=248&&n<=767||n>=880&&n<=893||n>=895&&n<=8191||n>=8204&&n<=8205||n>=8304&&n<=8591||n>=11264&&n<=12271||n>=12289&&n<=55295||n>=63744&&n<=64975||n>=65008&&n<=65533||n>=65536&&n<=983039}function P(n){return n==null?!1:n<=128?N(n):n===183||n>=192&&n<=214||n>=216&&n<=246||n>=248&&n<=767||n>=768&&n<=879||n>=880&&n<=893||n>=895&&n<=8191||n>=8204&&n<=8205||n>=8255&&n<=8256||n>=8304&&n<=8591||n>=11264&&n<=12271||n>=12289&&n<=55295||n>=63744&&n<=64975||n>=65008&&n<=65533||n>=65536&&n<=983039}function _(n){return n==null?!1:n<32?A(n):n!==65535&&n!==65534}function A(n){return n===m||n===s||n===a||n===o}function N(n){return n>=E&&n<=t||n>=i&&n<=r||n>=e&&n<=u||n===l||n===R||n===C||n===O}export{c as isAsciiDigit,_ as isXmlChar,P as isXmlName,N as isXmlNameByte,S as isXmlNameStart,A as isXmlSpaceByte};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tokenize as c}from"./tokenizer/tokenize.js";function a(t,
|
|
1
|
+
import{tokenize as c}from"./tokenizer/tokenize.js";function a(t,n={}){const e={local:"root",attributes:[],content:[]},l=[e];return c(t,r=>{o(r,l)},n),e.content[0]}function o(t,n){switch(t.type){case"ElementStart":{const e={local:t.local,prefix:t.prefix.length>0?t.prefix:void 0,attributes:[],content:[]},l=n[n.length-1];l!=null&&l.content.push(e),n.push(e);break}case"ElementEnd":{(t.end.type==="Close"||t.end.type==="Empty")&&n.pop();break}case"Attribute":{const e=n[n.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=n[n.length-1];e!=null&&t.text.trim().length>0&&e.content.push(t.text);break}}}export{o as processTokenForObject,a as xmlToObject};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { TXmlStreamOptions } from '../tokenizer';
|
|
1
2
|
import { type TSelectedTokenCallback, type TTokenSelectPath } from './types';
|
|
2
|
-
export declare function select(xml: string, tokenSelectPaths: TTokenSelectPath[], callback: TSelectedTokenCallback): void;
|
|
3
|
+
export declare function select(xml: string, tokenSelectPaths: TTokenSelectPath[], callback: TSelectedTokenCallback, options?: TXmlStreamOptions): void;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xml-tokenizer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
|
|
6
6
|
"keywords": [],
|
|
7
7
|
"homepage": "https://builder.group/?source=package-json",
|
|
8
8
|
"bugs": {
|
|
9
|
-
"url": "https://github.com/builder-group/
|
|
9
|
+
"url": "https://github.com/builder-group/community/issues"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/builder-group/
|
|
13
|
+
"url": "https://github.com/builder-group/community.git"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"author": "@bennobuilder",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"saxen": "^10.0.0",
|
|
33
33
|
"txml": "^5.1.1",
|
|
34
34
|
"xml2js": "^0.6.2",
|
|
35
|
-
"@blgc/config": "0.0.
|
|
35
|
+
"@blgc/config": "0.0.28"
|
|
36
36
|
},
|
|
37
37
|
"size-limit": [
|
|
38
38
|
{
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"bench": "vitest bench",
|
|
44
44
|
"build": "shx rm -rf dist && chmod +x ../../scripts/cli.sh && ../../scripts/cli.sh bundle",
|
|
45
45
|
"build:prod": "pnpm build -t prod",
|
|
46
|
-
"clean": "shx rm -rf dist && shx rm -rf
|
|
46
|
+
"clean": "shx rm -rf dist && shx rm -rf .turbo && shx rm -rf node_modules",
|
|
47
47
|
"install:clean": "pnpm run clean && pnpm install",
|
|
48
48
|
"lint": "eslint . --fix",
|
|
49
49
|
"publish:patch": "pnpm build:prod && pnpm version patch && pnpm publish --no-git-checks --access=public",
|