xml-tokenizer 0.0.4 → 0.0.6
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 +8 -1
- package/dist/cjs/get-q-name.js +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/selector/TokenSelectState.js +1 -0
- package/dist/cjs/selector/TokenSelectStateMachine.js +1 -0
- package/dist/cjs/selector/TokenSelector.js +1 -0
- package/dist/cjs/selector/select.js +1 -0
- package/dist/cjs/tokenizer/XmlStream.js +1 -1
- package/dist/cjs/tokenizer/tokenize.js +1 -0
- package/dist/cjs/tokens-to-xml.js +1 -0
- package/dist/cjs/xml-to-object.js +1 -1
- package/dist/esm/get-q-name.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/selector/TokenSelectState.js +1 -0
- package/dist/esm/selector/TokenSelectStateMachine.js +1 -0
- package/dist/esm/selector/TokenSelector.js +1 -0
- package/dist/esm/selector/select.js +1 -0
- package/dist/esm/tokenizer/XmlStream.js +1 -1
- package/dist/esm/tokenizer/tokenize.js +1 -0
- package/dist/esm/tokens-to-xml.js +1 -0
- package/dist/esm/xml-to-object.js +1 -1
- package/dist/types/get-q-name.d.ts +2 -0
- package/dist/types/get-q-name.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/selector/TokenSelectState.d.ts +32 -0
- package/dist/types/selector/TokenSelectState.d.ts.map +1 -0
- package/dist/types/selector/TokenSelectStateMachine.d.ts +25 -0
- package/dist/types/selector/TokenSelectStateMachine.d.ts.map +1 -0
- package/dist/types/selector/TokenSelector.d.ts +15 -0
- package/dist/types/selector/TokenSelector.d.ts.map +1 -0
- package/dist/types/selector/index.d.ts +6 -0
- package/dist/types/selector/index.d.ts.map +1 -0
- package/dist/types/selector/select.d.ts +4 -0
- package/dist/types/selector/select.d.ts.map +1 -0
- package/dist/types/selector/types.d.ts +65 -0
- package/dist/types/selector/types.d.ts.map +1 -0
- package/dist/types/tokenizer/XmlStream.d.ts +6 -4
- package/dist/types/tokenizer/XmlStream.d.ts.map +1 -1
- package/dist/types/tokenizer/index.d.ts +1 -1
- package/dist/types/tokenizer/index.d.ts.map +1 -1
- package/dist/types/tokenizer/tokenize.d.ts +12 -0
- package/dist/types/tokenizer/tokenize.d.ts.map +1 -0
- package/dist/types/tokenizer/types.d.ts +2 -2
- package/dist/types/tokens-to-xml.d.ts +4 -0
- package/dist/types/tokens-to-xml.d.ts.map +1 -0
- package/dist/types/xml-to-object.d.ts +0 -1
- package/dist/types/xml-to-object.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/parse-string.js +0 -1
- package/dist/cjs/tokenizer/tokenizer.js +0 -1
- package/dist/esm/parse-string.js +0 -1
- package/dist/esm/tokenizer/tokenizer.js +0 -1
- package/dist/types/parse-string.d.ts +0 -3
- package/dist/types/parse-string.d.ts.map +0 -1
- package/dist/types/tokenizer/tokenizer.d.ts +0 -11
- package/dist/types/tokenizer/tokenizer.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -82,6 +82,13 @@ The following token types are supported:
|
|
|
82
82
|
- **Text**: Text content between elements, including whitespace.
|
|
83
83
|
- **Cdata**: `<![CDATA[text]]>`
|
|
84
84
|
|
|
85
|
+
## 👀 Differences from [XML 1.0 Specification](https://www.w3.org/TR/xml/)
|
|
86
|
+
|
|
87
|
+
- **Attribute Value Handling:**
|
|
88
|
+
- **XML 1.0:** Attributes must be explicitly assigned a value in the format `Name="Value"`. An attribute without a value is not valid XML.
|
|
89
|
+
- **Parser Behavior:** Attributes without an explicit value are interpreted as `true` (e.g., `<element attribute/>` is parsed as `attribute="true"`).
|
|
90
|
+
- **Reason**: This behavior aligns with HTML-style parsing, which was necessary to handle HTML attributes without explicit values.
|
|
91
|
+
|
|
85
92
|
## 🚀 Benchmark
|
|
86
93
|
|
|
87
94
|
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.
|
|
@@ -128,7 +135,7 @@ The `roxmltree` package with the Rust implementation can be found in the `_depre
|
|
|
128
135
|
| roxmltree:wasmMix | 28.17 | 34.83 | 36.71 | 35.49 | ±0.91% |
|
|
129
136
|
| roxmltree:wasm | 109.30 | 8.30 | 13.16 | 9.15 | ±3.31% |
|
|
130
137
|
|
|
131
|
-
### Why
|
|
138
|
+
### Why ported `tokenizer.rs` to TypeScript?
|
|
132
139
|
|
|
133
140
|
We ported [`tokenizer.rs`](https://github.com/RazrFalcon/roxmltree/blob/master/src/tokenizer.rs) to TypeScript because frequent communication between Rust and TypeScript negated Rust's performance benefits. The stream architecture required constant interaction between Rust and TypeScript via the `tokenCallback`, reducing overall efficiency.
|
|
134
141
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function l(t,e=null){return e!=null&&e.length>0?`${e}:${t}`:t}exports.getQName=l;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=require("./selector/select.js"),r=require("./selector/TokenSelector.js"),E=require("./selector/TokenSelectState.js"),R=require("./selector/TokenSelectStateMachine.js"),S=require("./tokenizer/tokenize.js"),e=require("./tokenizer/utils.js"),T=require("./tokenizer/XmlError.js"),i=require("./tokenizer/XmlStream.js"),A=require("./tokens-to-xml.js"),a=require("./xml-to-object.js");exports.select=t.select,exports.TokenSelector=r.TokenSelector,exports.EToCacheNodeProps=E.EToCacheNodeProps,exports.ETokenMatchCriteria=E.ETokenMatchCriteria,exports.TokenSelectState=E.TokenSelectState,exports.TokenSelectStateMachine=R.TokenSelectStateMachine,exports.tokenize=S.tokenize,exports.tokenizeXmlStream=S.tokenizeXmlStream,exports.AMPERSAND=e.AMPERSAND,exports.CARRIAGE_RETURN=e.CARRIAGE_RETURN,exports.COLON=e.COLON,exports.DOUBLE_QUOTE=e.DOUBLE_QUOTE,exports.EQUALS=e.EQUALS,exports.EXCLAMATION_MARK=e.EXCLAMATION_MARK,exports.GREATER_THAN=e.GREATER_THAN,exports.HASH=e.HASH,exports.HORIZONTAL_TAB=e.HORIZONTAL_TAB,exports.HYPHEN=e.HYPHEN,exports.LESS_THAN=e.LESS_THAN,exports.LINE_FEED=e.LINE_FEED,exports.LOWERCASE_A=e.LOWERCASE_A,exports.LOWERCASE_F=e.LOWERCASE_F,exports.LOWERCASE_X=e.LOWERCASE_X,exports.LOWERCASE_Z=e.LOWERCASE_Z,exports.NINE=e.NINE,exports.OPEN_BRACKET=e.OPEN_BRACKET,exports.PERCENT=e.PERCENT,exports.PERIOD=e.PERIOD,exports.QUESTION_MARK=e.QUESTION_MARK,exports.SEMICOLON=e.SEMICOLON,exports.SINGLE_QUOTE=e.SINGLE_QUOTE,exports.SLASH=e.SLASH,exports.SPACE=e.SPACE,exports.UNDERSCORE=e.UNDERSCORE,exports.UPPERCASE_A=e.UPPERCASE_A,exports.UPPERCASE_F=e.UPPERCASE_F,exports.UPPERCASE_P=e.UPPERCASE_P,exports.UPPERCASE_S=e.UPPERCASE_S,exports.UPPERCASE_Z=e.UPPERCASE_Z,exports.ZERO=e.ZERO,exports.isAsciiDigit=e.isAsciiDigit,exports.isXmlChar=e.isXmlChar,exports.isXmlName=e.isXmlName,exports.isXmlNameByte=e.isXmlNameByte,exports.isXmlNameStart=e.isXmlNameStart,exports.isXmlSpaceByte=e.isXmlSpaceByte,exports.XmlError=T.XmlError,exports.XmlStream=i.XmlStream,exports.tokenToXml=A.tokenToXml,exports.tokensToXml=A.tokensToXml,exports.xmlToObject=a.xmlToObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=require("../get-q-name.js"),n=Object.defineProperty,o=(t,e,a)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a,r=(t,e,a)=>o(t,typeof e!="symbol"?e+"":e,a);class c{constructor(e){r(this,"_part"),r(this,"_matchCriteria",0),r(this,"_toCacheNodeProps",0),r(this,"_enteredDepth",null),this._part=e,this.applyLevels()}get matchCriteria(){return this._matchCriteria}get toCacheNodeProps(){return this._toCacheNodeProps}get enteredDepth(){return this._enteredDepth}applyLevels(){let e=0,a=0;(this._part.local!=null||this._part.prefix!=null)&&(e|=1),this._part.attributes!=null&&(e|=2,a|=2),this._part.textContains!=null&&(e|=4),this._part.predicate!=null&&(e|=8,a|=7),this._matchCriteria=e,this._toCacheNodeProps=a}matchesName(e,a){return(this._part.local==null||this._part.local==="*"||this._part.local===e)&&(this._part.prefix==null||this._part.prefix===a)}matchesAttributes(e){if(this._part.attributes!=null)for(const a of this._part.attributes){const s=l.getQName(a.local,a.prefix);if(!(s in e)||a.value!=null&&e[s]!==a.value)return!1}return!0}matchesText(e){return this._part.textContains==null||e.includes(this._part.textContains)}matchesDepth(e,a){switch(this._part.axis){case"child":return e===a+1;case"self-or-descendant":return e>=a}}match(e){this._enteredDepth=e}unmatch(){this._enteredDepth=null}}var i=(t=>(t[t.None=0]="None",t[t.Name=1]="Name",t[t.Attributes=2]="Attributes",t[t.Text=4]="Text",t))(i||{}),h=(t=>(t[t.None=0]="None",t[t.Name=1]="Name",t[t.Attributes=2]="Attributes",t[t.Text=4]="Text",t[t.Node=8]="Node",t))(h||{});exports.EToCacheNodeProps=i,exports.ETokenMatchCriteria=h,exports.TokenSelectState=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=require("../get-q-name.js"),s=require("./TokenSelectState.js"),_=Object.defineProperty,C=(o,t,e)=>t in o?_(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,i=(o,t,e)=>C(o,typeof t!="symbol"?t+"":t,e);class p{constructor(t){i(this,"_states"),i(this,"_currentState",null),i(this,"_hasActiveCache",!1),i(this,"_toCacheNodeProps",s.EToCacheNodeProps.None),i(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),i(this,"_cachedTokens",[]),i(this,"_toRecordTokens",[]),this._states=t.map(e=>new s.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._hasActiveCache&&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 a;const h=this.getNextState(),n=this.getCurrentState();return h!=null&&h.matchesName(t,e)&&h.matchesDepth(r,(a=n==null?void 0:n.enteredDepth)!=null?a:0)?h.matchCriteria&(s.ETokenMatchCriteria.Attributes|s.ETokenMatchCriteria.Text|s.ETokenMatchCriteria.Node)?(this._hasActiveCache=!0,this._toCacheNodeProps|=h.toCacheNodeProps,this._toCacheNodeProps&s.EToCacheNodeProps.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),!1):(this.transitionForward(r),!0):!1}transitionIfAttributesMatch(t,e,r,a){var h,n;const c=this.getNextState(),u=this.getCurrentState(),l=(h=this._cachedNodeProps.attributes)!=null?h:{};return l[d.getQName(t,e)]=r,c!=null&&c.matchesAttributes(l)&&c.matchesDepth(a,(n=u==null?void 0:u.enteredDepth)!=null?n:0)?c.matchCriteria&(s.ETokenMatchCriteria.Text|s.ETokenMatchCriteria.Node)?(this._hasActiveCache=!0,this._toCacheNodeProps|=c.toCacheNodeProps,this._toCacheNodeProps&s.EToCacheNodeProps.Attributes&&(this._cachedNodeProps.attributes=l),!1):(this.transitionForward(a),!0):!1}transitionIfTextMatch(t,e){var r;const a=this.getNextState(),h=this.getCurrentState();return a!=null&&a.matchesText(t)&&a.matchesDepth(e,(r=h==null?void 0:h.enteredDepth)!=null?r:0)?a.matchCriteria&s.ETokenMatchCriteria.Node?(this._hasActiveCache=!0,this._toCacheNodeProps|=a.toCacheNodeProps,this._toCacheNodeProps&s.EToCacheNodeProps.Text&&(this._cachedNodeProps.text=t),!1):(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}resetCurrentStateCache(){this._hasActiveCache=!1,this._toCacheNodeProps=s.EToCacheNodeProps.None,this._cachedNodeProps.prefix=null,this._cachedNodeProps.local=null,this._cachedNodeProps.attributes=null,this._cachedNodeProps.text=null,this._cachedTokens=[]}}exports.TokenSelectStateMachine=p;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=require("./TokenSelectState.js"),l=require("./TokenSelectStateMachine.js"),u=Object.defineProperty,S=(r,t,i)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,s=(r,t,i)=>S(r,typeof t!="symbol"?t+"":t,i);class p{constructor(t){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=t.map(i=>new l.TokenSelectStateMachine(i))}pipeToken(t,i){let e=!1,n=!1;switch(t.type){case"ElementStart":e=this.handleElementStart(t);break;case"Attribute":e=this.handleAttribute(t);break;case"Text":e=this.handleText(t);break;case"ElementEnd":{n=this.handleElementEnd(t);break}}e&&!this._isRecording&&this.record();for(const c of this._tspStateMachines){c.record(t);const h=c.takeRecordedTokens();h!=null&&h.forEach(o=>{i(o)})}this._isRecording&&i(t),n&&(this._isRecording=!1)}handleElementStart(t){this._currentDepth+=1;let i=!1;for(const e of this._tspStateMachines){if(e.resetCurrentStateCache(),e.isFinalState())continue;const n=e.getNextState();n==null||!(n.matchCriteria&a.ETokenMatchCriteria.Name)||e.transitionIfNameMatch(t.local,t.prefix,this._currentDepth)&&e.isFinalState()&&(i=!0)}return i}handleAttribute(t){let i=!1;for(const e of this._tspStateMachines){if(e.isFinalState())continue;const n=e.getNextState();n==null||!(n.matchCriteria&a.ETokenMatchCriteria.Attributes)||e.transitionIfAttributesMatch(t.local,t.prefix,t.value,this._currentDepth)&&e.isFinalState()&&(i=!0)}return i}handleText(t){let i=!1;for(const e of this._tspStateMachines){if(e.isFinalState())continue;const n=e.getNextState();n==null||!(n.matchCriteria&a.ETokenMatchCriteria.Text)||e.transitionIfTextMatch(t.text,this._currentDepth)&&e.isFinalState()&&(i=!0)}return i}handleElementEnd(t){if(t.end.type==="Close"||t.end.type==="Empty"){this._currentDepth-=1;let i=!1;for(const e of this._tspStateMachines){const n=e.getCurrentState();n!=null&&(n.enteredDepth!=null&&this._currentDepth<n.enteredDepth&&e.transitionBack(this._currentDepth),i=i||e.isFinalState())}return!i}return!1}record(){this._isRecording=!0}}exports.TokenSelector=p;
|
|
@@ -0,0 +1 @@
|
|
|
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,!1,r=>{o.pipeToken(r,c=>{t(c)})})}exports.select=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=require("./utils.js"),o=require("./XmlError.js"),u=Object.defineProperty,m=(h,t,e)=>t in h?u(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,l=(h,t,e)=>m(h,typeof t!="symbol"?t+"":t,e);class c{constructor(t,e=0){l(this,"_text"),l(this,"_pos"),l(this,"_end"),this._text=t,this._pos=e,this._end=this._text.length}clone(){return new c(this._text,this._pos)}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}advance(t){this._pos+=t}startsWith(t){return this._text.startsWith(t,this._pos)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}skipString(t){if(!this.startsWith(t))throw new o.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked());)this._pos+=1}consumeCharsWhile(t){const e=this._pos;return this.skipCharsWhile(t),this.sliceBack(e)}skipCharsWhile(t){for(;this._pos<this._end;){const e=this._text[this._pos];if(e==null||!s.isXmlChar(e.codePointAt(0)))throw new o.XmlError({type:"NonXmlChar",char:e!=null?e:"\uFFFD"},this.genTextPos());if(t(this,e))this._pos+=e.length;else break}}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&s.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),r=e.consumeReference();return r!=null?(this._pos+=e.getPos()-t,r):null}consumeReference(){if(!this.tryConsumeCodeUnit(s.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(s.HASH)){let e,r;this.tryConsumeCodeUnit(s.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(i=>i>=s.ZERO&&i<=s.NINE||i>=s.UPPERCASE_A&&i<=s.UPPERCASE_F||i>=s.LOWERCASE_A&&i<=s.LOWERCASE_F),r=16):(e=this.consumeCodeUnitsWhile(i=>s.isAsciiDigit(i)),r=10);const n=parseInt(e,r);isNaN(n)||!s.isXmlChar(n)?t=null:t={type:"Char",value:String.fromCodePoint(n)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(s.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!s.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!s.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const r=this._pos;let n=null;for(;this._pos<this._end;){const p=this.currCodeUnitUnchecked();if(p===s.COLON)if(n==null)n=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));else if(s.isXmlName(p))this._pos+=1;else break}let i,a;if(n!=null?(i=this._text.slice(r,n),a=this.sliceBack(n+1)):(i="",a=this.sliceBack(r)),i.length>0&&!s.isXmlNameStart((t=i[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));if(a.length>0){if(!s.isXmlNameStart((e=a[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));return[i,a]}
|
|
1
|
+
"use strict";var s=require("./utils.js"),o=require("./XmlError.js"),u=Object.defineProperty,m=(h,t,e)=>t in h?u(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,l=(h,t,e)=>m(h,typeof t!="symbol"?t+"":t,e);class c{constructor(t,e=0){l(this,"_text"),l(this,"_pos"),l(this,"_end"),this._text=t,this._pos=e,this._end=this._text.length}clone(){return new c(this._text,this._pos)}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}skipString(t){if(!this.startsWith(t))throw new o.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked());)this._pos+=1}consumeCharsWhile(t){const e=this._pos;return this.skipCharsWhile(t),this.sliceBack(e)}skipCharsWhile(t){for(;this._pos<this._end;){const e=this._text[this._pos];if(e==null||!s.isXmlChar(e.codePointAt(0)))throw new o.XmlError({type:"NonXmlChar",char:e!=null?e:"\uFFFD"},this.genTextPos());if(t(this,e))this._pos+=e.length;else break}}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&s.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),r=e.consumeReference();return r!=null?(this._pos+=e.getPos()-t,r):null}consumeReference(){if(!this.tryConsumeCodeUnit(s.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(s.HASH)){let e,r;this.tryConsumeCodeUnit(s.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(i=>i>=s.ZERO&&i<=s.NINE||i>=s.UPPERCASE_A&&i<=s.UPPERCASE_F||i>=s.LOWERCASE_A&&i<=s.LOWERCASE_F),r=16):(e=this.consumeCodeUnitsWhile(i=>s.isAsciiDigit(i)),r=10);const n=parseInt(e,r);isNaN(n)||!s.isXmlChar(n)?t=null:t={type:"Char",value:String.fromCodePoint(n)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(s.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!s.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!s.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const r=this._pos;let n=null;for(;this._pos<this._end;){const p=this.currCodeUnitUnchecked();if(p===s.COLON)if(n==null)n=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));else if(s.isXmlName(p))this._pos+=1;else break}let i,a;if(n!=null?(i=this._text.slice(r,n),a=this.sliceBack(n+1)):(i="",a=this.sliceBack(r)),i.length>0&&!s.isXmlNameStart((t=i[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));if(a.length>0){if(!s.isXmlNameStart((e=a[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));return[i,a]}consumeQuote(){const t=this.currCodeUnit();if(t===s.SINGLE_QUOTE||t===s.DOUBLE_QUOTE)return this._pos+=1,t;throw new o.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let r=1,n=1;for(let i=0;i<e;i++)this._text.charCodeAt(i)===s.LINE_FEED?(r++,n=1):n++;return{row:r,col:n}}}exports.XmlStream=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./utils.js"),i=require("./XmlError.js"),P=require("./XmlStream.js");function w(t,n,s){T(new P.XmlStream(t),n,s)}function T(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&A(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i.XmlError({type:"DtdDetected"});W(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===r.LESS_THAN&&S(t,s),m(t,s),!t.atEnd())throw new i.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!--"))h(t,n);else if(t.startsWith("<?"))f(t,n);else break}function A(t){if(t.advance(5),E(t),!t.startsWith("version"))throw new i.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());d(t),E(t),t.startsWith("encoding")&&(d(t),E(t)),t.startsWith("standalone")&&d(t),t.skipSpaces(),t.skipString("?>")}function E(t){if(t.startsWithSpace())t.skipSpaces();else if(!t.startsWith("?>")&&!t.atEnd())throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos())}function h(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCharsWhile((e,a)=>!(a==="-"&&e.startsWith("-->")));if(t.skipString("-->"),o.includes("--")||o.endsWith("-"))throw new i.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function f(t,n){if(t.startsWith("<?xml "))throw new i.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith("?>")));t.skipString("?>"),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function W(t,n){const s=t.getPos();if(v(t),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!ENTITY"))y(t,n);else if(t.startsWith("<!--"))h(t,n);else if(t.startsWith("<?"))f(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);break}else throw new i.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith("<!ELEMENT")||t.startsWith("<!ATTLIST")||t.startsWith("<!NOTATION"))try{N(t)}catch(o){throw new i.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function v(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),g(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==r.OPEN_BRACKET&&n!==r.GREATER_THAN)throw new i.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function g(t){if(t.startsWith("SYSTEM")||t.startsWith("PUBLIC")){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s==="PUBLIC"){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==e),t.consumeCodeUnit(e)}return!0}return!1}function y(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(r.PERCENT);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=x(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN)}function x(t,n){const s=t.currCodeUnit();if(s===r.DOUBLE_QUOTE||s===r.SINGLE_QUOTE){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const a=t.sliceBack(e);return t.consumeCodeUnit(o),a}else if(s===r.UPPERCASE_S||s===r.UPPERCASE_P){if(g(t))return n&&(t.skipSpaces(),t.startsWith("NDATA")&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new i.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new i.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function N(t){t.skipCodeUnitsWhile(n=>n!==r.GREATER_THAN),t.consumeCodeUnit(r.GREATER_THAN)}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 a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const p=t.getPos(),u=t.currCodeUnit();if(u===r.SLASH){t.advance(1),t.consumeCodeUnit(r.GREATER_THAN);const l=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Empty"},range:l});break}else if(u===r.GREATER_THAN){t.advance(1);const l=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Open"},range:l}),a=!0;break}else{if(!c)throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[l,C,k]=d(t),U=t.getPos();n({type:"Attribute",range:{start:p,end:U},prefix:l,local:C,value:k})}}a&&R(t,n)}function d(t){const[n,s]=t.consumeQName();let o;const e=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(r.EQUALS)){t.skipSpaces();const a=t.consumeQuote(),c=String.fromCharCode(a),p=t.getPos();t.skipCharsWhile((u,l)=>l!==c&&l!=="<"),o=t.sliceBack(p),t.consumeCodeUnit(a)}else t.goTo(e),o="true";return[n,s,o]}function R(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===r.LESS_THAN){const s=t.nextCodeUnit();if(s===r.EXCLAMATION_MARK)if(t.startsWith("<!--"))h(t,n);else if(t.startsWith("<![CDATA["))X(t,n);else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===r.QUESTION_MARK)f(t,n);else if(s===r.SLASH){I(t,n);break}else S(t,n)}else _(t,n)}function X(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith("]]>")));t.skipString("]]>");const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function I(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:a})}function _(t,n){const s=t.getPos(),o=t.consumeCharsWhile((e,a)=>a!=="<");if(o.includes(">")&&o.includes("]]>"))throw new i.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}exports.tokenize=w,exports.tokenizeXmlStream=T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function n(t){let e="";switch(t.type){case"ProcessingInstruction":e+=`<?${t.target}`,t.content&&(e+=` ${t.content}`),e+="?>";break;case"Comment":e+=`<!--${t.text}-->`;break;case"EntityDeclaration":e+=`<!ENTITY ${t.name} "${t.definition}">`;break;case"ElementStart":e+=`<${t.prefix.length>0?`${t.prefix}:`:""}${t.local}`;break;case"Attribute":e+=` ${t.prefix.length>0?`${t.prefix}:`:""}${t.local}="${t.value}"`;break;case"ElementEnd":t.end.type==="Open"?e+=">":t.end.type==="Close"?e+=`</${t.end.prefix.length>0?`${t.end.prefix}:`:""}${t.end.local}>`:e+="/>";break;case"Text":e+=t.text;break;case"Cdata":e+=`<![CDATA[${t.text}]]>`;break}return e}function r(t){let e="";return t.forEach(a=>{e+=n(a)}),e}exports.tokenToXml=n,exports.tokensToXml=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var n=require("./get-q-name.js"),s=require("./tokenizer/tokenize.js");function o(c,l=!1){const i={tagName:"root",attributes:{},children:[]},r=[i];let a=i;return s.tokenize(c,l,t=>{switch(t.type){case"ElementStart":{const e={tagName:n.getQName(t.local,t.prefix),attributes:{},children:[]};a.children.push(e),r.push(e),a=e;break}case"ElementEnd":{if(t.end.type==="Close"||t.end.type==="Empty"){r.pop();const e=r[r.length-1];e!=null&&(a=e)}break}case"Attribute":{a.attributes[n.getQName(t.local,t.prefix)]=t.value;break}case"Text":case"Cdata":{t.text.trim().length>0&&a.children.push(t.text);break}}}),i.children[0]}exports.xmlToObject=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(l,e=null){return e!=null&&e.length>0?`${e}:${l}`:l}export{n as getQName};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{select as o}from"./selector/select.js";import{TokenSelector as r}from"./selector/TokenSelector.js";import{EToCacheNodeProps as A,ETokenMatchCriteria as m,TokenSelectState as R}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as C}from"./selector/TokenSelectStateMachine.js";import{tokenize as T,tokenizeXmlStream as _}from"./tokenizer/tokenize.js";import{AMPERSAND as i,CARRIAGE_RETURN as l,COLON as a,DOUBLE_QUOTE as L,EQUALS as p,EXCLAMATION_MARK as U,GREATER_THAN as X,HASH as x,HORIZONTAL_TAB as c,HYPHEN as f,LESS_THAN as s,LINE_FEED as n,LOWERCASE_A as I,LOWERCASE_F as k,LOWERCASE_X as H,LOWERCASE_Z as M,NINE as D,OPEN_BRACKET as B,PERCENT as h,PERIOD as Q,QUESTION_MARK as W,SEMICOLON as Z,SINGLE_QUOTE as F,SLASH as G,SPACE as K,UNDERSCORE as y,UPPERCASE_A as z,UPPERCASE_F as b,UPPERCASE_P as d,UPPERCASE_S as g,UPPERCASE_Z as j,ZERO as Y,isAsciiDigit as q,isXmlChar as u,isXmlName as v,isXmlNameByte as w,isXmlNameStart as J,isXmlSpaceByte as V}from"./tokenizer/utils.js";import{XmlError as EE}from"./tokenizer/XmlError.js";import{XmlStream as oE}from"./tokenizer/XmlStream.js";import{tokenToXml as rE,tokensToXml as SE}from"./tokens-to-xml.js";import{xmlToObject as mE}from"./xml-to-object.js";export{i as AMPERSAND,l as CARRIAGE_RETURN,a as COLON,L as DOUBLE_QUOTE,p as EQUALS,A as EToCacheNodeProps,m as ETokenMatchCriteria,U as EXCLAMATION_MARK,X as GREATER_THAN,x as HASH,c as HORIZONTAL_TAB,f as HYPHEN,s as LESS_THAN,n as LINE_FEED,I as LOWERCASE_A,k as LOWERCASE_F,H as LOWERCASE_X,M as LOWERCASE_Z,D as NINE,B as OPEN_BRACKET,h as PERCENT,Q as PERIOD,W as QUESTION_MARK,Z as SEMICOLON,F as SINGLE_QUOTE,G as SLASH,K as SPACE,R as TokenSelectState,C as TokenSelectStateMachine,r as TokenSelector,y as UNDERSCORE,z as UPPERCASE_A,b as UPPERCASE_F,d as UPPERCASE_P,g as UPPERCASE_S,j as UPPERCASE_Z,EE as XmlError,oE as XmlStream,Y as ZERO,q as isAsciiDigit,u as isXmlChar,v as isXmlName,w as isXmlNameByte,J as isXmlNameStart,V as isXmlSpaceByte,o as select,rE as tokenToXml,T as tokenize,_ as tokenizeXmlStream,SE as tokensToXml,mE as xmlToObject};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getQName as l}from"../get-q-name.js";var n=Object.defineProperty,o=(t,e,r)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e,r)=>o(t,typeof e!="symbol"?e+"":e,r);class p{constructor(e){a(this,"_part"),a(this,"_matchCriteria",0),a(this,"_toCacheNodeProps",0),a(this,"_enteredDepth",null),this._part=e,this.applyLevels()}get matchCriteria(){return this._matchCriteria}get toCacheNodeProps(){return this._toCacheNodeProps}get enteredDepth(){return this._enteredDepth}applyLevels(){let e=0,r=0;(this._part.local!=null||this._part.prefix!=null)&&(e|=1),this._part.attributes!=null&&(e|=2,r|=2),this._part.textContains!=null&&(e|=4),this._part.predicate!=null&&(e|=8,r|=7),this._matchCriteria=e,this._toCacheNodeProps=r}matchesName(e,r){return(this._part.local==null||this._part.local==="*"||this._part.local===e)&&(this._part.prefix==null||this._part.prefix===r)}matchesAttributes(e){if(this._part.attributes!=null)for(const r of this._part.attributes){const s=l(r.local,r.prefix);if(!(s in e)||r.value!=null&&e[s]!==r.value)return!1}return!0}matchesText(e){return this._part.textContains==null||e.includes(this._part.textContains)}matchesDepth(e,r){switch(this._part.axis){case"child":return e===r+1;case"self-or-descendant":return e>=r}}match(e){this._enteredDepth=e}unmatch(){this._enteredDepth=null}}var i=(t=>(t[t.None=0]="None",t[t.Name=1]="Name",t[t.Attributes=2]="Attributes",t[t.Text=4]="Text",t))(i||{}),h=(t=>(t[t.None=0]="None",t[t.Name=1]="Name",t[t.Attributes=2]="Attributes",t[t.Text=4]="Text",t[t.Node=8]="Node",t))(h||{});export{i as EToCacheNodeProps,h as ETokenMatchCriteria,p as TokenSelectState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getQName as _}from"../get-q-name.js";import{EToCacheNodeProps as l,TokenSelectState as p,ETokenMatchCriteria as o}from"./TokenSelectState.js";var C=Object.defineProperty,N=(i,t,e)=>t in i?C(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,h=(i,t,e)=>N(i,typeof t!="symbol"?t+"":t,e);class S{constructor(t){h(this,"_states"),h(this,"_currentState",null),h(this,"_hasActiveCache",!1),h(this,"_toCacheNodeProps",l.None),h(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),h(this,"_cachedTokens",[]),h(this,"_toRecordTokens",[]),this._states=t.map(e=>new p(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._hasActiveCache&&this._cachedTokens.push(t)}takeRecordedTokens(){if(this._toRecordTokens.length>0){const t=this._toRecordTokens;return this._toRecordTokens=[],t}return null}transitionIfNameMatch(t,e,s){var r;const a=this.getNextState(),n=this.getCurrentState();return a!=null&&a.matchesName(t,e)&&a.matchesDepth(s,(r=n==null?void 0:n.enteredDepth)!=null?r:0)?a.matchCriteria&(o.Attributes|o.Text|o.Node)?(this._hasActiveCache=!0,this._toCacheNodeProps|=a.toCacheNodeProps,this._toCacheNodeProps&l.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),!1):(this.transitionForward(s),!0):!1}transitionIfAttributesMatch(t,e,s,r){var a,n;const c=this.getNextState(),d=this.getCurrentState(),u=(a=this._cachedNodeProps.attributes)!=null?a:{};return u[_(t,e)]=s,c!=null&&c.matchesAttributes(u)&&c.matchesDepth(r,(n=d==null?void 0:d.enteredDepth)!=null?n:0)?c.matchCriteria&(o.Text|o.Node)?(this._hasActiveCache=!0,this._toCacheNodeProps|=c.toCacheNodeProps,this._toCacheNodeProps&l.Attributes&&(this._cachedNodeProps.attributes=u),!1):(this.transitionForward(r),!0):!1}transitionIfTextMatch(t,e){var s;const r=this.getNextState(),a=this.getCurrentState();return r!=null&&r.matchesText(t)&&r.matchesDepth(e,(s=a==null?void 0:a.enteredDepth)!=null?s:0)?r.matchCriteria&o.Node?(this._hasActiveCache=!0,this._toCacheNodeProps|=r.toCacheNodeProps,this._toCacheNodeProps&l.Text&&(this._cachedNodeProps.text=t),!1):(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 s=this.getCurrentState();s!=null&&s.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 s=this.getCurrentState();s!=null&&s.match(t),this.resetCurrentStateCache()}isFinalState(){return this._currentState!=null&&this._currentState>=this._states.length-1}resetCurrentStateCache(){this._hasActiveCache=!1,this._toCacheNodeProps=l.None,this._cachedNodeProps.prefix=null,this._cachedNodeProps.local=null,this._cachedNodeProps.attributes=null,this._cachedNodeProps.text=null,this._cachedTokens=[]}}export{S as TokenSelectStateMachine};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ETokenMatchCriteria as a}from"./TokenSelectState.js";import{TokenSelectStateMachine as l}from"./TokenSelectStateMachine.js";var u=Object.defineProperty,p=(r,t,i)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,s=(r,t,i)=>p(r,typeof t!="symbol"?t+"":t,i);class f{constructor(t){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=t.map(i=>new l(i))}pipeToken(t,i){let e=!1,n=!1;switch(t.type){case"ElementStart":e=this.handleElementStart(t);break;case"Attribute":e=this.handleAttribute(t);break;case"Text":e=this.handleText(t);break;case"ElementEnd":{n=this.handleElementEnd(t);break}}e&&!this._isRecording&&this.record();for(const c of this._tspStateMachines){c.record(t);const h=c.takeRecordedTokens();h!=null&&h.forEach(o=>{i(o)})}this._isRecording&&i(t),n&&(this._isRecording=!1)}handleElementStart(t){this._currentDepth+=1;let i=!1;for(const e of this._tspStateMachines){if(e.resetCurrentStateCache(),e.isFinalState())continue;const n=e.getNextState();n==null||!(n.matchCriteria&a.Name)||e.transitionIfNameMatch(t.local,t.prefix,this._currentDepth)&&e.isFinalState()&&(i=!0)}return i}handleAttribute(t){let i=!1;for(const e of this._tspStateMachines){if(e.isFinalState())continue;const n=e.getNextState();n==null||!(n.matchCriteria&a.Attributes)||e.transitionIfAttributesMatch(t.local,t.prefix,t.value,this._currentDepth)&&e.isFinalState()&&(i=!0)}return i}handleText(t){let i=!1;for(const e of this._tspStateMachines){if(e.isFinalState())continue;const n=e.getNextState();n==null||!(n.matchCriteria&a.Text)||e.transitionIfTextMatch(t.text,this._currentDepth)&&e.isFinalState()&&(i=!0)}return i}handleElementEnd(t){if(t.end.type==="Close"||t.end.type==="Empty"){this._currentDepth-=1;let i=!1;for(const e of this._tspStateMachines){const n=e.getCurrentState();n!=null&&(n.enteredDepth!=null&&this._currentDepth<n.enteredDepth&&e.transitionBack(this._currentDepth),i=i||e.isFinalState())}return!i}return!1}record(){this._isRecording=!0}}export{f as TokenSelector};
|
|
@@ -0,0 +1 @@
|
|
|
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,!1,r=>{t.pipeToken(r,i=>{n(i)})})}export{m as select};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isXmlChar as u,isXmlSpaceByte as _,AMPERSAND as m,HASH as C,LOWERCASE_X as f,ZERO as
|
|
1
|
+
import{isXmlChar as u,isXmlSpaceByte as _,AMPERSAND as m,HASH as C,LOWERCASE_X as f,ZERO as x,NINE as U,UPPERCASE_A as w,UPPERCASE_F as y,LOWERCASE_A as g,LOWERCASE_F as k,isAsciiDigit as E,SEMICOLON as P,isXmlNameStart as a,isXmlName as d,COLON as v,SINGLE_QUOTE as N,DOUBLE_QUOTE as S,LINE_FEED as A}from"./utils.js";import{XmlError as n}from"./XmlError.js";var T=Object.defineProperty,W=(h,t,e)=>t in h?T(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,c=(h,t,e)=>W(h,typeof t!="symbol"?t+"":t,e);class l{constructor(t,e=0){c(this,"_text"),c(this,"_pos"),c(this,"_end"),this._text=t,this._pos=e,this._end=this._text.length}clone(){return new l(this._text,this._pos)}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new n({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new n({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new n({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}skipString(t){if(!this.startsWith(t))throw new n({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked());)this._pos+=1}consumeCharsWhile(t){const e=this._pos;return this.skipCharsWhile(t),this.sliceBack(e)}skipCharsWhile(t){for(;this._pos<this._end;){const e=this._text[this._pos];if(e==null||!u(e.codePointAt(0)))throw new n({type:"NonXmlChar",char:e!=null?e:"\uFFFD"},this.genTextPos());if(t(this,e))this._pos+=e.length;else break}}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&_(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new n({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new n({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(m))return null;let t;if(this.tryConsumeCodeUnit(C)){let e,i;this.tryConsumeCodeUnit(f)?(e=this.consumeCodeUnitsWhile(s=>s>=x&&s<=U||s>=w&&s<=y||s>=g&&s<=k),i=16):(e=this.consumeCodeUnitsWhile(s=>E(s)),i=10);const o=parseInt(e,i);isNaN(o)||!u(o)?t=null:t={type:"Char",value:String.fromCodePoint(o)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(P)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new n({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!a(e))throw new n({type:"InvalidName"},this.genTextPosFrom(t))}else if(!d(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let o=null;for(;this._pos<this._end;){const p=this.currCodeUnitUnchecked();if(p===v)if(o==null)o=this._pos,this._pos+=1;else throw new n({type:"InvalidName"},this.genTextPosFrom(i));else if(d(p))this._pos+=1;else break}let s,r;if(o!=null?(s=this._text.slice(i,o),r=this.sliceBack(o+1)):(s="",r=this.sliceBack(i)),s.length>0&&!a((t=s[0])==null?void 0:t.codePointAt(0)))throw new n({type:"InvalidName"},this.genTextPosFrom(i));if(r.length>0){if(!a((e=r[0])==null?void 0:e.codePointAt(0)))throw new n({type:"InvalidName"},this.genTextPosFrom(i))}else throw new n({type:"InvalidName"},this.genTextPosFrom(i));return[s,r]}consumeQuote(){const t=this.currCodeUnit();if(t===N||t===S)return this._pos+=1,t;throw new n({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let i=1,o=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===A?(i++,o=1):o++;return{row:i,col:o}}}export{l as XmlStream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LESS_THAN as C,GREATER_THAN as r,OPEN_BRACKET as W,PERCENT as y,DOUBLE_QUOTE as x,SINGLE_QUOTE as v,UPPERCASE_S as I,UPPERCASE_P as N,SLASH as S,EQUALS as A,EXCLAMATION_MARK as F,QUESTION_MARK as L}from"./utils.js";import{XmlError as i}from"./XmlError.js";import{XmlStream as Q}from"./XmlStream.js";function O(t,n,s){k(new Q(t),n,s)}function k(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&D(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i({type:"DtdDetected"});_(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===C&&U(t,s),m(t,s),!t.atEnd())throw new i({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!--"))f(t,n);else if(t.startsWith("<?"))g(t,n);else break}function D(t){if(t.advance(5),h(t),!t.startsWith("version"))throw new i({type:"InvalidString",expected:"version"},t.genTextPos());u(t),h(t),t.startsWith("encoding")&&(u(t),h(t)),t.startsWith("standalone")&&u(t),t.skipSpaces(),t.skipString("?>")}function h(t){if(t.startsWithSpace())t.skipSpaces();else if(!t.startsWith("?>")&&!t.atEnd())throw new i({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos())}function f(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCharsWhile((e,a)=>!(a==="-"&&e.startsWith("-->")));if(t.skipString("-->"),o.includes("--")||o.endsWith("-"))throw new i({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function g(t,n){if(t.startsWith("<?xml "))throw new i({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith("?>")));t.skipString("?>"),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function _(t,n){const s=t.getPos();if(B(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!ENTITY"))R(t,n);else if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<?"))g(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new i({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith("<!ELEMENT")||t.startsWith("<!ATTLIST")||t.startsWith("<!NOTATION"))try{M(t)}catch(o){throw new i({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new i({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function B(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),E(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==W&&n!==r)throw new i({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function E(t){if(t.startsWith("SYSTEM")||t.startsWith("PUBLIC")){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s==="PUBLIC"){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==e),t.consumeCodeUnit(e)}return!0}return!1}function R(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(y);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=b(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r)}function b(t,n){const s=t.currCodeUnit();if(s===x||s===v){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const a=t.sliceBack(e);return t.consumeCodeUnit(o),a}else if(s===I||s===N){if(E(t))return n&&(t.skipSpaces(),t.startsWith("NDATA")&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new i({type:"InvalidExternalID"},t.genTextPos())}else throw new i({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function M(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function U(t,n){const s=t.getPos();t.advance(1);const[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s});let a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const d=t.getPos(),l=t.currCodeUnit();if(l===S){t.advance(1),t.consumeCodeUnit(r);const p=t.rangeFrom(d);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(l===r){t.advance(1);const p=t.rangeFrom(d);n({type:"ElementEnd",end:{type:"Open"},range:p}),a=!0;break}else{if(!c)throw new i({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[p,T,P]=u(t),w=t.getPos();n({type:"Attribute",range:{start:d,end:w},prefix:p,local:T,value:P})}}a&&X(t,n)}function u(t){const[n,s]=t.consumeQName();let o;const e=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(A)){t.skipSpaces();const a=t.consumeQuote(),c=String.fromCharCode(a),d=t.getPos();t.skipCharsWhile((l,p)=>p!==c&&p!=="<"),o=t.sliceBack(d),t.consumeCodeUnit(a)}else t.goTo(e),o="true";return[n,s,o]}function X(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===C){const s=t.nextCodeUnit();if(s===F)if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<![CDATA["))Y(t,n);else throw new i({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===L)g(t,n);else if(s===S){H(t,n);break}else U(t,n)}else K(t,n)}function Y(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith("]]>")));t.skipString("]]>");const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function H(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:a})}function K(t,n){const s=t.getPos(),o=t.consumeCharsWhile((e,a)=>a!=="<");if(o.includes(">")&&o.includes("]]>"))throw new i({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}export{O as tokenize,k as tokenizeXmlStream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(t){let e="";switch(t.type){case"ProcessingInstruction":e+=`<?${t.target}`,t.content&&(e+=` ${t.content}`),e+="?>";break;case"Comment":e+=`<!--${t.text}-->`;break;case"EntityDeclaration":e+=`<!ENTITY ${t.name} "${t.definition}">`;break;case"ElementStart":e+=`<${t.prefix.length>0?`${t.prefix}:`:""}${t.local}`;break;case"Attribute":e+=` ${t.prefix.length>0?`${t.prefix}:`:""}${t.local}="${t.value}"`;break;case"ElementEnd":t.end.type==="Open"?e+=">":t.end.type==="Close"?e+=`</${t.end.prefix.length>0?`${t.end.prefix}:`:""}${t.end.local}>`:e+="/>";break;case"Text":e+=t.text;break;case"Cdata":e+=`<![CDATA[${t.text}]]>`;break}return e}function r(t){let e="";return t.forEach(a=>{e+=n(a)}),e}export{n as tokenToXml,r as tokensToXml};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getQName as i}from"./get-q-name.js";import{tokenize as o}from"./tokenizer/tokenize.js";function s(l,c=!1){const n={tagName:"root",attributes:{},children:[]},a=[n];let r=n;return o(l,c,t=>{switch(t.type){case"ElementStart":{const e={tagName:i(t.local,t.prefix),attributes:{},children:[]};r.children.push(e),a.push(e),r=e;break}case"ElementEnd":{if(t.end.type==="Close"||t.end.type==="Empty"){a.pop();const e=a[a.length-1];e!=null&&(r=e)}break}case"Attribute":{r.attributes[i(t.local,t.prefix)]=t.value;break}case"Text":case"Cdata":{t.text.trim().length>0&&r.children.push(t.text);break}}}),n.children[0]}export{s as xmlToObject};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-q-name.d.ts","sourceRoot":"","sources":["../../src/get-q-name.ts"],"names":[],"mappings":"AACA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAE5E"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type TTokenSelectPathPart } from './types';
|
|
2
|
+
export declare class TokenSelectState {
|
|
3
|
+
private _part;
|
|
4
|
+
private _matchCriteria;
|
|
5
|
+
private _toCacheNodeProps;
|
|
6
|
+
private _enteredDepth;
|
|
7
|
+
constructor(part: TTokenSelectPathPart);
|
|
8
|
+
get matchCriteria(): ETokenMatchCriteria;
|
|
9
|
+
get toCacheNodeProps(): EToCacheNodeProps;
|
|
10
|
+
get enteredDepth(): number | null;
|
|
11
|
+
private applyLevels;
|
|
12
|
+
matchesName(local: string, prefix: string): boolean;
|
|
13
|
+
matchesAttributes(attributes: Record<string, string>): boolean;
|
|
14
|
+
matchesText(text: string): boolean;
|
|
15
|
+
matchesDepth(depth: number, parentDepth: number): boolean;
|
|
16
|
+
match(depth: number): void;
|
|
17
|
+
unmatch(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const enum EToCacheNodeProps {
|
|
20
|
+
None = 0,// Cache none
|
|
21
|
+
Name = 1,// Cache local and prefix <prefix:local
|
|
22
|
+
Attributes = 2,// Cache attributes <prefix:local attribute="x"
|
|
23
|
+
Text = 4
|
|
24
|
+
}
|
|
25
|
+
export declare const enum ETokenMatchCriteria {
|
|
26
|
+
None = 0,// Match none
|
|
27
|
+
Name = 1,// Match local and prefix <prefix:local
|
|
28
|
+
Attributes = 2,// Match attributes <prefix:local attribute="x"
|
|
29
|
+
Text = 4,// Match text content <prefix:local attribute="x">text
|
|
30
|
+
Node = 8
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=TokenSelectState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenSelectState.d.ts","sourceRoot":"","sources":["../../../src/selector/TokenSelectState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,cAAc,CAAiD;IACvE,OAAO,CAAC,iBAAiB,CAA6C;IACtE,OAAO,CAAC,aAAa,CAAuB;gBAEhC,IAAI,EAAE,oBAAoB;IAKtC,IAAW,aAAa,IAAI,mBAAmB,CAE9C;IAED,IAAW,gBAAgB,IAAI,iBAAiB,CAE/C;IAED,IAAW,YAAY,IAAI,MAAM,GAAG,IAAI,CAEvC;IAED,OAAO,CAAC,WAAW;IAuBZ,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IASnD,iBAAiB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO;IAe9D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIlC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO;IASzD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI1B,OAAO,IAAI,IAAI;CAGtB;AAED,0BAAkB,iBAAiB;IAClC,IAAI,IAAI,CAAE,aAAa;IACvB,IAAI,IAAS,CAAE,uCAAuC;IACtD,UAAU,IAAS,CAAE,+CAA+C;IACpE,IAAI,IAAS;CACb;AAED,0BAAkB,mBAAmB;IACpC,IAAI,IAAI,CAAE,aAAa;IACvB,IAAI,IAAS,CAAE,uCAAuC;IACtD,UAAU,IAAS,CAAE,+CAA+C;IACpE,IAAI,IAAS,CAAE,sDAAsD;IACrE,IAAI,IAAS;CACb"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TXmlToken } from '../tokenizer';
|
|
2
|
+
import { TokenSelectState } from './TokenSelectState';
|
|
3
|
+
import { type TTokenSelectPath } from './types';
|
|
4
|
+
export declare class TokenSelectStateMachine {
|
|
5
|
+
private _states;
|
|
6
|
+
private _currentState;
|
|
7
|
+
private _hasActiveCache;
|
|
8
|
+
private _toCacheNodeProps;
|
|
9
|
+
private _cachedNodeProps;
|
|
10
|
+
private _cachedTokens;
|
|
11
|
+
private _toRecordTokens;
|
|
12
|
+
constructor(tokenSelectPath: TTokenSelectPath);
|
|
13
|
+
getNextState(): TokenSelectState | null;
|
|
14
|
+
getCurrentState(): TokenSelectState | null;
|
|
15
|
+
record(token: TXmlToken): void;
|
|
16
|
+
takeRecordedTokens(): TXmlToken[] | null;
|
|
17
|
+
transitionIfNameMatch(local: string, prefix: string, depth: number): boolean;
|
|
18
|
+
transitionIfAttributesMatch(local: string, prefix: string, value: string, depth: number): boolean;
|
|
19
|
+
transitionIfTextMatch(text: string, depth: number): boolean;
|
|
20
|
+
private transitionForward;
|
|
21
|
+
transitionBack(depth: number): void;
|
|
22
|
+
isFinalState(): boolean;
|
|
23
|
+
resetCurrentStateCache(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=TokenSelectStateMachine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenSelectStateMachine.d.ts","sourceRoot":"","sources":["../../../src/selector/TokenSelectStateMachine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAA0C,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,qBAAa,uBAAuB;IACnC,OAAO,CAAC,OAAO,CAAqB;IAGpC,OAAO,CAAC,aAAa,CAAuB;IAG5C,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,iBAAiB,CAA6C;IACtE,OAAO,CAAC,gBAAgB,CAKtB;IACF,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,eAAe,CAAmB;gBAE9B,eAAe,EAAE,gBAAgB;IAItC,YAAY,IAAI,gBAAgB,GAAG,IAAI;IAQvC,eAAe,IAAI,gBAAgB,GAAG,IAAI;IAO1C,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAM9B,kBAAkB,IAAI,SAAS,EAAE,GAAG,IAAI;IASxC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IA6B5E,2BAA2B,CACjC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACX,OAAO;IA4BH,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAyBlE,OAAO,CAAC,iBAAiB;IAmBlB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAgBnC,YAAY,IAAI,OAAO;IAIvB,sBAAsB,IAAI,IAAI;CASrC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type TXmlToken } from '../tokenizer';
|
|
2
|
+
import { type TTokenSelectPath } from './types';
|
|
3
|
+
export declare class TokenSelector {
|
|
4
|
+
private _currentDepth;
|
|
5
|
+
private _tspStateMachines;
|
|
6
|
+
private _isRecording;
|
|
7
|
+
constructor(tokenSelectPaths: TTokenSelectPath[]);
|
|
8
|
+
pipeToken(token: TXmlToken, recorder: (token: TXmlToken) => void): void;
|
|
9
|
+
private handleElementStart;
|
|
10
|
+
private handleAttribute;
|
|
11
|
+
private handleText;
|
|
12
|
+
private handleElementEnd;
|
|
13
|
+
private record;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=TokenSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenSelector.d.ts","sourceRoot":"","sources":["../../../src/selector/TokenSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,SAAS,EACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,qBAAa,aAAa;IACzB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,iBAAiB,CAA4B;IACrD,OAAO,CAAC,YAAY,CAAS;gBAEjB,gBAAgB,EAAE,gBAAgB,EAAE;IAMzC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI;IA2C9E,OAAO,CAAC,kBAAkB;IA6B1B,OAAO,CAAC,eAAe;IA2BvB,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,gBAAgB;IAwBxB,OAAO,CAAC,MAAM;CAGd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/selector/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../src/selector/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAgB,MAAM,CACrB,GAAG,EAAE,MAAM,EACX,gBAAgB,EAAE,gBAAgB,EAAE,EACpC,QAAQ,EAAE,cAAc,GACtB,IAAI,CAON"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a single segment of a XPath expression.
|
|
3
|
+
*
|
|
4
|
+
* This interface allows for constructing XPath expressions in a object-oriented way,
|
|
5
|
+
* avoiding the complexities of parsing a full XPath string.
|
|
6
|
+
* If parsing a full XPath becomes necessary in the future, a tool like [Peggy](https://github.com/peggyjs/peggy)
|
|
7
|
+
* could be used to facilitate the process.
|
|
8
|
+
*
|
|
9
|
+
* https://www.w3.org/TR/xpath-31/
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Represents the XPath expression `/bookstore/book[@category='fiction'][1]`
|
|
13
|
+
* const xpathExpr: TXPathExpr = [
|
|
14
|
+
* \{ axis: '/', name: 'bookstore' \},
|
|
15
|
+
* \{
|
|
16
|
+
* axis: '/',
|
|
17
|
+
* name: 'book',
|
|
18
|
+
* predicate: \{ attribute: 'category', value: 'fiction' \},
|
|
19
|
+
* position: 1,
|
|
20
|
+
* attributes: ['category', 'lang'] // Selects the 'category' and 'lang' attributes
|
|
21
|
+
* \}
|
|
22
|
+
* ];
|
|
23
|
+
*/
|
|
24
|
+
export interface TTokenSelectPathPart {
|
|
25
|
+
/**
|
|
26
|
+
* The axis defining the relationship between nodes.
|
|
27
|
+
*/
|
|
28
|
+
axis: 'child' | 'self-or-descendant';
|
|
29
|
+
/**
|
|
30
|
+
* The tag name of the node to match.
|
|
31
|
+
*/
|
|
32
|
+
local?: string | '*';
|
|
33
|
+
/**
|
|
34
|
+
* An optional prefix (e.g. namespace) to qualify the node name.
|
|
35
|
+
*/
|
|
36
|
+
prefix?: string;
|
|
37
|
+
/**
|
|
38
|
+
* An optional attribute-based filter.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Matches a book element with a category attribute equal to 'fiction'
|
|
42
|
+
* predicate: \{ attribute: 'category', value: 'fiction' \}
|
|
43
|
+
*/
|
|
44
|
+
attributes?: {
|
|
45
|
+
local: string;
|
|
46
|
+
prefix?: string;
|
|
47
|
+
value?: string;
|
|
48
|
+
}[];
|
|
49
|
+
/**
|
|
50
|
+
* An optional text content matcher.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Matches elements containing the text 'bestseller'
|
|
54
|
+
* textContains: 'bestseller'
|
|
55
|
+
*/
|
|
56
|
+
textContains?: string;
|
|
57
|
+
predicate?: (node: any) => boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Represents an entire XPath expression composed of multiple parts.
|
|
61
|
+
* The expression is an array of `TXPathPart` objects, each defining
|
|
62
|
+
* a segment of the XPath.
|
|
63
|
+
*/
|
|
64
|
+
export type TTokenSelectPath = TTokenSelectPathPart[];
|
|
65
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/selector/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAAC;IAErC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAYlE;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,EAAE,CAAC"}
|
|
@@ -55,6 +55,12 @@ export declare class XmlStream {
|
|
|
55
55
|
* @param n - The number of characters to advance.
|
|
56
56
|
*/
|
|
57
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;
|
|
58
64
|
/**
|
|
59
65
|
* Checks if the stream starts with the given text.
|
|
60
66
|
*
|
|
@@ -178,10 +184,6 @@ export declare class XmlStream {
|
|
|
178
184
|
* @throws XmlError if an invalid qualified XML name is encountered.
|
|
179
185
|
*/
|
|
180
186
|
consumeQName(): [string, string];
|
|
181
|
-
/**
|
|
182
|
-
* Consumes an equal sign, surrounded by optional whitespace.
|
|
183
|
-
*/
|
|
184
|
-
consumeEq(): void;
|
|
185
187
|
/**
|
|
186
188
|
* Consumes a quote character.
|
|
187
189
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XmlStream.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/XmlStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"XmlStream.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/XmlStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAwBtE;;;;;;GAMG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;gBAEF,IAAI,EAAE,MAAM,EAAE,GAAG,SAAI;IAMxC;;;;OAIG;IACI,KAAK,IAAI,SAAS;IAIzB;;;;OAIG;IACI,MAAM,IAAI,MAAM;IAIvB;;;;OAIG;IACI,KAAK,IAAI,OAAO;IAIvB;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAO7B;;;;OAIG;IACI,qBAAqB,IAAI,MAAM;IAItC;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAO7B;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;OAIG;IACI,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI9B;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;;OAKG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAW9C;;;;;;OAMG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQpD;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOrC;;;;;OAKG;IACI,qBAAqB,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM;IAM9E;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI;IAMzE;;;;;;OAMG;IACI,iBAAiB,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM;IAMzF;;;;;OAKG;IACI,cAAc,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI;IAapF;;;;;OAKG;IACI,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIrC;;;;;OAKG;IACI,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,UAAU,IAAI,IAAI;IAMzB;;;;OAIG;IACI,eAAe,IAAI,OAAO;IAIjC;;;;;OAKG;IACI,aAAa,IAAI,IAAI;IAe5B;;;;;OAKG;IACI,mBAAmB,IAAI,UAAU,GAAG,IAAI;IAiB/C;;;;OAIG;IACI,gBAAgB,IAAI,UAAU,GAAG,IAAI;IA4D5C;;;;;;OAMG;IACI,WAAW,IAAI,MAAM;IAY5B;;;;OAIG;IACI,QAAQ,IAAI,IAAI;IAgBvB;;;;;;OAMG;IACI,YAAY,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAiDvC;;;;;OAKG;IACI,YAAY,IAAI,MAAM;IAY7B;;;;;OAKG;IACI,UAAU,IAAI,QAAQ;IAI7B;;;;;;OAMG;IACI,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;CAc5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TTokenCallback } from './types';
|
|
2
|
+
import { XmlStream } from './XmlStream';
|
|
3
|
+
export declare function tokenize(xmlString: string, allowDtd: boolean, tokenCallback: TTokenCallback): void;
|
|
4
|
+
/**
|
|
5
|
+
* Parses an XML document.
|
|
6
|
+
*
|
|
7
|
+
* document ::= prolog element Misc*
|
|
8
|
+
*
|
|
9
|
+
* https://www.w3.org/TR/xml/#NT-document
|
|
10
|
+
*/
|
|
11
|
+
export declare function tokenizeXmlStream(s: XmlStream, allowDtd: boolean, tokenCallback: TTokenCallback): void;
|
|
12
|
+
//# sourceMappingURL=tokenize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/tokenize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAgB9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,wBAAgB,QAAQ,CACvB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,CAAC,EAAE,SAAS,EACZ,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAgCN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type TTokenCallback = (token:
|
|
1
|
+
export type TTokenCallback = (token: TXmlToken) => void;
|
|
2
2
|
/**
|
|
3
3
|
* A Processing Instruction token.
|
|
4
4
|
*
|
|
@@ -92,7 +92,7 @@ export interface TCdataToken {
|
|
|
92
92
|
text: string;
|
|
93
93
|
range: TRange;
|
|
94
94
|
}
|
|
95
|
-
export type
|
|
95
|
+
export type TXmlToken = TProcessingInstructionToken | TCommentToken | TEntityDeclarationToken | TElementStartToken | TAttributeToken | TElementEndToken | TTextToken | TCdataToken;
|
|
96
96
|
export interface TRange {
|
|
97
97
|
start: number;
|
|
98
98
|
end: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens-to-xml.d.ts","sourceRoot":"","sources":["../../src/tokens-to-xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAgDnD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAQvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-to-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-object.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xml-to-object.d.ts","sourceRoot":"","sources":["../../src/xml-to-object.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,QAAQ,CAmDzE;AAED,MAAM,WAAW,QAAQ;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;CAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xml-tokenizer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"@types/node": "^20.14.10",
|
|
23
23
|
"@types/sax": "^1.2.7",
|
|
24
24
|
"@types/xml2js": "^0.4.14",
|
|
25
|
+
"camaro": "^6.2.3",
|
|
25
26
|
"fast-xml-parser": "^4.4.1",
|
|
26
27
|
"sax": "^1.4.1",
|
|
27
28
|
"saxen": "^10.0.0",
|
|
28
29
|
"txml": "^5.1.1",
|
|
29
|
-
"xml-tokenizer": "^0.0.2",
|
|
30
30
|
"xml2js": "^0.6.2",
|
|
31
|
-
"@blgc/config": "0.0.
|
|
31
|
+
"@blgc/config": "0.0.17"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
package/dist/cjs/parse-string.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var a=require("./tokenizer/tokenizer.js"),i=require("./tokenizer/XmlStream.js");function m(r,e,t){a.parseXmlStream(new i.XmlStream(r),e,t)}exports.parseString=m;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var r=require("./utils.js"),i=require("./XmlError.js");function U(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&P(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i.XmlError({type:"DtdDetected"});w(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===r.LESS_THAN&&g(t,s),m(t,s),!t.atEnd())throw new i.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!--"))h(t,n);else if(t.startsWith("<?"))f(t,n);else break}function P(t){if(t.advance(5),E(t),!t.startsWith("version"))throw new i.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());u(t),E(t),t.startsWith("encoding")&&(u(t),E(t)),t.startsWith("standalone")&&u(t),t.skipSpaces(),t.skipString("?>")}function E(t){if(t.startsWithSpace())t.skipSpaces();else if(!t.startsWith("?>")&&!t.atEnd())throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos())}function h(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCharsWhile((e,a)=>!(a==="-"&&e.startsWith("-->")));if(t.skipString("-->"),o.includes("--")||o.endsWith("-"))throw new i.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function f(t,n){if(t.startsWith("<?xml "))throw new i.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith("?>")));t.skipString("?>"),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function w(t,n){const s=t.getPos();if(A(t),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!ENTITY"))W(t,n);else if(t.startsWith("<!--"))h(t,n);else if(t.startsWith("<?"))f(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r.GREATER_THAN){t.advance(1);break}else throw new i.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith("<!ELEMENT")||t.startsWith("<!ATTLIST")||t.startsWith("<!NOTATION"))try{y(t)}catch(o){throw new i.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function A(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),T(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==r.OPEN_BRACKET&&n!==r.GREATER_THAN)throw new i.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function T(t){if(t.startsWith("SYSTEM")||t.startsWith("PUBLIC")){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s==="PUBLIC"){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==e),t.consumeCodeUnit(e)}return!0}return!1}function W(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(r.PERCENT);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=v(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN)}function v(t,n){const s=t.currCodeUnit();if(s===r.DOUBLE_QUOTE||s===r.SINGLE_QUOTE){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const a=t.sliceBack(e);return t.consumeCodeUnit(o),a}else if(s===r.UPPERCASE_S||s===r.UPPERCASE_P){if(T(t))return n&&(t.skipSpaces(),t.startsWith("NDATA")&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new i.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new i.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function y(t){t.skipCodeUnitsWhile(n=>n!==r.GREATER_THAN),t.consumeCodeUnit(r.GREATER_THAN)}function g(t,n){const s=t.getPos();t.advance(1);const[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s});let a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const d=t.getPos(),l=t.currCodeUnit();if(l===r.SLASH){t.advance(1),t.consumeCodeUnit(r.GREATER_THAN);const p=t.rangeFrom(d);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(l===r.GREATER_THAN){t.advance(1);const p=t.rangeFrom(d);n({type:"ElementEnd",end:{type:"Open"},range:p}),a=!0;break}else{if(!c)throw new i.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[p,C,S]=u(t),k=t.getPos();n({type:"Attribute",range:{start:d,end:k},prefix:p,local:C,value:S})}}a&&x(t,n)}function u(t){const[n,s]=t.consumeQName();t.consumeEq();const o=t.consumeQuote(),e=String.fromCharCode(o),a=t.getPos();t.skipCharsWhile((d,l)=>l!==e&&l!=="<");const c=t.sliceBack(a);return t.consumeCodeUnit(o),[n,s,c]}function x(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===r.LESS_THAN){const s=t.nextCodeUnit();if(s===r.EXCLAMATION_MARK)if(t.startsWith("<!--"))h(t,n);else if(t.startsWith("<![CDATA["))N(t,n);else throw new i.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===r.QUESTION_MARK)f(t,n);else if(s===r.SLASH){R(t,n);break}else g(t,n)}else I(t,n)}function N(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith("]]>")));t.skipString("]]>");const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function R(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:a})}function I(t,n){const s=t.getPos(),o=t.consumeCharsWhile((e,a)=>a!=="<");if(o.includes(">")&&o.includes("]]>"))throw new i.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}exports.parseXmlStream=U;
|
package/dist/esm/parse-string.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parseXmlStream as e}from"./tokenizer/tokenizer.js";import{XmlStream as o}from"./tokenizer/XmlStream.js";function p(r,m,t){e(new o(r),m,t)}export{p as parseString};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LESS_THAN as C,GREATER_THAN as r,OPEN_BRACKET as w,PERCENT as W,DOUBLE_QUOTE as x,SINGLE_QUOTE as y,UPPERCASE_S as v,UPPERCASE_P as I,SLASH as S,EXCLAMATION_MARK as N,QUESTION_MARK as A}from"./utils.js";import{XmlError as i}from"./XmlError.js";function F(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&D(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i({type:"DtdDetected"});L(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===C&&k(t,s),m(t,s),!t.atEnd())throw new i({type:"UnknownToken",message:"Not at end"},t.genTextPos())}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!--"))f(t,n);else if(t.startsWith("<?"))g(t,n);else break}function D(t){if(t.advance(5),h(t),!t.startsWith("version"))throw new i({type:"InvalidString",expected:"version"},t.genTextPos());l(t),h(t),t.startsWith("encoding")&&(l(t),h(t)),t.startsWith("standalone")&&l(t),t.skipSpaces(),t.skipString("?>")}function h(t){if(t.startsWithSpace())t.skipSpaces();else if(!t.startsWith("?>")&&!t.atEnd())throw new i({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos())}function f(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCharsWhile((e,a)=>!(a==="-"&&e.startsWith("-->")));if(t.skipString("-->"),o.includes("--")||o.endsWith("-"))throw new i({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function g(t,n){if(t.startsWith("<?xml "))throw new i({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCharsWhile((a,c)=>!(c==="?"&&a.startsWith("?>")));t.skipString("?>"),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)})}function L(t,n){const s=t.getPos();if(O(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith("<!ENTITY"))Q(t,n);else if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<?"))g(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new i({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith("<!ELEMENT")||t.startsWith("<!ATTLIST")||t.startsWith("<!NOTATION"))try{B(t)}catch(o){throw new i({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new i({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function O(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),E(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==w&&n!==r)throw new i({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function E(t){if(t.startsWith("SYSTEM")||t.startsWith("PUBLIC")){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s==="PUBLIC"){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(a=>a!==e),t.consumeCodeUnit(e)}return!0}return!1}function Q(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(W);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=_(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r)}function _(t,n){const s=t.currCodeUnit();if(s===x||s===y){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const a=t.sliceBack(e);return t.consumeCodeUnit(o),a}else if(s===v||s===I){if(E(t))return n&&(t.skipSpaces(),t.startsWith("NDATA")&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new i({type:"InvalidExternalID"},t.genTextPos())}else throw new i({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function B(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function k(t,n){const s=t.getPos();t.advance(1);const[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s});let a=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const u=t.getPos(),p=t.currCodeUnit();if(p===S){t.advance(1),t.consumeCodeUnit(r);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Empty"},range:d});break}else if(p===r){t.advance(1);const d=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Open"},range:d}),a=!0;break}else{if(!c)throw new i({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[d,U,T]=l(t),P=t.getPos();n({type:"Attribute",range:{start:u,end:P},prefix:d,local:U,value:T})}}a&&R(t,n)}function l(t){const[n,s]=t.consumeQName();t.consumeEq();const o=t.consumeQuote(),e=String.fromCharCode(o),a=t.getPos();t.skipCharsWhile((u,p)=>p!==e&&p!=="<");const c=t.sliceBack(a);return t.consumeCodeUnit(o),[n,s,c]}function R(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===C){const s=t.nextCodeUnit();if(s===N)if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<![CDATA["))b(t,n);else throw new i({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===A)g(t,n);else if(s===S){M(t,n);break}else k(t,n)}else Y(t,n)}function b(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCharsWhile((a,c)=>!(c==="]"&&a.startsWith("]]>")));t.skipString("]]>");const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e})}function M(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const a=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:a})}function Y(t,n){const s=t.getPos(),o=t.consumeCharsWhile((e,a)=>a!=="<");if(o.includes(">")&&o.includes("]]>"))throw new i({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}export{F as parseXmlStream};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-string.d.ts","sourceRoot":"","sources":["../../src/parse-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7E,wBAAgB,WAAW,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAEN"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type TTokenCallback } from './types';
|
|
2
|
-
import { type XmlStream } from './XmlStream';
|
|
3
|
-
/**
|
|
4
|
-
* Parses an XML document.
|
|
5
|
-
*
|
|
6
|
-
* document ::= prolog element Misc*
|
|
7
|
-
*
|
|
8
|
-
* https://www.w3.org/TR/xml/#NT-document
|
|
9
|
-
*/
|
|
10
|
-
export declare function parseXmlStream(s: XmlStream, allowDtd: boolean, tokenCallback: TTokenCallback): void;
|
|
11
|
-
//# sourceMappingURL=tokenizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/tokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAe9C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC7B,CAAC,EAAE,SAAS,EACZ,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,GAC3B,IAAI,CAgCN"}
|