xml-tokenizer 0.0.38 → 0.0.39
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var o=require("./ascii-constants.js"),c=require("./utils.js"),n=require("./XmlError.js"),C=Object.defineProperty,g=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,m=(a,t,e)=>t in a?C(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))x.call(t,e)&&m(a,e,t[e]);if(g)for(var e of g(t))E.call(t,e)&&m(a,e,t[e]);return a},d=(a,t,e)=>m(a,typeof t!="symbol"?t+"":t,e);class _{constructor(t,e={}){d(this,"_text"),d(this,"_pos"),d(this,"_end"),d(this,"config");const{pos:s=0,strictDocument:r=!0,allowDtd:i=!0,rawTextElements:p=null,implicitSelfClosingElements:h=null,contextSliceSize:l=!1,debugLogger:u}=e;this.debug("XmlStream constructor",{textLength:t.length,initialPos:s,platform:process.platform,nodeVersion:process.version,textSample:t.slice(0,Math.min(100,t.length))+(t.length>100?"...":"")}),this.
|
|
1
|
+
"use strict";var o=require("./ascii-constants.js"),c=require("./utils.js"),n=require("./XmlError.js"),C=Object.defineProperty,g=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,m=(a,t,e)=>t in a?C(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))x.call(t,e)&&m(a,e,t[e]);if(g)for(var e of g(t))E.call(t,e)&&m(a,e,t[e]);return a},d=(a,t,e)=>m(a,typeof t!="symbol"?t+"":t,e);class _{constructor(t,e={}){d(this,"_text"),d(this,"_pos"),d(this,"_end"),d(this,"config");const{pos:s=0,strictDocument:r=!0,allowDtd:i=!0,rawTextElements:p=null,implicitSelfClosingElements:h=null,contextSliceSize:l=!1,debugLogger:u}=e;this._text=t,this._pos=s,this._end=this._text.length,this.config={strictDocument:r,allowDtd:i,rawTextElements:p,implicitSelfClosingElements:h,contextSliceSize:l,debugLogger:u},this.debug("XmlStream constructor",{textLength:t.length,initialPos:s,platform:process.platform,nodeVersion:process.version,textSample:t.slice(0,Math.min(100,t.length))+(t.length>100?"...":"")}),this.debug("XmlStream initialized",{textLength:this._text.length,initialPos:s,platform:process.platform,nodeVersion:process.version,textSample:this._text.slice(0,Math.min(100,this._text.length))+(this._text.length>100?"...":"")})}debug(t,...e){this.config.debugLogger&&this.config.debugLogger(t,...e)}clone(){return new _(this._text,f({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new n.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!c.isXmlChar(this.currCodeUnitUnchecked()))throw new n.XmlError({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}goToEnd(){this._pos=this._end}startsWith(t){return this._text.startsWith(t,this._pos)}startsWithIgnoreCase(t){if(this._pos+t.length>this._end)return!1;for(let e=0;e<t.length;e++){const s=this._text.charCodeAt(this._pos+e),r=t.charCodeAt(e);if((s>=97&&s<=122?s-32:s)!==r)return!1}return!0}skipString(t){if(!this.startsWith(t))throw new n.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&c.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new n.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),s=e.consumeReference();return s!=null?(this._pos+=e.getPos()-t,s):null}consumeReference(){if(!this.tryConsumeCodeUnit(o.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(o.HASH)){let e,s;this.tryConsumeCodeUnit(o.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(i=>i>=o.ZERO&&i<=o.NINE||i>=o.UPPERCASE_A&&i<=o.UPPERCASE_F||i>=o.LOWERCASE_A&&i<=o.LOWERCASE_F),s=16):(e=this.consumeCodeUnitsWhile(i=>c.isAsciiDigit(i)),s=10);const r=parseInt(e,s);isNaN(r)||!c.isXmlChar(r)?t=null:t={type:"Char",value:String.fromCodePoint(r)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(o.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!c.isXmlNameStart(e))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!c.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e,s,r;const i=this._pos;let p=null;for(this.debug("Starting consumeQName",{position:this._pos,nextChars:this._text.slice(this._pos,this._pos+10)});this._pos<this._end;){const u=this.currCodeUnitUnchecked();if(u===o.COLON)if(p==null)p=this._pos,this._pos+=1,this.debug("Found colon splitter",{position:this._pos});else throw this.debug("Multiple colons found - error",{position:this._pos}),new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));else if(c.isXmlName(u))this._pos+=1;else break}let h,l;if(p!=null?(h=this._text.slice(i,p),l=this.sliceBack(p+1)):(h="",l=this.sliceBack(i)),this.debug("Finished consumeQName",{prefix:h,local:l,startPos:i,endPos:this._pos}),h.length>0&&!c.isXmlNameStart((t=h[0])==null?void 0:t.codePointAt(0)))throw this.debug("Invalid prefix start character",{prefix:h,firstChar:h[0],codePoint:(e=h[0])==null?void 0:e.codePointAt(0)}),new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));if(l.length>0){if(!c.isXmlNameStart((s=l[0])==null?void 0:s.codePointAt(0)))throw this.debug("Invalid local name start character",{local:l,firstChar:l[0],codePoint:(r=l[0])==null?void 0:r.codePointAt(0)}),new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i))}else throw this.debug("Empty local name - error"),new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));return[h,l]}consumeQuote(){const t=this.currCodeUnit();if(t===o.SINGLE_QUOTE||t===o.DOUBLE_QUOTE)return this._pos+=1,t;throw new n.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}getTextAround(t,e){const s=Math.floor(e/2),r=Math.max(0,t-s),i=Math.min(this._end,t+s+e%2);return this._text.slice(r,i)}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let s=1,r=1;for(let i=0;i<e;i++)this._text.charCodeAt(i)===o.LINE_FEED?(s++,r=1):r++;return f({row:s,col:r},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}getTextSnippet(t,e){return this._text.slice(t,t+e)}}exports.XmlStream=_;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AMPERSAND as C,HASH as S,LOWERCASE_X as U,ZERO as w,NINE as y,UPPERCASE_A as P,UPPERCASE_F as v,LOWERCASE_A as E,LOWERCASE_F as b,SEMICOLON as k,COLON as N,SINGLE_QUOTE as T,DOUBLE_QUOTE as A,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as _,isXmlSpaceByte as I,isAsciiDigit as W,isXmlNameStart as u,isXmlName as g}from"./utils.js";import{XmlError as n}from"./XmlError.js";var F=Object.defineProperty,f=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,d=(c,t,e)=>t in c?F(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,x=(c,t)=>{for(var e in t||(t={}))L.call(t,e)&&d(c,e,t[e]);if(f)for(var e of f(t))R.call(t,e)&&d(c,e,t[e]);return c},p=(c,t,e)=>d(c,typeof t!="symbol"?t+"":t,e);class m{constructor(t,e={}){p(this,"_text"),p(this,"_pos"),p(this,"_end"),p(this,"config");const{pos:s=0,strictDocument:o=!0,allowDtd:i=!0,rawTextElements:a=null,implicitSelfClosingElements:r=null,contextSliceSize:h=!1,debugLogger:l}=e;this.debug("XmlStream constructor",{textLength:t.length,initialPos:s,platform:process.platform,nodeVersion:process.version,textSample:t.slice(0,Math.min(100,t.length))+(t.length>100?"...":"")}),this.
|
|
1
|
+
import{AMPERSAND as C,HASH as S,LOWERCASE_X as U,ZERO as w,NINE as y,UPPERCASE_A as P,UPPERCASE_F as v,LOWERCASE_A as E,LOWERCASE_F as b,SEMICOLON as k,COLON as N,SINGLE_QUOTE as T,DOUBLE_QUOTE as A,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as _,isXmlSpaceByte as I,isAsciiDigit as W,isXmlNameStart as u,isXmlName as g}from"./utils.js";import{XmlError as n}from"./XmlError.js";var F=Object.defineProperty,f=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,d=(c,t,e)=>t in c?F(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,x=(c,t)=>{for(var e in t||(t={}))L.call(t,e)&&d(c,e,t[e]);if(f)for(var e of f(t))R.call(t,e)&&d(c,e,t[e]);return c},p=(c,t,e)=>d(c,typeof t!="symbol"?t+"":t,e);class m{constructor(t,e={}){p(this,"_text"),p(this,"_pos"),p(this,"_end"),p(this,"config");const{pos:s=0,strictDocument:o=!0,allowDtd:i=!0,rawTextElements:a=null,implicitSelfClosingElements:r=null,contextSliceSize:h=!1,debugLogger:l}=e;this._text=t,this._pos=s,this._end=this._text.length,this.config={strictDocument:o,allowDtd:i,rawTextElements:a,implicitSelfClosingElements:r,contextSliceSize:h,debugLogger:l},this.debug("XmlStream constructor",{textLength:t.length,initialPos:s,platform:process.platform,nodeVersion:process.version,textSample:t.slice(0,Math.min(100,t.length))+(t.length>100?"...":"")}),this.debug("XmlStream initialized",{textLength:this._text.length,initialPos:s,platform:process.platform,nodeVersion:process.version,textSample:this._text.slice(0,Math.min(100,this._text.length))+(this._text.length>100?"...":"")})}debug(t,...e){this.config.debugLogger&&this.config.debugLogger(t,...e)}clone(){return new m(this._text,x({pos:this._pos},this.config))}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)}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}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!_(this.currCodeUnitUnchecked()))throw new n({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}goToEnd(){this._pos=this._end}startsWith(t){return this._text.startsWith(t,this._pos)}startsWithIgnoreCase(t){if(this._pos+t.length>this._end)return!1;for(let e=0;e<t.length;e++){const s=this._text.charCodeAt(this._pos+e),o=t.charCodeAt(e);if((s>=97&&s<=122?s-32:s)!==o)return!1}return!0}skipString(t){if(!this.startsWith(t))throw new n({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&I(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(),s=e.consumeReference();return s!=null?(this._pos+=e.getPos()-t,s):null}consumeReference(){if(!this.tryConsumeCodeUnit(C))return null;let t;if(this.tryConsumeCodeUnit(S)){let e,s;this.tryConsumeCodeUnit(U)?(e=this.consumeCodeUnitsWhile(i=>i>=w&&i<=y||i>=P&&i<=v||i>=E&&i<=b),s=16):(e=this.consumeCodeUnitsWhile(i=>W(i)),s=10);const o=parseInt(e,s);isNaN(o)||!_(o)?t=null:t={type:"Char",value:String.fromCodePoint(o)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(k)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new n({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!u(e))throw new n({type:"InvalidName"},this.genTextPosFrom(t))}else if(!g(e))break;this._pos+=1}}consumeQName(){var t,e,s,o;const i=this._pos;let a=null;for(this.debug("Starting consumeQName",{position:this._pos,nextChars:this._text.slice(this._pos,this._pos+10)});this._pos<this._end;){const l=this.currCodeUnitUnchecked();if(l===N)if(a==null)a=this._pos,this._pos+=1,this.debug("Found colon splitter",{position:this._pos});else throw this.debug("Multiple colons found - error",{position:this._pos}),new n({type:"InvalidName"},this.genTextPosFrom(i));else if(g(l))this._pos+=1;else break}let r,h;if(a!=null?(r=this._text.slice(i,a),h=this.sliceBack(a+1)):(r="",h=this.sliceBack(i)),this.debug("Finished consumeQName",{prefix:r,local:h,startPos:i,endPos:this._pos}),r.length>0&&!u((t=r[0])==null?void 0:t.codePointAt(0)))throw this.debug("Invalid prefix start character",{prefix:r,firstChar:r[0],codePoint:(e=r[0])==null?void 0:e.codePointAt(0)}),new n({type:"InvalidName"},this.genTextPosFrom(i));if(h.length>0){if(!u((s=h[0])==null?void 0:s.codePointAt(0)))throw this.debug("Invalid local name start character",{local:h,firstChar:h[0],codePoint:(o=h[0])==null?void 0:o.codePointAt(0)}),new n({type:"InvalidName"},this.genTextPosFrom(i))}else throw this.debug("Empty local name - error"),new n({type:"InvalidName"},this.genTextPosFrom(i));return[r,h]}consumeQuote(){const t=this.currCodeUnit();if(t===T||t===A)return this._pos+=1,t;throw new n({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}getTextAround(t,e){const s=Math.floor(e/2),o=Math.max(0,t-s),i=Math.min(this._end,t+s+e%2);return this._text.slice(o,i)}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let s=1,o=1;for(let i=0;i<e;i++)this._text.charCodeAt(i)===O?(s++,o=1):o++;return x({row:s,col:o},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}getTextSnippet(t,e){return this._text.slice(t,t+e)}}export{m as XmlStream};
|