xml-tokenizer 0.0.5 → 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/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/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/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/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 +2 -1
- 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
|
@@ -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;
|
|
@@ -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};
|
|
@@ -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"}
|
|
@@ -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,6 +22,7 @@
|
|
|
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",
|
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());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(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{v(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=y(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e}),t.skipSpaces(),t.consumeCodeUnit(r.GREATER_THAN)}function y(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 v(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 l=t.getPos(),u=t.currCodeUnit();if(u===r.SLASH){t.advance(1),t.consumeCodeUnit(r.GREATER_THAN);const p=t.rangeFrom(l);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(u===r.GREATER_THAN){t.advance(1);const p=t.rangeFrom(l);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]=d(t),k=t.getPos();n({type:"Attribute",range:{start:l,end:k},prefix:p,local:C,value:S})}}a&&x(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),l=t.getPos();t.skipCharsWhile((u,p)=>p!==c&&p!=="<"),o=t.sliceBack(l),t.consumeCodeUnit(a)}else t.goTo(e),o="true";return[n,s,o]}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 y,SINGLE_QUOTE as x,UPPERCASE_S as v,UPPERCASE_P as I,SLASH as S,EQUALS as N,EXCLAMATION_MARK as A,QUESTION_MARK as F}from"./utils.js";import{XmlError as i}from"./XmlError.js";function L(t,n,s){if(t.startsWith("\uFEFF")&&t.advance(1),t.startsWith("<?xml ")&&Q(t),m(t,s),t.skipSpaces(),t.startsWith("<!DOCTYPE")){if(!n)throw new i({type:"DtdDetected"});D(t,s),m(t,s)}if(t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===C&&E(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 Q(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 D(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"))_(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{R(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(),k(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==w&&n!==r)throw new i({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function k(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 _(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(W);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===y||s===x){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(k(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 R(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function E(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,U,T]=u(t),P=t.getPos();n({type:"Attribute",range:{start:d,end:P},prefix:p,local:U,value:T})}}a&&b(t,n)}function u(t){const[n,s]=t.consumeQName();let o;const e=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(N)){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 b(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===C){const s=t.nextCodeUnit();if(s===A)if(t.startsWith("<!--"))f(t,n);else if(t.startsWith("<![CDATA["))M(t,n);else throw new i({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===F)g(t,n);else if(s===S){Y(t,n);break}else E(t,n)}else H(t,n)}function M(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 Y(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 H(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{L 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;AAgB9C,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"}
|