xml-tokenizer 0.0.31 → 0.0.33
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/index.js +1 -1
- package/dist/cjs/processor/process.js +1 -0
- package/dist/cjs/processor/processors/path-tracker.js +1 -0
- package/dist/cjs/processor/validate-processor-order.js +5 -0
- package/dist/cjs/tokenizer/XmlStream.js +1 -1
- package/dist/cjs/tokenizer/tokenize.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/processor/process.js +1 -0
- package/dist/esm/processor/processors/path-tracker.js +1 -0
- package/dist/esm/processor/validate-processor-order.js +5 -0
- package/dist/esm/tokenizer/XmlStream.js +1 -1
- package/dist/esm/tokenizer/tokenize.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/processor/index.d.ts +4 -0
- package/dist/types/processor/process.d.ts +3 -0
- package/dist/types/processor/processors/index.d.ts +1 -0
- package/dist/types/processor/processors/path-tracker.d.ts +5 -0
- package/dist/types/processor/types.d.ts +10 -0
- package/dist/types/processor/validate-processor-order.d.ts +2 -0
- package/dist/types/tokenizer/XmlStream.d.ts +7 -0
- package/package.json +8 -7
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=require("./config.js"),a=require("./get-q-name.js"),A=require("./processor/process.js"),T=require("./processor/processors/path-tracker.js"),R=require("./processor/validate-processor-order.js"),l=require("./selector/select.js"),m=require("./selector/TokenSelector.js"),t=require("./selector/TokenSelectState.js"),O=require("./selector/TokenSelectStateMachine.js"),C=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),i=require("./tokenizer/tokenize.js"),r=require("./tokenizer/utils.js"),s=require("./tokenizer/XmlError.js"),c=require("./tokenizer/XmlStream.js"),N=require("./tokens-to-xml.js"),S=require("./xml-to-object.js"),o=require("./xml-to-simplified-object.js");exports.htmlConfig=E.htmlConfig,exports.svgConfig=E.svgConfig,exports.xmlConfig=E.xmlConfig,exports.getQName=a.getQName,exports.process=A.process,exports.pathTracker=T.pathTracker,exports.validateProcessorOrder=R.validateProcessorOrder,exports.select=l.select,exports.TokenSelector=m.TokenSelector,exports.EToCacheNodeProps=t.EToCacheNodeProps,exports.ETokenMatchCriteria=t.ETokenMatchCriteria,exports.TokenSelectState=t.TokenSelectState,exports.TokenSelectStateMachine=O.TokenSelectStateMachine,exports.tokenToXml=C.tokenToXml,exports.AMPERSAND=e.AMPERSAND,exports.CARRIAGE_RETURN=e.CARRIAGE_RETURN,exports.CLOSE_SQUARE_BRACKET=e.CLOSE_SQUARE_BRACKET,exports.COLON=e.COLON,exports.DOUBLE_QUOTE=e.DOUBLE_QUOTE,exports.EQUALS=e.EQUALS,exports.EXCLAMATION_MARK=e.EXCLAMATION_MARK,exports.GREATER_THAN=e.GREATER_THAN,exports.HASH=e.HASH,exports.HORIZONTAL_TAB=e.HORIZONTAL_TAB,exports.HYPHEN=e.HYPHEN,exports.LESS_THAN=e.LESS_THAN,exports.LINE_FEED=e.LINE_FEED,exports.LOWERCASE_A=e.LOWERCASE_A,exports.LOWERCASE_F=e.LOWERCASE_F,exports.LOWERCASE_X=e.LOWERCASE_X,exports.LOWERCASE_Z=e.LOWERCASE_Z,exports.NINE=e.NINE,exports.OPEN_SQUARE_BRACKET=e.OPEN_SQUARE_BRACKET,exports.PERCENT=e.PERCENT,exports.PERIOD=e.PERIOD,exports.QUESTION_MARK=e.QUESTION_MARK,exports.SEMICOLON=e.SEMICOLON,exports.SINGLE_QUOTE=e.SINGLE_QUOTE,exports.SLASH=e.SLASH,exports.SPACE=e.SPACE,exports.UNDERSCORE=e.UNDERSCORE,exports.UPPERCASE_A=e.UPPERCASE_A,exports.UPPERCASE_F=e.UPPERCASE_F,exports.UPPERCASE_P=e.UPPERCASE_P,exports.UPPERCASE_S=e.UPPERCASE_S,exports.UPPERCASE_Z=e.UPPERCASE_Z,exports.ZERO=e.ZERO,exports.tokenize=i.tokenize,exports.tokenizeXmlStream=i.tokenizeXmlStream,exports.isAsciiDigit=r.isAsciiDigit,exports.isXmlChar=r.isXmlChar,exports.isXmlName=r.isXmlName,exports.isXmlNameByte=r.isXmlNameByte,exports.isXmlNameStart=r.isXmlNameStart,exports.isXmlSpaceByte=r.isXmlSpaceByte,exports.XmlError=s.XmlError,exports.XmlStream=c.XmlStream,exports.tokensToXml=N.tokensToXml,exports.processTokenForObject=S.processTokenForObject,exports.xmlToObject=S.xmlToObject,exports.processTokenForSimplifiedObject=o.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=o.xmlToSimplifiedObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=require("../tokenizer/tokenize.js"),i=require("./validate-processor-order.js");function l(c,r,n){i.validateProcessorOrder(r);const e={};for(const s of r)Object.assign(e,s.context);return a.tokenize(c,s=>{var o;for(const t of r)(o=t.process)==null||o.call(t,s,e)},n),e}exports.process=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const a={name:"PathTracker",context:{currentPath:[]},process:(t,e)=>{if(t.type==="ElementStart"){const r=t.prefix?`${t.prefix}:${t.local}`:t.local;e.currentPath.push(r)}else t.type==="ElementEnd"&&t.end.type==="Close"&&e.currentPath.pop()}};exports.pathTracker=a;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";function p(r){const t=new Set;for(let s=0;s<r.length;s++){const o=r[s];if(o.deps==null){t.add(o);continue}const d=[];for(const n of o.deps)t.has(n)||d.push(n);if(d.length>0){const n=o.name||`Processor[${s}]`,a=d.map((e,c)=>{const i=r.indexOf(e);return e.name||`Processor[${i>=0?i:c}]`}).join(", "),l=r.filter(e=>e!=null).map((e,c)=>e.name||`Processor[${c}]`).join(" \u2192 ");throw new Error(`Processor dependency order invalid:
|
|
2
|
+
${n} depends on: ${a}
|
|
3
|
+
But those dependencies haven't been processed yet.
|
|
4
|
+
Current order: ${l}
|
|
5
|
+
Solution: Move dependencies before ${n} in the processors array.`)}t.add(o)}}exports.validateProcessorOrder=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("./ascii-constants.js"),
|
|
1
|
+
"use strict";var n=require("./ascii-constants.js"),a=require("./utils.js"),o=require("./XmlError.js"),f=Object.defineProperty,d=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,p=(h,t,e)=>t in h?f(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,_=(h,t)=>{for(var e in t||(t={}))E.call(t,e)&&p(h,e,t[e]);if(d)for(var e of d(t))g.call(t,e)&&p(h,e,t[e]);return h},u=(h,t,e)=>p(h,typeof t!="symbol"?t+"":t,e);class m{constructor(t,e={}){u(this,"_text"),u(this,"_pos"),u(this,"_end"),u(this,"config");const{pos:s=0,strictDocument:r=!0,allowDtd:i=!0,rawTextElements:l=null,implicitSelfClosingElements:c=null,contextSliceSize:C=!1}=e;this._text=t,this._pos=s,this._end=this._text.length,this.config={strictDocument:r,allowDtd:i,rawTextElements:l,implicitSelfClosingElements:c,contextSliceSize:C}}clone(){return new m(this._text,_({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!a.isXmlChar(this.currCodeUnitUnchecked()))throw new o.XmlError({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}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 o.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&a.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),s=e.consumeReference();return s!=null?(this._pos+=e.getPos()-t,s):null}consumeReference(){if(!this.tryConsumeCodeUnit(n.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(n.HASH)){let e,s;this.tryConsumeCodeUnit(n.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(i=>i>=n.ZERO&&i<=n.NINE||i>=n.UPPERCASE_A&&i<=n.UPPERCASE_F||i>=n.LOWERCASE_A&&i<=n.LOWERCASE_F),s=16):(e=this.consumeCodeUnitsWhile(i=>a.isAsciiDigit(i)),s=10);const r=parseInt(e,s);isNaN(r)||!a.isXmlChar(r)?t=null:t={type:"Char",value:String.fromCodePoint(r)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(n.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!a.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!a.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const s=this._pos;let r=null;for(;this._pos<this._end;){const c=this.currCodeUnitUnchecked();if(c===n.COLON)if(r==null)r=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(s));else if(a.isXmlName(c))this._pos+=1;else break}let i,l;if(r!=null?(i=this._text.slice(s,r),l=this.sliceBack(r+1)):(i="",l=this.sliceBack(s)),i.length>0&&!a.isXmlNameStart((t=i[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(s));if(l.length>0){if(!a.isXmlNameStart((e=l[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(s))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(s));return[i,l]}consumeQuote(){const t=this.currCodeUnit();if(t===n.SINGLE_QUOTE||t===n.DOUBLE_QUOTE)return this._pos+=1,t;throw new o.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}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)===n.LINE_FEED?(s++,r=1):r++;return _({row:s,col:r},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}}exports.XmlStream=m;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=require("../get-q-name.js"),s=require("./ascii-constants.js"),L=require("./utils.js"),c=require("./XmlError.js"),H=require("./XmlStream.js");const Q="\uFEFF",A="<?xml ",k="?>",D="<!ENTITY",F="<!ELEMENT",O="<!ATTLIST",G="<!NOTATION",p="<!DOCTYPE",w="<?",W="?>",E="<!--",y="-->",b="<![CDATA[",f="]]>",B="NDATA",N="PUBLIC",M="SYSTEM",q="version",K="encoding",Y="standalone";function z(t,n,e={}){P(new H.XmlStream(t,e),n)}function P(t,n){if(t.startsWith(Q)&&t.advance(1),t.startsWith(A)&&$(t),m(t,n),t.config.strictDocument){if(t.skipSpaces(),t.startsWithIgnoreCase(p)&&(S(t,n),m(t,n)),t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===s.LESS_THAN&&T(t,n),m(t,n),!t.atEnd())throw new c.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===s.LESS_THAN?T(t,n):R(t,n),m(t,n)}function m(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(E))g(t,n);else if(!t.config.strictDocument&&t.startsWithIgnoreCase(p))S(t,n);else if(t.startsWith(w))h(t,n);else break}function $(t){function n(e){if(e.startsWithSpace())e.skipSpaces();else if(!e.startsWith(k)&&!e.atEnd())throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:e.currCodeUnitUnchecked()},e.genTextPos())}if(t.advance(5),n(t),!t.startsWith(q))throw new c.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());d(t),n(t),t.startsWith(K)&&(d(t),n(t)),t.startsWith(Y)&&d(t),t.skipSpaces(),t.skipString(k)}function g(t,n){const e=t.getPos();t.advance(4);const o=t.consumeCodeUnitsWhile((i,r)=>!(i===s.HYPHEN&&r.startsWith(y)));if(t.skipString(y),o.includes("--")||o.endsWith("-"))throw new c.XmlError({type:"InvalidComment"},t.genTextPosFrom(e));n({type:"Comment",text:o,range:t.rangeFrom(e)},t)}function h(t,n){if(t.startsWith(A))throw new c.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const e=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const i=t.consumeCodeUnitsWhile((r,a)=>!(r===s.QUESTION_MARK&&a.startsWith(W)));t.skipString(W),n({type:"ProcessingInstruction",target:o,content:i.length===0?void 0:i,range:t.rangeFrom(e)},t)}function S(t,n){if(!t.config.allowDtd)throw new c.XmlError({type:"DtdDetected"});const e=t.getPos();if(j(t),t.skipSpaces(),t.currCodeUnit()===s.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(D))J(t,n);else if(t.startsWith(E))g(t,n);else if(t.startsWith(w))h(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===s.GREATER_THAN){t.advance(1);break}else throw new c.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(F)||t.startsWith(O)||t.startsWith(G))try{Z(t)}catch(o){throw new c.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(e))}else throw new c.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function j(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),x(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==s.OPEN_SQUARE_BRACKET&&n!==s.GREATER_THAN)throw new c.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function x(t){if(t.startsWith(M)||t.startsWith(N)){const n=t.getPos();t.advance(6);const e=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o),e===N){t.consumeSpaces();const i=t.consumeQuote();t.consumeCodeUnitsWhile(r=>r!==i),t.consumeCodeUnit(i)}return!0}return!1}function J(t,n){t.advance(8),t.consumeSpaces();const e=!t.tryConsumeCodeUnit(s.PERCENT);e||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const i=V(t,e);i!==null&&n({type:"EntityDeclaration",name:o,definition:i},t),t.skipSpaces(),t.consumeCodeUnit(s.GREATER_THAN)}function V(t,n){const e=t.currCodeUnit();if(e===s.DOUBLE_QUOTE||e===s.SINGLE_QUOTE){const o=t.consumeQuote(),i=t.getPos();t.skipCodeUnitsWhile(a=>a!==o);const r=t.sliceBack(i);return t.consumeCodeUnit(o),r}else if(e===s.UPPERCASE_S||e===s.UPPERCASE_P){if(x(t))return n&&(t.skipSpaces(),t.startsWith(B)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new c.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new c.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:e},t.genTextPos())}function Z(t){t.skipCodeUnitsWhile(n=>n!==s.GREATER_THAN),t.consumeCodeUnit(s.GREATER_THAN)}function T(t,n){const e=t.getPos();t.advance(1);const[o,i]=t.consumeQName();n({type:"ElementStart",prefix:o,local:i,start:e},t);let r=!1;for(;!t.atEnd();){const a=t.startsWithSpace();t.skipSpaces();const l=t.getPos(),C=t.currCodeUnit();if(C===s.SLASH){t.advance(1),t.consumeCodeUnit(s.GREATER_THAN);const u=t.rangeFrom(l);n({type:"ElementEnd",end:{type:"Empty"},range:u},t);break}else if(C===s.GREATER_THAN){t.advance(1);const u=t.rangeFrom(l);if(t.config.implicitSelfClosingElements!=null&&t.config.implicitSelfClosingElements.includes(U.getQName(i,o))){n({type:"ElementEnd",end:{type:"Empty"},range:u},t);break}else{n({type:"ElementEnd",end:{type:"Open"},range:u},t),r=!0;break}}else{if(!a)throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[u,_,I]=d(t),X=t.getPos();n({type:"Attribute",range:{start:l,end:X},prefix:u,local:_,value:I},t)}}if(r){if(t.config.rawTextElements!=null){const a=U.getQName(i,o);if(t.config.rawTextElements.includes(a)){v(t,n,`</${a}>`);return}}v(t,n)}}function d(t){const[n,e]=t.consumeQName();let o;const i=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(s.EQUALS)){t.skipSpaces();const r=t.currCodeUnit();if(r===s.SINGLE_QUOTE||r===s.DOUBLE_QUOTE){const a=t.consumeQuote();o=t.consumeCodeUnitsWhile(l=>l!==a&&l!==s.LESS_THAN),t.consumeCodeUnit(a)}else if(!t.config.strictDocument)o=t.consumeCodeUnitsWhile(a=>!L.isXmlSpaceByte(a)&&a!==s.GREATER_THAN&&a!==s.SLASH&&a!==s.LESS_THAN);else throw new c.XmlError({type:"InvalidChar",expected:"a quote",actual:r},t.genTextPos())}else if(!t.config.strictDocument)t.goTo(i),o="true";else throw new c.XmlError({type:"InvalidChar",expected:s.EQUALS,actual:t.currCodeUnit()},t.genTextPos());return[n,e,o]}function v(t,n,e=s.LESS_THAN){for(;!t.atEnd();)if(typeof e=="number"?t.currCodeUnit()===e:t.startsWith(e)){const o=t.nextCodeUnit();if(o===s.EXCLAMATION_MARK)if(t.startsWith(E))g(t,n);else if(t.startsWith(b))tt(t,n);else if(!t.config.strictDocument&&t.startsWithIgnoreCase(p))S(t,n);else throw new c.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(o===s.QUESTION_MARK)h(t,n);else if(o===s.SLASH){nt(t,n);break}else T(t,n)}else R(t,n,e)}function tt(t,n){const e=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((r,a)=>!(r===s.CLOSE_SQUARE_BRACKET&&a.startsWith(f)));t.skipString(f);const i=t.rangeFrom(e);n({type:"Cdata",text:o,range:i},t)}function nt(t,n){const e=t.getPos();t.advance(2);const[o,i]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(s.GREATER_THAN);const r=t.rangeFrom(e);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:i},range:r},t)}function R(t,n,e=s.LESS_THAN){const o=t.getPos(),i=typeof e=="number"?t.consumeCodeUnitsWhile(r=>r!==e):t.consumeCodeUnitsWhile((r,a)=>!a.startsWith(e));if(t.config.strictDocument&&i.includes(f))throw new c.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:i,range:t.rangeFrom(o)},t)}exports.tokenize=z,exports.tokenizeXmlStream=P;
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{htmlConfig as
|
|
1
|
+
import{htmlConfig as r,svgConfig as E,xmlConfig as t}from"./config.js";import{getQName as S}from"./get-q-name.js";import{process as R}from"./processor/process.js";import{pathTracker as i}from"./processor/processors/path-tracker.js";import{validateProcessorOrder as O}from"./processor/validate-processor-order.js";import{select as f}from"./selector/select.js";import{TokenSelector as _}from"./selector/TokenSelector.js";import{EToCacheNodeProps as x,ETokenMatchCriteria as a,TokenSelectState as s}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as c}from"./selector/TokenSelectStateMachine.js";import{tokenToXml as n}from"./token-to-xml.js";import{AMPERSAND as X,CARRIAGE_RETURN as k,CLOSE_SQUARE_BRACKET as I,COLON as H,DOUBLE_QUOTE as M,EQUALS as Q,EXCLAMATION_MARK as g,GREATER_THAN as h,HASH as B,HORIZONTAL_TAB as D,HYPHEN as d,LESS_THAN as F,LINE_FEED as b,LOWERCASE_A as j,LOWERCASE_F as K,LOWERCASE_X as W,LOWERCASE_Z as Z,NINE as G,OPEN_SQUARE_BRACKET as v,PERCENT as y,PERIOD as z,QUESTION_MARK as Y,SEMICOLON as q,SINGLE_QUOTE as u,SLASH as w,SPACE as J,UNDERSCORE as V,UPPERCASE_A as $,UPPERCASE_F as ee,UPPERCASE_P as oe,UPPERCASE_S as re,UPPERCASE_Z as Ee,ZERO as te}from"./tokenizer/ascii-constants.js";import{tokenize as Se,tokenizeXmlStream as Ae}from"./tokenizer/tokenize.js";import{isAsciiDigit as pe,isXmlChar as ie,isXmlName as Ce,isXmlNameByte as Oe,isXmlNameStart as Te,isXmlSpaceByte as fe}from"./tokenizer/utils.js";import{XmlError as _e}from"./tokenizer/XmlError.js";import{XmlStream as xe}from"./tokenizer/XmlStream.js";import{tokensToXml as se}from"./tokens-to-xml.js";import{processTokenForObject as ce,xmlToObject as Le}from"./xml-to-object.js";import{processTokenForSimplifiedObject as Ue,xmlToSimplifiedObject as Xe}from"./xml-to-simplified-object.js";export{X as AMPERSAND,k as CARRIAGE_RETURN,I as CLOSE_SQUARE_BRACKET,H as COLON,M as DOUBLE_QUOTE,Q as EQUALS,x as EToCacheNodeProps,a as ETokenMatchCriteria,g as EXCLAMATION_MARK,h as GREATER_THAN,B as HASH,D as HORIZONTAL_TAB,d as HYPHEN,F as LESS_THAN,b as LINE_FEED,j as LOWERCASE_A,K as LOWERCASE_F,W as LOWERCASE_X,Z as LOWERCASE_Z,G as NINE,v as OPEN_SQUARE_BRACKET,y as PERCENT,z as PERIOD,Y as QUESTION_MARK,q as SEMICOLON,u as SINGLE_QUOTE,w as SLASH,J as SPACE,s as TokenSelectState,c as TokenSelectStateMachine,_ as TokenSelector,V as UNDERSCORE,$ as UPPERCASE_A,ee as UPPERCASE_F,oe as UPPERCASE_P,re as UPPERCASE_S,Ee as UPPERCASE_Z,_e as XmlError,xe as XmlStream,te as ZERO,S as getQName,r as htmlConfig,pe as isAsciiDigit,ie as isXmlChar,Ce as isXmlName,Oe as isXmlNameByte,Te as isXmlNameStart,fe as isXmlSpaceByte,i as pathTracker,R as process,ce as processTokenForObject,Ue as processTokenForSimplifiedObject,f as select,E as svgConfig,n as tokenToXml,Se as tokenize,Ae as tokenizeXmlStream,se as tokensToXml,O as validateProcessorOrder,t as xmlConfig,Le as xmlToObject,Xe as xmlToSimplifiedObject};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tokenize as f}from"../tokenizer/tokenize.js";import{validateProcessorOrder as i}from"./validate-processor-order.js";function a(c,o,n){i(o);const r={};for(const t of o)Object.assign(r,t.context);return f(c,t=>{var e;for(const s of o)(e=s.process)==null||e.call(s,t,r)},n),r}export{a as process};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a={name:"PathTracker",context:{currentPath:[]},process:(t,e)=>{if(t.type==="ElementStart"){const r=t.prefix?`${t.prefix}:${t.local}`:t.local;e.currentPath.push(r)}else t.type==="ElementEnd"&&t.end.type==="Close"&&e.currentPath.pop()}};export{a as pathTracker};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function l(r){const t=new Set;for(let s=0;s<r.length;s++){const o=r[s];if(o.deps==null){t.add(o);continue}const d=[];for(const n of o.deps)t.has(n)||d.push(n);if(d.length>0){const n=o.name||`Processor[${s}]`,a=d.map((e,c)=>{const i=r.indexOf(e);return e.name||`Processor[${i>=0?i:c}]`}).join(", "),p=r.filter(e=>e!=null).map((e,c)=>e.name||`Processor[${c}]`).join(" \u2192 ");throw new Error(`Processor dependency order invalid:
|
|
2
|
+
${n} depends on: ${a}
|
|
3
|
+
But those dependencies haven't been processed yet.
|
|
4
|
+
Current order: ${p}
|
|
5
|
+
Solution: Move dependencies before ${n} in the processors array.`)}t.add(o)}}export{l as validateProcessorOrder};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AMPERSAND as x,HASH as g,LOWERCASE_X as U,ZERO as w,NINE as y,UPPERCASE_A as S,UPPERCASE_F as E,LOWERCASE_A as v,LOWERCASE_F as P,SEMICOLON as k,COLON as N,SINGLE_QUOTE as T,DOUBLE_QUOTE as
|
|
1
|
+
import{AMPERSAND as x,HASH as g,LOWERCASE_X as U,ZERO as w,NINE as y,UPPERCASE_A as S,UPPERCASE_F as E,LOWERCASE_A as v,LOWERCASE_F as P,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 d,isXmlSpaceByte as b,isAsciiDigit as I,isXmlNameStart as l,isXmlName as _}from"./utils.js";import{XmlError as o}from"./XmlError.js";var W=Object.defineProperty,m=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,p=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,f=(r,t)=>{for(var e in t||(t={}))F.call(t,e)&&p(r,e,t[e]);if(m)for(var e of m(t))R.call(t,e)&&p(r,e,t[e]);return r},a=(r,t,e)=>p(r,typeof t!="symbol"?t+"":t,e);class u{constructor(t,e={}){a(this,"_text"),a(this,"_pos"),a(this,"_end"),a(this,"config");const{pos:s=0,strictDocument:n=!0,allowDtd:i=!0,rawTextElements:h=null,implicitSelfClosingElements:c=null,contextSliceSize:C=!1}=e;this._text=t,this._pos=s,this._end=this._text.length,this.config={strictDocument:n,allowDtd:i,rawTextElements:h,implicitSelfClosingElements:c,contextSliceSize:C}}clone(){return new u(this._text,f({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!d(this.currCodeUnitUnchecked()))throw new o({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}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),n=t.charCodeAt(e);if((s>=97&&s<=122?s-32:s)!==n)return!1}return!0}skipString(t){if(!this.startsWith(t))throw new o({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&b(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),s=e.consumeReference();return s!=null?(this._pos+=e.getPos()-t,s):null}consumeReference(){if(!this.tryConsumeCodeUnit(x))return null;let t;if(this.tryConsumeCodeUnit(g)){let e,s;this.tryConsumeCodeUnit(U)?(e=this.consumeCodeUnitsWhile(i=>i>=w&&i<=y||i>=S&&i<=E||i>=v&&i<=P),s=16):(e=this.consumeCodeUnitsWhile(i=>I(i)),s=10);const n=parseInt(e,s);isNaN(n)||!d(n)?t=null:t={type:"Char",value:String.fromCodePoint(n)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(k)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!l(e))throw new o({type:"InvalidName"},this.genTextPosFrom(t))}else if(!_(e))break;this._pos+=1}}consumeQName(){var t,e;const s=this._pos;let n=null;for(;this._pos<this._end;){const c=this.currCodeUnitUnchecked();if(c===N)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(s));else if(_(c))this._pos+=1;else break}let i,h;if(n!=null?(i=this._text.slice(s,n),h=this.sliceBack(n+1)):(i="",h=this.sliceBack(s)),i.length>0&&!l((t=i[0])==null?void 0:t.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(s));if(h.length>0){if(!l((e=h[0])==null?void 0:e.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(s))}else throw new o({type:"InvalidName"},this.genTextPosFrom(s));return[i,h]}consumeQuote(){const t=this.currCodeUnit();if(t===T||t===A)return this._pos+=1,t;throw new o({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}getTextAround(t,e){const s=Math.floor(e/2),n=Math.max(0,t-s),i=Math.min(this._end,t+s+e%2);return this._text.slice(n,i)}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let s=1,n=1;for(let i=0;i<e;i++)this._text.charCodeAt(i)===O?(s++,n=1):n++;return f({row:s,col:n},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}}export{u as XmlStream};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getQName as
|
|
1
|
+
import{getQName as w}from"../get-q-name.js";import{LESS_THAN as d,GREATER_THAN as r,SLASH as f,EQUALS as W,SINGLE_QUOTE as y,DOUBLE_QUOTE as P,HYPHEN as M,QUESTION_MARK as x,OPEN_SQUARE_BRACKET as X,PERCENT as H,EXCLAMATION_MARK as Y,UPPERCASE_S as K,UPPERCASE_P as q,CLOSE_SQUARE_BRACKET as z}from"./ascii-constants.js";import{isXmlSpaceByte as G}from"./utils.js";import{XmlError as a}from"./XmlError.js";import{XmlStream as $}from"./XmlStream.js";const j="\uFEFF",v="<?xml ",I="?>",J="<!ENTITY",V="<!ELEMENT",Z="<!ATTLIST",tt="<!NOTATION",g="<!DOCTYPE",A="<?",N="?>",h="<!--",D="-->",nt="<![CDATA[",C="]]>",st="NDATA",F="PUBLIC",et="SYSTEM",ot="version",it="encoding",ct="standalone";function at(t,n,s={}){Q(new $(t,s),n)}function Q(t,n){if(t.startsWith(j)&&t.advance(1),t.startsWith(v)&&rt(t),u(t,n),t.config.strictDocument){if(t.skipSpaces(),t.startsWithIgnoreCase(g)&&(U(t,n),u(t,n)),t.skipSpaces(),!t.atEnd()&&t.currCodeUnit()===d&&k(t,n),u(t,n),!t.atEnd())throw new a({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===d?k(t,n):O(t,n),u(t,n)}function u(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(h))E(t,n);else if(!t.config.strictDocument&&t.startsWithIgnoreCase(g))U(t,n);else if(t.startsWith(A))S(t,n);else break}function rt(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(I)&&!s.atEnd())throw new a({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(ot))throw new a({type:"InvalidString",expected:"version"},t.genTextPos());m(t),n(t),t.startsWith(it)&&(m(t),n(t)),t.startsWith(ct)&&m(t),t.skipSpaces(),t.skipString(I)}function E(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCodeUnitsWhile((o,i)=>!(o===M&&i.startsWith(D)));if(t.skipString(D),e.includes("--")||e.endsWith("-"))throw new a({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)},t)}function S(t,n){if(t.startsWith(v))throw new a({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const o=t.consumeCodeUnitsWhile((i,c)=>!(i===x&&c.startsWith(N)));t.skipString(N),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)},t)}function U(t,n){if(!t.config.allowDtd)throw new a({type:"DtdDetected"});const s=t.getPos();if(pt(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(J))lt(t,n);else if(t.startsWith(h))E(t,n);else if(t.startsWith(A))S(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new a({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(V)||t.startsWith(Z)||t.startsWith(tt))try{ut(t)}catch(e){throw new a({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new a({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function pt(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),_(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==X&&n!==r)throw new a({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function _(t){if(t.startsWith(et)||t.startsWith(F)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const e=t.consumeQuote();if(t.consumeCodeUnitsWhile(o=>o!==e),t.consumeCodeUnit(e),s===F){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o)}return!0}return!1}function lt(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(H);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=dt(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o},t),t.skipSpaces(),t.consumeCodeUnit(r)}function dt(t,n){const s=t.currCodeUnit();if(s===P||s===y){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const i=t.sliceBack(o);return t.consumeCodeUnit(e),i}else if(s===K||s===q){if(_(t))return n&&(t.skipSpaces(),t.startsWith(st)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a({type:"InvalidExternalID"},t.genTextPos())}else throw new a({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function ut(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function k(t,n){const s=t.getPos();t.advance(1);const[e,o]=t.consumeQName();n({type:"ElementStart",prefix:e,local:o,start:s},t);let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const p=t.getPos(),T=t.currCodeUnit();if(T===f){t.advance(1),t.consumeCodeUnit(r);const l=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Empty"},range:l},t);break}else if(T===r){t.advance(1);const l=t.rangeFrom(p);if(t.config.implicitSelfClosingElements!=null&&t.config.implicitSelfClosingElements.includes(w(o,e))){n({type:"ElementEnd",end:{type:"Empty"},range:l},t);break}else{n({type:"ElementEnd",end:{type:"Open"},range:l},t),i=!0;break}}else{if(!c)throw new a({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[l,R,b]=m(t),B=t.getPos();n({type:"Attribute",range:{start:p,end:B},prefix:l,local:R,value:b},t)}}if(i){if(t.config.rawTextElements!=null){const c=w(o,e);if(t.config.rawTextElements.includes(c)){L(t,n,`</${c}>`);return}}L(t,n)}}function m(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(W)){t.skipSpaces();const i=t.currCodeUnit();if(i===y||i===P){const c=t.consumeQuote();e=t.consumeCodeUnitsWhile(p=>p!==c&&p!==d),t.consumeCodeUnit(c)}else if(!t.config.strictDocument)e=t.consumeCodeUnitsWhile(c=>!G(c)&&c!==r&&c!==f&&c!==d);else throw new a({type:"InvalidChar",expected:"a quote",actual:i},t.genTextPos())}else if(!t.config.strictDocument)t.goTo(o),e="true";else throw new a({type:"InvalidChar",expected:W,actual:t.currCodeUnit()},t.genTextPos());return[n,s,e]}function L(t,n,s=d){for(;!t.atEnd();)if(typeof s=="number"?t.currCodeUnit()===s:t.startsWith(s)){const e=t.nextCodeUnit();if(e===Y)if(t.startsWith(h))E(t,n);else if(t.startsWith(nt))mt(t,n);else if(!t.config.strictDocument&&t.startsWithIgnoreCase(g))U(t,n);else throw new a({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(e===x)S(t,n);else if(e===f){ft(t,n);break}else k(t,n)}else O(t,n,s)}function mt(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCodeUnitsWhile((i,c)=>!(i===z&&c.startsWith(C)));t.skipString(C);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o},t)}function ft(t,n){const s=t.getPos();t.advance(2);const[e,o]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:o},range:i},t)}function O(t,n,s=d){const e=t.getPos(),o=typeof s=="number"?t.consumeCodeUnitsWhile(i=>i!==s):t.consumeCodeUnitsWhile((i,c)=>!c.startsWith(s));if(t.config.strictDocument&&o.includes(C))throw new a({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(e)},t)}export{at as tokenize,Q as tokenizeXmlStream};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type TXmlStreamOptions } from '../tokenizer';
|
|
2
|
+
import { TMergeProcessorContexts, TProcessorAny } from './types';
|
|
3
|
+
export declare function process<GProcessors extends readonly TProcessorAny[]>(xml: string, processors: [...GProcessors], options?: TXmlStreamOptions): TMergeProcessorContexts<GProcessors>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pathTracker, type TPathTrackerContext } from './path-tracker';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TXmlToken } from '../tokenizer';
|
|
2
|
+
export interface TProcessor<GContext = unknown, GDeps extends readonly TProcessorAny[] = []> {
|
|
3
|
+
name?: string;
|
|
4
|
+
context: GContext;
|
|
5
|
+
deps?: GDeps;
|
|
6
|
+
process?: TProcessorTokenCallback<GContext & TMergeProcessorContexts<GDeps>>;
|
|
7
|
+
}
|
|
8
|
+
export type TProcessorAny = TProcessor<any, any>;
|
|
9
|
+
export type TProcessorTokenCallback<GContext = unknown> = (token: TXmlToken, context: GContext) => void;
|
|
10
|
+
export type TMergeProcessorContexts<GProcessors extends readonly TProcessorAny[]> = GProcessors extends [infer Head, ...infer Tail] ? Head extends TProcessorAny ? Tail extends readonly TProcessorAny[] ? Head['context'] & TMergeProcessorContexts<Tail> : Head['context'] : {} : {};
|
|
@@ -101,6 +101,13 @@ export declare class XmlStream {
|
|
|
101
101
|
* @returns True if the stream starts with the text, false otherwise.
|
|
102
102
|
*/
|
|
103
103
|
startsWith(text: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the stream starts with the given text, case-insensitive.
|
|
106
|
+
*
|
|
107
|
+
* @param text - The text to check for (should be uppercase).
|
|
108
|
+
* @returns True if the stream starts with the text (case-insensitive), false otherwise.
|
|
109
|
+
*/
|
|
110
|
+
startsWithIgnoreCase(text: string): boolean;
|
|
104
111
|
/**
|
|
105
112
|
* Skips a specific string in the stream.
|
|
106
113
|
*
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xml-tokenizer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
|
|
6
6
|
"keywords": [],
|
|
7
|
-
"homepage": "https://builder.group/?
|
|
7
|
+
"homepage": "https://builder.group/?utm_source=package-json",
|
|
8
8
|
"bugs": {
|
|
9
9
|
"url": "https://github.com/builder-group/community/issues"
|
|
10
10
|
},
|
|
@@ -23,16 +23,17 @@
|
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/node": "^22.
|
|
26
|
+
"@types/node": "^22.15.29",
|
|
27
27
|
"@types/sax": "^1.2.7",
|
|
28
28
|
"@types/xml2js": "^0.4.14",
|
|
29
29
|
"camaro": "^6.2.3",
|
|
30
|
-
"fast-xml-parser": "^5.
|
|
30
|
+
"fast-xml-parser": "^5.2.3",
|
|
31
31
|
"sax": "^1.4.1",
|
|
32
32
|
"saxen": "^10.0.0",
|
|
33
33
|
"txml": "^5.1.1",
|
|
34
34
|
"xml2js": "^0.6.2",
|
|
35
|
-
"@blgc/config": "0.0.
|
|
35
|
+
"@blgc/config": "0.0.35",
|
|
36
|
+
"rollup-presets": "0.0.21"
|
|
36
37
|
},
|
|
37
38
|
"size-limit": [
|
|
38
39
|
{
|
|
@@ -41,8 +42,8 @@
|
|
|
41
42
|
],
|
|
42
43
|
"scripts": {
|
|
43
44
|
"bench": "vitest bench",
|
|
44
|
-
"build": "shx rm -rf dist &&
|
|
45
|
-
"build:prod": "pnpm build
|
|
45
|
+
"build": "shx rm -rf dist && rollup -c rollup.config.js",
|
|
46
|
+
"build:prod": "export NODE_ENV=production && pnpm build",
|
|
46
47
|
"clean": "shx rm -rf dist && shx rm -rf .turbo && shx rm -rf node_modules",
|
|
47
48
|
"install:clean": "pnpm run clean && pnpm install",
|
|
48
49
|
"lint": "eslint . --fix",
|