xml-tokenizer 0.0.17 → 0.0.19

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.
Files changed (34) hide show
  1. package/README.md +5 -5
  2. package/dist/cjs/get-q-name.js +7 -1
  3. package/dist/cjs/index.js +73 -1
  4. package/dist/cjs/selector/TokenSelectState.js +106 -1
  5. package/dist/cjs/selector/TokenSelectStateMachine.js +150 -1
  6. package/dist/cjs/selector/TokenSelector.js +139 -1
  7. package/dist/cjs/selector/match-string.js +21 -1
  8. package/dist/cjs/selector/select.js +15 -1
  9. package/dist/cjs/token-to-xml.js +44 -1
  10. package/dist/cjs/tokenizer/XmlError.js +96 -1
  11. package/dist/cjs/tokenizer/XmlStream.js +443 -1
  12. package/dist/cjs/tokenizer/ascii-constants.js +69 -1
  13. package/dist/cjs/tokenizer/tokenize.js +388 -1
  14. package/dist/cjs/tokenizer/utils.js +47 -1
  15. package/dist/cjs/tokens-to-xml.js +13 -1
  16. package/dist/cjs/xml-to-object.js +69 -1
  17. package/dist/cjs/xml-to-simplified-object.js +86 -1
  18. package/dist/esm/get-q-name.js +5 -1
  19. package/dist/esm/index.js +13 -1
  20. package/dist/esm/selector/TokenSelectState.js +102 -1
  21. package/dist/esm/selector/TokenSelectStateMachine.js +148 -1
  22. package/dist/esm/selector/TokenSelector.js +137 -1
  23. package/dist/esm/selector/match-string.js +19 -1
  24. package/dist/esm/selector/select.js +13 -1
  25. package/dist/esm/token-to-xml.js +42 -1
  26. package/dist/esm/tokenizer/XmlError.js +94 -1
  27. package/dist/esm/tokenizer/XmlStream.js +441 -1
  28. package/dist/esm/tokenizer/ascii-constants.js +35 -1
  29. package/dist/esm/tokenizer/tokenize.js +385 -1
  30. package/dist/esm/tokenizer/utils.js +40 -1
  31. package/dist/esm/tokens-to-xml.js +11 -1
  32. package/dist/esm/xml-to-object.js +66 -1
  33. package/dist/esm/xml-to-simplified-object.js +83 -1
  34. package/package.json +8 -8
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  <h1 align="center">
2
- <img src="https://raw.githubusercontent.com/builder-group/monorepo/develop/packages/xml-tokenizer/.github/banner.svg" alt="xml-tokenizer banner">
2
+ <img src="https://raw.githubusercontent.com/builder-group/community/develop/packages/xml-tokenizer/.github/banner.svg" alt="xml-tokenizer banner">
3
3
  </h1>
4
4
 
5
5
  <p align="left">
6
- <a href="https://github.com/builder-group/monorepo/blob/develop/LICENSE">
7
- <img src="https://img.shields.io/github/license/builder-group/monorepo.svg?label=license&style=flat&colorA=293140&colorB=FDE200" alt="GitHub License"/>
6
+ <a href="https://github.com/builder-group/community/blob/develop/LICENSE">
7
+ <img src="https://img.shields.io/github/license/builder-group/community.svg?label=license&style=flat&colorA=293140&colorB=FDE200" alt="GitHub License"/>
8
8
  </a>
9
9
  <a href="https://www.npmjs.com/package/xml-tokenizer">
10
10
  <img src="https://img.shields.io/bundlephobia/minzip/xml-tokenizer.svg?label=minzipped%20size&style=flat&colorA=293140&colorB=FDE200" alt="NPM bundle minzipped size"/>
@@ -29,7 +29,7 @@ The implementation is based on the [roxmltree](https://github.com/RazrFalcon/rox
29
29
 
30
30
  ### 📚 Examples
31
31
 
32
- - [Vanilla Profiler](https://github.com/builder-group/monorepo/tree/develop/examples/xml-tokenizer/vanilla/playground)
32
+ - [Vanilla Profiler](https://github.com/builder-group/community/tree/develop/examples/xml-tokenizer/vanilla/playground)
33
33
 
34
34
  ### 🌟 Motivation
35
35
 
@@ -194,7 +194,7 @@ See [Generator vs Iterator vs Callback](https://observablehq.com/@domoritz/yield
194
194
  [fast-xml-parser] Total Time: 1308.0000 ms | Average Time per Run: 13.0800 ms | Median Time: 13.0000 ms | Runs: 100
195
195
  ```
196
196
 
197
- [Benchmark implementation in Vanilla Profiler](https://github.com/builder-group/monorepo/tree/develop/examples/xml-tokenizer/vanilla/playground)
197
+ [Benchmark implementation in Vanilla Profiler](https://github.com/builder-group/community/tree/develop/examples/xml-tokenizer/vanilla/playground)
198
198
 
199
199
  ## 💡 Resources
200
200
 
@@ -1 +1,7 @@
1
- "use strict";function l(t,e=null){return e!=null&&e.length>0?`${e}:${t}`:t}exports.getQName=l;
1
+ 'use strict';
2
+
3
+ function getQName(local, prefix = null) {
4
+ return prefix != null && prefix.length > 0 ? `${prefix}:${local}` : local;
5
+ }
6
+
7
+ exports.getQName = getQName;
package/dist/cjs/index.js CHANGED
@@ -1 +1,73 @@
1
- "use strict";var i=require("./selector/select.js"),o=require("./selector/TokenSelector.js"),S=require("./selector/TokenSelectState.js"),R=require("./selector/TokenSelectStateMachine.js"),T=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),r=require("./tokenizer/tokenize.js"),E=require("./tokenizer/utils.js"),O=require("./tokenizer/XmlError.js"),l=require("./tokenizer/XmlStream.js"),a=require("./tokens-to-xml.js"),t=require("./xml-to-object.js"),A=require("./xml-to-simplified-object.js");exports.select=i.select,exports.TokenSelector=o.TokenSelector,exports.EToCacheNodeProps=S.EToCacheNodeProps,exports.ETokenMatchCriteria=S.ETokenMatchCriteria,exports.TokenSelectState=S.TokenSelectState,exports.TokenSelectStateMachine=R.TokenSelectStateMachine,exports.tokenToXml=T.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=r.tokenize,exports.tokenizeXmlStream=r.tokenizeXmlStream,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=O.XmlError,exports.XmlStream=l.XmlStream,exports.tokensToXml=a.tokensToXml,exports.processTokenForObject=t.processTokenForObject,exports.xmlToObject=t.xmlToObject,exports.processTokenForSimplifiedObject=A.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=A.xmlToSimplifiedObject;
1
+ 'use strict';
2
+
3
+ var select = require('./selector/select.js');
4
+ var TokenSelector = require('./selector/TokenSelector.js');
5
+ var TokenSelectState = require('./selector/TokenSelectState.js');
6
+ var TokenSelectStateMachine = require('./selector/TokenSelectStateMachine.js');
7
+ var tokenToXml = require('./token-to-xml.js');
8
+ var asciiConstants = require('./tokenizer/ascii-constants.js');
9
+ var tokenize = require('./tokenizer/tokenize.js');
10
+ var utils = require('./tokenizer/utils.js');
11
+ var XmlError = require('./tokenizer/XmlError.js');
12
+ var XmlStream = require('./tokenizer/XmlStream.js');
13
+ var tokensToXml = require('./tokens-to-xml.js');
14
+ var xmlToObject = require('./xml-to-object.js');
15
+ var xmlToSimplifiedObject = require('./xml-to-simplified-object.js');
16
+
17
+
18
+
19
+ exports.select = select.select;
20
+ exports.TokenSelector = TokenSelector.TokenSelector;
21
+ exports.EToCacheNodeProps = TokenSelectState.EToCacheNodeProps;
22
+ exports.ETokenMatchCriteria = TokenSelectState.ETokenMatchCriteria;
23
+ exports.TokenSelectState = TokenSelectState.TokenSelectState;
24
+ exports.TokenSelectStateMachine = TokenSelectStateMachine.TokenSelectStateMachine;
25
+ exports.tokenToXml = tokenToXml.tokenToXml;
26
+ exports.AMPERSAND = asciiConstants.AMPERSAND;
27
+ exports.CARRIAGE_RETURN = asciiConstants.CARRIAGE_RETURN;
28
+ exports.CLOSE_SQUARE_BRACKET = asciiConstants.CLOSE_SQUARE_BRACKET;
29
+ exports.COLON = asciiConstants.COLON;
30
+ exports.DOUBLE_QUOTE = asciiConstants.DOUBLE_QUOTE;
31
+ exports.EQUALS = asciiConstants.EQUALS;
32
+ exports.EXCLAMATION_MARK = asciiConstants.EXCLAMATION_MARK;
33
+ exports.GREATER_THAN = asciiConstants.GREATER_THAN;
34
+ exports.HASH = asciiConstants.HASH;
35
+ exports.HORIZONTAL_TAB = asciiConstants.HORIZONTAL_TAB;
36
+ exports.HYPHEN = asciiConstants.HYPHEN;
37
+ exports.LESS_THAN = asciiConstants.LESS_THAN;
38
+ exports.LINE_FEED = asciiConstants.LINE_FEED;
39
+ exports.LOWERCASE_A = asciiConstants.LOWERCASE_A;
40
+ exports.LOWERCASE_F = asciiConstants.LOWERCASE_F;
41
+ exports.LOWERCASE_X = asciiConstants.LOWERCASE_X;
42
+ exports.LOWERCASE_Z = asciiConstants.LOWERCASE_Z;
43
+ exports.NINE = asciiConstants.NINE;
44
+ exports.OPEN_SQUARE_BRACKET = asciiConstants.OPEN_SQUARE_BRACKET;
45
+ exports.PERCENT = asciiConstants.PERCENT;
46
+ exports.PERIOD = asciiConstants.PERIOD;
47
+ exports.QUESTION_MARK = asciiConstants.QUESTION_MARK;
48
+ exports.SEMICOLON = asciiConstants.SEMICOLON;
49
+ exports.SINGLE_QUOTE = asciiConstants.SINGLE_QUOTE;
50
+ exports.SLASH = asciiConstants.SLASH;
51
+ exports.SPACE = asciiConstants.SPACE;
52
+ exports.UNDERSCORE = asciiConstants.UNDERSCORE;
53
+ exports.UPPERCASE_A = asciiConstants.UPPERCASE_A;
54
+ exports.UPPERCASE_F = asciiConstants.UPPERCASE_F;
55
+ exports.UPPERCASE_P = asciiConstants.UPPERCASE_P;
56
+ exports.UPPERCASE_S = asciiConstants.UPPERCASE_S;
57
+ exports.UPPERCASE_Z = asciiConstants.UPPERCASE_Z;
58
+ exports.ZERO = asciiConstants.ZERO;
59
+ exports.tokenize = tokenize.tokenize;
60
+ exports.tokenizeXmlStream = tokenize.tokenizeXmlStream;
61
+ exports.isAsciiDigit = utils.isAsciiDigit;
62
+ exports.isXmlChar = utils.isXmlChar;
63
+ exports.isXmlName = utils.isXmlName;
64
+ exports.isXmlNameByte = utils.isXmlNameByte;
65
+ exports.isXmlNameStart = utils.isXmlNameStart;
66
+ exports.isXmlSpaceByte = utils.isXmlSpaceByte;
67
+ exports.XmlError = XmlError.XmlError;
68
+ exports.XmlStream = XmlStream.XmlStream;
69
+ exports.tokensToXml = tokensToXml.tokensToXml;
70
+ exports.processTokenForObject = xmlToObject.processTokenForObject;
71
+ exports.xmlToObject = xmlToObject.xmlToObject;
72
+ exports.processTokenForSimplifiedObject = xmlToSimplifiedObject.processTokenForSimplifiedObject;
73
+ exports.xmlToSimplifiedObject = xmlToSimplifiedObject.xmlToSimplifiedObject;
@@ -1 +1,106 @@
1
- "use strict";var s=require("./match-string.js"),m=Object.defineProperty,g=(t,e,r)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e,r)=>g(t,typeof e!="symbol"?e+"":e,r);class p{constructor(e){a(this,"_segment"),a(this,"_matchCriteria",0),a(this,"_toCacheNodeProps",0),a(this,"_enteredDepth",null),this._segment=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._segment.local!=null||this._segment.prefix!=null)&&(e|=1),this._segment.attributes!=null&&(e|=2,r|=2),this._segment.text!=null&&(e|=4),this._matchCriteria=e,this._toCacheNodeProps=r}matchesName(e,r){return(this._segment.local==null||s.matchString(e,this._segment.local))&&(this._segment.prefix==null||s.matchString(r,this._segment.prefix))}matchesAttributes(e){if(this._segment.attributes==null)return!0;for(const r of this._segment.attributes){let n=!1;for(const i of e){const o=r.local==null||s.matchString(i.local,r.local),c=r.value==null||i.value!=null&&s.matchString(i.value,r.value),u=r.prefix==null||i.prefix!=null&&s.matchString(i.prefix,r.prefix);if(o&&c&&u){n=!0;break}}if(!n)return!1}return!0}matchesText(e){return this._segment.text==null||s.matchString(e,this._segment.text)}matchesDepth(e,r){switch(this._segment.axis){case"child":return e===r+1;case"self-or-descendant":return e>=r}}match(e){this._enteredDepth=e}unmatch(){this._enteredDepth=null}}var h=(t=>(t[t.None=0]="None",t[t.Name=1]="Name",t[t.Attributes=2]="Attributes",t[t.Text=4]="Text",t))(h||{}),l=(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))(l||{});exports.EToCacheNodeProps=h,exports.ETokenMatchCriteria=l,exports.TokenSelectState=p;
1
+ 'use strict';
2
+
3
+ var matchString = require('./match-string.js');
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ class TokenSelectState {
9
+ constructor(segment) {
10
+ __publicField(this, "_segment");
11
+ __publicField(this, "_matchCriteria", 0 /* None */);
12
+ __publicField(this, "_toCacheNodeProps", 0 /* None */);
13
+ __publicField(this, "_enteredDepth", null);
14
+ this._segment = segment;
15
+ this.applyLevels();
16
+ }
17
+ get matchCriteria() {
18
+ return this._matchCriteria;
19
+ }
20
+ get toCacheNodeProps() {
21
+ return this._toCacheNodeProps;
22
+ }
23
+ get enteredDepth() {
24
+ return this._enteredDepth;
25
+ }
26
+ applyLevels() {
27
+ let matchCriteria = 0 /* None */;
28
+ let cacheProps = 0 /* None */;
29
+ if (this._segment.local != null || this._segment.prefix != null) {
30
+ matchCriteria |= 1 /* Name */;
31
+ }
32
+ if (this._segment.attributes != null) {
33
+ matchCriteria |= 2 /* Attributes */;
34
+ cacheProps |= 2 /* Attributes */;
35
+ }
36
+ if (this._segment.text != null) {
37
+ matchCriteria |= 4 /* Text */;
38
+ }
39
+ this._matchCriteria = matchCriteria;
40
+ this._toCacheNodeProps = cacheProps;
41
+ }
42
+ matchesName(local, prefix) {
43
+ return (
44
+ // Match local
45
+ (this._segment.local == null || matchString.matchString(local, this._segment.local)) && // Match prefix
46
+ (this._segment.prefix == null || matchString.matchString(prefix, this._segment.prefix))
47
+ );
48
+ }
49
+ matchesAttributes(attributes) {
50
+ if (this._segment.attributes == null) {
51
+ return true;
52
+ }
53
+ for (const attributeConfig of this._segment.attributes) {
54
+ let matchFound = false;
55
+ for (const attribute of attributes) {
56
+ const localMatch = attributeConfig.local == null || matchString.matchString(attribute.local, attributeConfig.local);
57
+ const valueMatch = attributeConfig.value == null || attribute.value != null && matchString.matchString(attribute.value, attributeConfig.value);
58
+ const prefixMatch = attributeConfig.prefix == null || attribute.prefix != null && matchString.matchString(attribute.prefix, attributeConfig.prefix);
59
+ if (localMatch && valueMatch && prefixMatch) {
60
+ matchFound = true;
61
+ break;
62
+ }
63
+ }
64
+ if (!matchFound) {
65
+ return false;
66
+ }
67
+ }
68
+ return true;
69
+ }
70
+ matchesText(text) {
71
+ return this._segment.text == null || matchString.matchString(text, this._segment.text);
72
+ }
73
+ matchesDepth(depth, parentDepth) {
74
+ switch (this._segment.axis) {
75
+ case "child":
76
+ return depth === parentDepth + 1;
77
+ case "self-or-descendant":
78
+ return depth >= parentDepth;
79
+ }
80
+ }
81
+ match(depth) {
82
+ this._enteredDepth = depth;
83
+ }
84
+ unmatch() {
85
+ this._enteredDepth = null;
86
+ }
87
+ }
88
+ var EToCacheNodeProps = /* @__PURE__ */ ((EToCacheNodeProps2) => {
89
+ EToCacheNodeProps2[EToCacheNodeProps2["None"] = 0] = "None";
90
+ EToCacheNodeProps2[EToCacheNodeProps2["Name"] = 1] = "Name";
91
+ EToCacheNodeProps2[EToCacheNodeProps2["Attributes"] = 2] = "Attributes";
92
+ EToCacheNodeProps2[EToCacheNodeProps2["Text"] = 4] = "Text";
93
+ return EToCacheNodeProps2;
94
+ })(EToCacheNodeProps || {});
95
+ var ETokenMatchCriteria = /* @__PURE__ */ ((ETokenMatchCriteria2) => {
96
+ ETokenMatchCriteria2[ETokenMatchCriteria2["None"] = 0] = "None";
97
+ ETokenMatchCriteria2[ETokenMatchCriteria2["Name"] = 1] = "Name";
98
+ ETokenMatchCriteria2[ETokenMatchCriteria2["Attributes"] = 2] = "Attributes";
99
+ ETokenMatchCriteria2[ETokenMatchCriteria2["Text"] = 4] = "Text";
100
+ ETokenMatchCriteria2[ETokenMatchCriteria2["Node"] = 8] = "Node";
101
+ return ETokenMatchCriteria2;
102
+ })(ETokenMatchCriteria || {});
103
+
104
+ exports.EToCacheNodeProps = EToCacheNodeProps;
105
+ exports.ETokenMatchCriteria = ETokenMatchCriteria;
106
+ exports.TokenSelectState = TokenSelectState;
@@ -1 +1,150 @@
1
- "use strict";var n=require("./TokenSelectState.js"),d=Object.defineProperty,_=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,c=(i,t,e)=>_(i,typeof t!="symbol"?t+"":t,e);class S{constructor(t){c(this,"_states"),c(this,"_currentState",null),c(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),c(this,"_cachedTokens",[]),c(this,"_toRecordTokens",[]),this._states=t.map(e=>new n.TokenSelectState(e))}getNextState(){var t;const e=this._currentState!=null?this._currentState+1:0;return e<this._states.length&&(t=this._states[e])!=null?t:null}getCurrentState(){var t;return this._currentState!=null&&this._currentState<this._states.length&&(t=this._states[this._currentState])!=null?t:null}record(t){this.getOffsetToFinal()<=1&&this._cachedTokens.push(t)}takeRecordedTokens(){if(this._toRecordTokens.length>0){const t=this._toRecordTokens;return this._toRecordTokens=[],t}return null}transitionIfNameMatch(t,e,r){var s;const a=this.getNextState(),h=this.getCurrentState();return a==null?!1:(a.toCacheNodeProps&n.EToCacheNodeProps.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),a.matchesName(t,e)&&a.matchesDepth(r,(s=h==null?void 0:h.enteredDepth)!=null?s:0)&&!(a.matchCriteria&(n.ETokenMatchCriteria.Attributes|n.ETokenMatchCriteria.Text|n.ETokenMatchCriteria.Node))?(this.transitionForward(r),!0):!1)}transitionIfAttributesMatch(t,e,r,s){var a,h;const o=this.getNextState(),u=this.getCurrentState();if(o==null)return!1;const l=(a=this._cachedNodeProps.attributes)!=null?a:[];return l.push({local:t,prefix:e,value:r}),o.toCacheNodeProps&n.EToCacheNodeProps.Attributes&&(this._cachedNodeProps.attributes=l),o.matchesAttributes(l)&&o.matchesDepth(s,(h=u==null?void 0:u.enteredDepth)!=null?h:0)&&!(o.matchCriteria&(n.ETokenMatchCriteria.Text|n.ETokenMatchCriteria.Node))?(this.transitionForward(s),!0):!1}transitionIfTextMatch(t,e){var r;const s=this.getNextState(),a=this.getCurrentState();return s==null?!1:(s.toCacheNodeProps&n.EToCacheNodeProps.Text&&(this._cachedNodeProps.text=t),s.matchesText(t)&&s.matchesDepth(e,(r=a==null?void 0:a.enteredDepth)!=null?r:0)&&!(s.matchCriteria&n.ETokenMatchCriteria.Node)?(this.transitionForward(e),!0):!1)}transitionForward(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState+1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.isFinalState()&&(this._toRecordTokens=this._cachedTokens),this.resetCurrentStateCache()}transitionBack(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState-1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.resetCurrentStateCache()}isFinalState(){return this._currentState!=null&&this._currentState>=this._states.length-1}getOffsetToFinal(){return this._currentState==null?this._states.length:this._states.length-1-this._currentState}resetCurrentStateCache(){this._cachedNodeProps.prefix=null,this._cachedNodeProps.local=null,this._cachedNodeProps.attributes=null,this._cachedNodeProps.text=null,this._cachedTokens=[]}}exports.TokenSelectStateMachine=S;
1
+ 'use strict';
2
+
3
+ var TokenSelectState = require('./TokenSelectState.js');
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ class TokenSelectStateMachine {
9
+ constructor(tokenSelectPath) {
10
+ __publicField(this, "_states");
11
+ // null (start state) -> index (x state)
12
+ __publicField(this, "_currentState", null);
13
+ // Current state cache
14
+ __publicField(this, "_cachedNodeProps", {
15
+ prefix: null,
16
+ local: null,
17
+ attributes: null,
18
+ text: null
19
+ });
20
+ __publicField(this, "_cachedTokens", []);
21
+ __publicField(this, "_toRecordTokens", []);
22
+ this._states = tokenSelectPath.map((part) => new TokenSelectState.TokenSelectState(part));
23
+ }
24
+ getNextState() {
25
+ var _a;
26
+ const nextIndex = this._currentState != null ? this._currentState + 1 : 0;
27
+ if (nextIndex < this._states.length) {
28
+ return (_a = this._states[nextIndex]) != null ? _a : null;
29
+ }
30
+ return null;
31
+ }
32
+ getCurrentState() {
33
+ var _a;
34
+ if (this._currentState != null && this._currentState < this._states.length) {
35
+ return (_a = this._states[this._currentState]) != null ? _a : null;
36
+ }
37
+ return null;
38
+ }
39
+ record(token) {
40
+ if (this.getOffsetToFinal() <= 1) {
41
+ this._cachedTokens.push(token);
42
+ }
43
+ }
44
+ takeRecordedTokens() {
45
+ if (this._toRecordTokens.length > 0) {
46
+ const recordedTokens = this._toRecordTokens;
47
+ this._toRecordTokens = [];
48
+ return recordedTokens;
49
+ }
50
+ return null;
51
+ }
52
+ transitionIfNameMatch(local, prefix, depth) {
53
+ var _a;
54
+ const nextState = this.getNextState();
55
+ const currentState = this.getCurrentState();
56
+ if (nextState == null) {
57
+ return false;
58
+ }
59
+ if (nextState.toCacheNodeProps & TokenSelectState.EToCacheNodeProps.Name) {
60
+ this._cachedNodeProps.local = local;
61
+ this._cachedNodeProps.prefix = prefix;
62
+ }
63
+ if (nextState.matchesName(local, prefix) && nextState.matchesDepth(depth, (_a = currentState == null ? void 0 : currentState.enteredDepth) != null ? _a : 0) && !(nextState.matchCriteria & (TokenSelectState.ETokenMatchCriteria.Attributes | TokenSelectState.ETokenMatchCriteria.Text | TokenSelectState.ETokenMatchCriteria.Node))) {
64
+ this.transitionForward(depth);
65
+ return true;
66
+ }
67
+ return false;
68
+ }
69
+ // Transition forward if attributes and depth match, and no additional criteria are required
70
+ transitionIfAttributesMatch(local, prefix, value, depth) {
71
+ var _a, _b;
72
+ const nextState = this.getNextState();
73
+ const currentState = this.getCurrentState();
74
+ if (nextState == null) {
75
+ return false;
76
+ }
77
+ const attributes = (_a = this._cachedNodeProps.attributes) != null ? _a : [];
78
+ attributes.push({ local, prefix, value });
79
+ if (nextState.toCacheNodeProps & TokenSelectState.EToCacheNodeProps.Attributes) {
80
+ this._cachedNodeProps.attributes = attributes;
81
+ }
82
+ if (nextState.matchesAttributes(attributes) && nextState.matchesDepth(depth, (_b = currentState == null ? void 0 : currentState.enteredDepth) != null ? _b : 0) && !(nextState.matchCriteria & (TokenSelectState.ETokenMatchCriteria.Text | TokenSelectState.ETokenMatchCriteria.Node))) {
83
+ this.transitionForward(depth);
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ // Transition forward if text content and depth match, and no additional criteria are required
89
+ transitionIfTextMatch(text, depth) {
90
+ var _a;
91
+ const nextState = this.getNextState();
92
+ const currentState = this.getCurrentState();
93
+ if (nextState == null) {
94
+ return false;
95
+ }
96
+ if (nextState.toCacheNodeProps & TokenSelectState.EToCacheNodeProps.Text) {
97
+ this._cachedNodeProps.text = text;
98
+ }
99
+ if (nextState.matchesText(text) && nextState.matchesDepth(depth, (_a = currentState == null ? void 0 : currentState.enteredDepth) != null ? _a : 0) && !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Node)) {
100
+ this.transitionForward(depth);
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ transitionForward(depth) {
106
+ const previousState = this.getCurrentState();
107
+ if (previousState != null) {
108
+ previousState.unmatch();
109
+ }
110
+ this._currentState = this._currentState != null ? this._currentState + 1 : 0;
111
+ const currentState = this.getCurrentState();
112
+ if (currentState != null) {
113
+ currentState.match(depth);
114
+ }
115
+ if (this.isFinalState()) {
116
+ this._toRecordTokens = this._cachedTokens;
117
+ }
118
+ this.resetCurrentStateCache();
119
+ }
120
+ transitionBack(depth) {
121
+ const previousState = this.getCurrentState();
122
+ if (previousState != null) {
123
+ previousState.unmatch();
124
+ }
125
+ this._currentState = this._currentState != null ? this._currentState - 1 : 0;
126
+ const currentState = this.getCurrentState();
127
+ if (currentState != null) {
128
+ currentState.match(depth);
129
+ }
130
+ this.resetCurrentStateCache();
131
+ }
132
+ isFinalState() {
133
+ return this._currentState != null && this._currentState >= this._states.length - 1;
134
+ }
135
+ getOffsetToFinal() {
136
+ if (this._currentState == null) {
137
+ return this._states.length;
138
+ }
139
+ return this._states.length - 1 - this._currentState;
140
+ }
141
+ resetCurrentStateCache() {
142
+ this._cachedNodeProps.prefix = null;
143
+ this._cachedNodeProps.local = null;
144
+ this._cachedNodeProps.attributes = null;
145
+ this._cachedNodeProps.text = null;
146
+ this._cachedTokens = [];
147
+ }
148
+ }
149
+
150
+ exports.TokenSelectStateMachine = TokenSelectStateMachine;
@@ -1 +1,139 @@
1
- "use strict";var a=require("./TokenSelectState.js"),l=require("./TokenSelectStateMachine.js"),u=Object.defineProperty,S=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,s=(r,t,e)=>S(r,typeof t!="symbol"?t+"":t,e);class p{constructor(t){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=t.map(e=>new l.TokenSelectStateMachine(e))}pipeToken(t,e){let n=!1,i=!1;switch(t.type){case"ElementStart":n=this.handleElementStart(t);break;case"Attribute":n=this.handleAttribute(t);break;case"Text":n=this.handleText(t);break;case"ElementEnd":{i=this.handleElementEnd(t);break}}n&&!this._isRecording&&(this._isRecording=!0,e({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(t);const h=c.takeRecordedTokens();h!=null&&h.forEach(o=>{e(o)})}this._isRecording&&e(t),i&&(e({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(t){this._currentDepth+=1;let e=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Name)||n.transitionIfNameMatch(t.local,t.prefix,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleAttribute(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Attributes)||n.transitionIfAttributesMatch(t.local,t.prefix,t.value,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleText(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Text)||n.transitionIfTextMatch(t.text,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleElementEnd(t){if(t.end.type==="Close"||t.end.type==="Empty"){this._currentDepth-=1;let e=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),e=e||n.isFinalState())}return!e}return!1}}exports.TokenSelector=p;
1
+ 'use strict';
2
+
3
+ var TokenSelectState = require('./TokenSelectState.js');
4
+ var TokenSelectStateMachine = require('./TokenSelectStateMachine.js');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ class TokenSelector {
10
+ constructor(tokenSelectPaths) {
11
+ __publicField(this, "_currentDepth", 0);
12
+ __publicField(this, "_tspStateMachines");
13
+ __publicField(this, "_isRecording", false);
14
+ this._tspStateMachines = tokenSelectPaths.map(
15
+ (tokenSelectPath) => new TokenSelectStateMachine.TokenSelectStateMachine(tokenSelectPath)
16
+ );
17
+ }
18
+ pipeToken(token, recorder) {
19
+ let startRecording = false;
20
+ let stopRecording = false;
21
+ switch (token.type) {
22
+ case "ElementStart":
23
+ startRecording = this.handleElementStart(token);
24
+ break;
25
+ case "Attribute":
26
+ startRecording = this.handleAttribute(token);
27
+ break;
28
+ case "Text":
29
+ startRecording = this.handleText(token);
30
+ break;
31
+ case "ElementEnd": {
32
+ stopRecording = this.handleElementEnd(token);
33
+ break;
34
+ }
35
+ }
36
+ if (startRecording && !this._isRecording) {
37
+ this._isRecording = true;
38
+ recorder({ type: "SelectionStart" });
39
+ }
40
+ for (const stateMachine of this._tspStateMachines) {
41
+ stateMachine.record(token);
42
+ const recordedTokens = stateMachine.takeRecordedTokens();
43
+ if (recordedTokens != null) {
44
+ recordedTokens.forEach((t) => {
45
+ recorder(t);
46
+ });
47
+ }
48
+ }
49
+ if (this._isRecording) {
50
+ recorder(token);
51
+ }
52
+ if (stopRecording) {
53
+ recorder({ type: "SelectionEnd" });
54
+ this._isRecording = false;
55
+ }
56
+ }
57
+ handleElementStart(token) {
58
+ this._currentDepth += 1;
59
+ let startRecording = false;
60
+ for (const stateMachine of this._tspStateMachines) {
61
+ stateMachine.resetCurrentStateCache();
62
+ if (stateMachine.isFinalState()) {
63
+ continue;
64
+ }
65
+ const nextState = stateMachine.getNextState();
66
+ if (nextState == null || !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Name)) {
67
+ continue;
68
+ }
69
+ const transitioned = stateMachine.transitionIfNameMatch(
70
+ token.local,
71
+ token.prefix,
72
+ this._currentDepth
73
+ );
74
+ if (transitioned && stateMachine.isFinalState()) {
75
+ startRecording = true;
76
+ }
77
+ }
78
+ return startRecording;
79
+ }
80
+ handleAttribute(token) {
81
+ let startRecording = false;
82
+ for (const stateMachine of this._tspStateMachines) {
83
+ if (stateMachine.isFinalState()) {
84
+ continue;
85
+ }
86
+ const nextState = stateMachine.getNextState();
87
+ if (nextState == null || !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Attributes)) {
88
+ continue;
89
+ }
90
+ const transitioned = stateMachine.transitionIfAttributesMatch(
91
+ token.local,
92
+ token.prefix,
93
+ token.value,
94
+ this._currentDepth
95
+ );
96
+ if (transitioned && stateMachine.isFinalState()) {
97
+ startRecording = true;
98
+ }
99
+ }
100
+ return startRecording;
101
+ }
102
+ handleText(token) {
103
+ let startRecording = false;
104
+ for (const stateMachine of this._tspStateMachines) {
105
+ if (stateMachine.isFinalState()) {
106
+ continue;
107
+ }
108
+ const nextState = stateMachine.getNextState();
109
+ if (nextState == null || !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Text)) {
110
+ continue;
111
+ }
112
+ const transitioned = stateMachine.transitionIfTextMatch(token.text, this._currentDepth);
113
+ if (transitioned && stateMachine.isFinalState()) {
114
+ startRecording = true;
115
+ }
116
+ }
117
+ return startRecording;
118
+ }
119
+ handleElementEnd(token) {
120
+ if (token.end.type === "Close" || token.end.type === "Empty") {
121
+ this._currentDepth -= 1;
122
+ let isFinalState = false;
123
+ for (const stateMachine of this._tspStateMachines) {
124
+ const currentState = stateMachine.getCurrentState();
125
+ if (currentState == null) {
126
+ continue;
127
+ }
128
+ if (currentState.enteredDepth != null && this._currentDepth < currentState.enteredDepth) {
129
+ stateMachine.transitionBack(this._currentDepth);
130
+ }
131
+ isFinalState = isFinalState || stateMachine.isFinalState();
132
+ }
133
+ return !isFinalState;
134
+ }
135
+ return false;
136
+ }
137
+ }
138
+
139
+ exports.TokenSelector = TokenSelector;
@@ -1 +1,21 @@
1
- "use strict";function a(t,e){if(typeof e=="string")return t===e;switch(e.matchStrategy){case"ANY":return!0;case"EXACT":return t===e.value;case"CONTAINS":return t.includes(e.value);case"STARTS_WITH":return t.startsWith(e.value);case"ENDS_WITH":return t.endsWith(e.value)}}exports.matchString=a;
1
+ 'use strict';
2
+
3
+ function matchString(value, config) {
4
+ if (typeof config === "string") {
5
+ return value === config;
6
+ }
7
+ switch (config.matchStrategy) {
8
+ case "ANY":
9
+ return true;
10
+ case "EXACT":
11
+ return value === config.value;
12
+ case "CONTAINS":
13
+ return value.includes(config.value);
14
+ case "STARTS_WITH":
15
+ return value.startsWith(config.value);
16
+ case "ENDS_WITH":
17
+ return value.endsWith(config.value);
18
+ }
19
+ }
20
+
21
+ exports.matchString = matchString;
@@ -1 +1,15 @@
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,r=>{o.pipeToken(r,c=>{t(c)})})}exports.select=s;
1
+ 'use strict';
2
+
3
+ var tokenize = require('../tokenizer/tokenize.js');
4
+ var TokenSelector = require('./TokenSelector.js');
5
+
6
+ function select(xml, tokenSelectPaths, callback) {
7
+ const selector = new TokenSelector.TokenSelector(tokenSelectPaths);
8
+ tokenize.tokenize(xml, (token) => {
9
+ selector.pipeToken(token, (recordedToken) => {
10
+ callback(recordedToken);
11
+ });
12
+ });
13
+ }
14
+
15
+ exports.select = select;
@@ -1 +1,44 @@
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}exports.tokenToXml=n;
1
+ 'use strict';
2
+
3
+ function tokenToXml(token) {
4
+ let xmlString = "";
5
+ switch (token.type) {
6
+ case "ProcessingInstruction":
7
+ xmlString += `<?${token.target}`;
8
+ if (token.content) {
9
+ xmlString += ` ${token.content}`;
10
+ }
11
+ xmlString += "?>";
12
+ break;
13
+ case "Comment":
14
+ xmlString += `<!--${token.text}-->`;
15
+ break;
16
+ case "EntityDeclaration":
17
+ xmlString += `<!ENTITY ${token.name} "${token.definition}">`;
18
+ break;
19
+ case "ElementStart":
20
+ xmlString += `<${token.prefix.length > 0 ? `${token.prefix}:` : ""}${token.local}`;
21
+ break;
22
+ case "Attribute":
23
+ xmlString += ` ${token.prefix.length > 0 ? `${token.prefix}:` : ""}${token.local}="${token.value}"`;
24
+ break;
25
+ case "ElementEnd":
26
+ if (token.end.type === "Open") {
27
+ xmlString += ">";
28
+ } else if (token.end.type === "Close") {
29
+ xmlString += `</${token.end.prefix.length > 0 ? `${token.end.prefix}:` : ""}${token.end.local}>`;
30
+ } else {
31
+ xmlString += "/>";
32
+ }
33
+ break;
34
+ case "Text":
35
+ xmlString += token.text;
36
+ break;
37
+ case "Cdata":
38
+ xmlString += `<![CDATA[${token.text}]]>`;
39
+ break;
40
+ }
41
+ return xmlString;
42
+ }
43
+
44
+ exports.tokenToXml = tokenToXml;