xml-tokenizer 0.0.26 → 0.0.27

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 (73) hide show
  1. package/dist/cjs/get-q-name.js +1 -7
  2. package/dist/cjs/index.js +1 -75
  3. package/dist/cjs/selector/TokenSelectState.js +1 -106
  4. package/dist/cjs/selector/TokenSelectStateMachine.js +1 -150
  5. package/dist/cjs/selector/TokenSelector.js +1 -139
  6. package/dist/cjs/selector/match-string.js +1 -21
  7. package/dist/cjs/selector/select.js +1 -19
  8. package/dist/cjs/token-to-xml.js +1 -44
  9. package/dist/cjs/tokenizer/XmlError.js +1 -96
  10. package/dist/cjs/tokenizer/XmlStream.js +1 -447
  11. package/dist/cjs/tokenizer/ascii-constants.js +1 -69
  12. package/dist/cjs/tokenizer/tokenize.js +1 -408
  13. package/dist/cjs/tokenizer/utils.js +1 -47
  14. package/dist/cjs/tokens-to-xml.js +1 -13
  15. package/dist/cjs/xml-to-object.js +1 -69
  16. package/dist/cjs/xml-to-simplified-object.js +1 -86
  17. package/dist/esm/get-q-name.js +1 -5
  18. package/dist/esm/index.js +1 -14
  19. package/dist/esm/selector/TokenSelectState.js +1 -102
  20. package/dist/esm/selector/TokenSelectStateMachine.js +1 -148
  21. package/dist/esm/selector/TokenSelector.js +1 -137
  22. package/dist/esm/selector/match-string.js +1 -19
  23. package/dist/esm/selector/select.js +1 -17
  24. package/dist/esm/token-to-xml.js +1 -42
  25. package/dist/esm/tokenizer/XmlError.js +1 -94
  26. package/dist/esm/tokenizer/XmlStream.js +1 -445
  27. package/dist/esm/tokenizer/ascii-constants.js +1 -35
  28. package/dist/esm/tokenizer/tokenize.js +1 -405
  29. package/dist/esm/tokenizer/utils.js +1 -40
  30. package/dist/esm/tokens-to-xml.js +1 -11
  31. package/dist/esm/xml-to-object.js +1 -66
  32. package/dist/esm/xml-to-simplified-object.js +1 -83
  33. package/dist/types/get-q-name.d.ts +0 -1
  34. package/dist/types/index.d.ts +0 -1
  35. package/dist/types/selector/TokenSelectState.d.ts +0 -1
  36. package/dist/types/selector/TokenSelectStateMachine.d.ts +0 -1
  37. package/dist/types/selector/TokenSelector.d.ts +0 -1
  38. package/dist/types/selector/index.d.ts +0 -1
  39. package/dist/types/selector/match-string.d.ts +0 -1
  40. package/dist/types/selector/select.d.ts +0 -1
  41. package/dist/types/selector/types.d.ts +0 -1
  42. package/dist/types/token-to-xml.d.ts +0 -1
  43. package/dist/types/tokenizer/XmlError.d.ts +0 -1
  44. package/dist/types/tokenizer/XmlStream.d.ts +20 -1
  45. package/dist/types/tokenizer/ascii-constants.d.ts +0 -1
  46. package/dist/types/tokenizer/index.d.ts +0 -1
  47. package/dist/types/tokenizer/tokenize.d.ts +0 -1
  48. package/dist/types/tokenizer/types.d.ts +3 -2
  49. package/dist/types/tokenizer/utils.d.ts +0 -1
  50. package/dist/types/tokens-to-xml.d.ts +0 -1
  51. package/dist/types/xml-to-object.d.ts +0 -1
  52. package/dist/types/xml-to-simplified-object.d.ts +0 -1
  53. package/package.json +1 -1
  54. package/dist/types/get-q-name.d.ts.map +0 -1
  55. package/dist/types/index.d.ts.map +0 -1
  56. package/dist/types/selector/TokenSelectState.d.ts.map +0 -1
  57. package/dist/types/selector/TokenSelectStateMachine.d.ts.map +0 -1
  58. package/dist/types/selector/TokenSelector.d.ts.map +0 -1
  59. package/dist/types/selector/index.d.ts.map +0 -1
  60. package/dist/types/selector/match-string.d.ts.map +0 -1
  61. package/dist/types/selector/select.d.ts.map +0 -1
  62. package/dist/types/selector/types.d.ts.map +0 -1
  63. package/dist/types/token-to-xml.d.ts.map +0 -1
  64. package/dist/types/tokenizer/XmlError.d.ts.map +0 -1
  65. package/dist/types/tokenizer/XmlStream.d.ts.map +0 -1
  66. package/dist/types/tokenizer/ascii-constants.d.ts.map +0 -1
  67. package/dist/types/tokenizer/index.d.ts.map +0 -1
  68. package/dist/types/tokenizer/tokenize.d.ts.map +0 -1
  69. package/dist/types/tokenizer/types.d.ts.map +0 -1
  70. package/dist/types/tokenizer/utils.d.ts.map +0 -1
  71. package/dist/types/tokens-to-xml.d.ts.map +0 -1
  72. package/dist/types/xml-to-object.d.ts.map +0 -1
  73. package/dist/types/xml-to-simplified-object.d.ts.map +0 -1
@@ -1,7 +1 @@
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;
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,75 +1 @@
1
- 'use strict';
2
-
3
- var getQName = require('./get-q-name.js');
4
- var select = require('./selector/select.js');
5
- var TokenSelector = require('./selector/TokenSelector.js');
6
- var TokenSelectState = require('./selector/TokenSelectState.js');
7
- var TokenSelectStateMachine = require('./selector/TokenSelectStateMachine.js');
8
- var tokenToXml = require('./token-to-xml.js');
9
- var asciiConstants = require('./tokenizer/ascii-constants.js');
10
- var tokenize = require('./tokenizer/tokenize.js');
11
- var utils = require('./tokenizer/utils.js');
12
- var XmlError = require('./tokenizer/XmlError.js');
13
- var XmlStream = require('./tokenizer/XmlStream.js');
14
- var tokensToXml = require('./tokens-to-xml.js');
15
- var xmlToObject = require('./xml-to-object.js');
16
- var xmlToSimplifiedObject = require('./xml-to-simplified-object.js');
17
-
18
-
19
-
20
- exports.getQName = getQName.getQName;
21
- exports.select = select.select;
22
- exports.TokenSelector = TokenSelector.TokenSelector;
23
- exports.EToCacheNodeProps = TokenSelectState.EToCacheNodeProps;
24
- exports.ETokenMatchCriteria = TokenSelectState.ETokenMatchCriteria;
25
- exports.TokenSelectState = TokenSelectState.TokenSelectState;
26
- exports.TokenSelectStateMachine = TokenSelectStateMachine.TokenSelectStateMachine;
27
- exports.tokenToXml = tokenToXml.tokenToXml;
28
- exports.AMPERSAND = asciiConstants.AMPERSAND;
29
- exports.CARRIAGE_RETURN = asciiConstants.CARRIAGE_RETURN;
30
- exports.CLOSE_SQUARE_BRACKET = asciiConstants.CLOSE_SQUARE_BRACKET;
31
- exports.COLON = asciiConstants.COLON;
32
- exports.DOUBLE_QUOTE = asciiConstants.DOUBLE_QUOTE;
33
- exports.EQUALS = asciiConstants.EQUALS;
34
- exports.EXCLAMATION_MARK = asciiConstants.EXCLAMATION_MARK;
35
- exports.GREATER_THAN = asciiConstants.GREATER_THAN;
36
- exports.HASH = asciiConstants.HASH;
37
- exports.HORIZONTAL_TAB = asciiConstants.HORIZONTAL_TAB;
38
- exports.HYPHEN = asciiConstants.HYPHEN;
39
- exports.LESS_THAN = asciiConstants.LESS_THAN;
40
- exports.LINE_FEED = asciiConstants.LINE_FEED;
41
- exports.LOWERCASE_A = asciiConstants.LOWERCASE_A;
42
- exports.LOWERCASE_F = asciiConstants.LOWERCASE_F;
43
- exports.LOWERCASE_X = asciiConstants.LOWERCASE_X;
44
- exports.LOWERCASE_Z = asciiConstants.LOWERCASE_Z;
45
- exports.NINE = asciiConstants.NINE;
46
- exports.OPEN_SQUARE_BRACKET = asciiConstants.OPEN_SQUARE_BRACKET;
47
- exports.PERCENT = asciiConstants.PERCENT;
48
- exports.PERIOD = asciiConstants.PERIOD;
49
- exports.QUESTION_MARK = asciiConstants.QUESTION_MARK;
50
- exports.SEMICOLON = asciiConstants.SEMICOLON;
51
- exports.SINGLE_QUOTE = asciiConstants.SINGLE_QUOTE;
52
- exports.SLASH = asciiConstants.SLASH;
53
- exports.SPACE = asciiConstants.SPACE;
54
- exports.UNDERSCORE = asciiConstants.UNDERSCORE;
55
- exports.UPPERCASE_A = asciiConstants.UPPERCASE_A;
56
- exports.UPPERCASE_F = asciiConstants.UPPERCASE_F;
57
- exports.UPPERCASE_P = asciiConstants.UPPERCASE_P;
58
- exports.UPPERCASE_S = asciiConstants.UPPERCASE_S;
59
- exports.UPPERCASE_Z = asciiConstants.UPPERCASE_Z;
60
- exports.ZERO = asciiConstants.ZERO;
61
- exports.tokenize = tokenize.tokenize;
62
- exports.tokenizeXmlStream = tokenize.tokenizeXmlStream;
63
- exports.isAsciiDigit = utils.isAsciiDigit;
64
- exports.isXmlChar = utils.isXmlChar;
65
- exports.isXmlName = utils.isXmlName;
66
- exports.isXmlNameByte = utils.isXmlNameByte;
67
- exports.isXmlNameStart = utils.isXmlNameStart;
68
- exports.isXmlSpaceByte = utils.isXmlSpaceByte;
69
- exports.XmlError = XmlError.XmlError;
70
- exports.XmlStream = XmlStream.XmlStream;
71
- exports.tokensToXml = tokensToXml.tokensToXml;
72
- exports.processTokenForObject = xmlToObject.processTokenForObject;
73
- exports.xmlToObject = xmlToObject.xmlToObject;
74
- exports.processTokenForSimplifiedObject = xmlToSimplifiedObject.processTokenForSimplifiedObject;
75
- exports.xmlToSimplifiedObject = xmlToSimplifiedObject.xmlToSimplifiedObject;
1
+ "use strict";var i=require("./get-q-name.js"),o=require("./selector/select.js"),R=require("./selector/TokenSelector.js"),S=require("./selector/TokenSelectState.js"),T=require("./selector/TokenSelectStateMachine.js"),a=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"),m=require("./tokenizer/XmlStream.js"),l=require("./tokens-to-xml.js"),t=require("./xml-to-object.js"),A=require("./xml-to-simplified-object.js");exports.getQName=i.getQName,exports.select=o.select,exports.TokenSelector=R.TokenSelector,exports.EToCacheNodeProps=S.EToCacheNodeProps,exports.ETokenMatchCriteria=S.ETokenMatchCriteria,exports.TokenSelectState=S.TokenSelectState,exports.TokenSelectStateMachine=T.TokenSelectStateMachine,exports.tokenToXml=a.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=m.XmlStream,exports.tokensToXml=l.tokensToXml,exports.processTokenForObject=t.processTokenForObject,exports.xmlToObject=t.xmlToObject,exports.processTokenForSimplifiedObject=A.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=A.xmlToSimplifiedObject;
@@ -1,106 +1 @@
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
+ "use strict";var s=require("./match-string.js"),m=Object.defineProperty,g=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t,r)=>g(e,typeof t!="symbol"?t+"":t,r);class p{constructor(t){a(this,"_segment"),a(this,"_matchCriteria",0),a(this,"_toCacheNodeProps",0),a(this,"_enteredDepth",null),this._segment=t,this.applyLevels()}get matchCriteria(){return this._matchCriteria}get toCacheNodeProps(){return this._toCacheNodeProps}get enteredDepth(){return this._enteredDepth}applyLevels(){let t=0,r=0;(this._segment.local!=null||this._segment.prefix!=null)&&(t|=1),this._segment.attributes!=null&&(t|=2,r|=2),this._segment.text!=null&&(t|=4),this._matchCriteria=t,this._toCacheNodeProps=r}matchesName(t,r){return(this._segment.local==null||s.matchString(t,this._segment.local))&&(this._segment.prefix==null||s.matchString(r,this._segment.prefix))}matchesAttributes(t){if(this._segment.attributes==null)return!0;for(const r of this._segment.attributes){let n=!1;for(const i of t){const u=r.local==null||s.matchString(i.local,r.local),o=r.value==null||i.value!=null&&s.matchString(i.value,r.value),c=r.prefix==null||i.prefix!=null&&s.matchString(i.prefix,r.prefix);if(u&&o&&c){n=!0;break}}if(!n)return!1}return!0}matchesText(t){return this._segment.text==null||s.matchString(t,this._segment.text)}matchesDepth(t,r){switch(this._segment.axis){case"child":return t===r+1;case"self-or-descendant":return t>=r}}match(t){this._enteredDepth=t}unmatch(){this._enteredDepth=null}}var h=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e))(h||{}),l=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e[e.Node=8]="Node",e))(l||{});exports.EToCacheNodeProps=h,exports.ETokenMatchCriteria=l,exports.TokenSelectState=p;
@@ -1,150 +1 @@
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
+ "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,139 +1 @@
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
+ "use strict";var a=require("./TokenSelectState.js"),o=require("./TokenSelectStateMachine.js"),u=Object.defineProperty,f=(r,e,t)=>e in r?u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>f(r,typeof e!="symbol"?e+"":e,t);class S{constructor(e){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=e.map(t=>new o.TokenSelectStateMachine(t))}pipeToken(e,t){let n=!1,i=!1;switch(e.type){case"ElementStart":n=this.handleElementStart(e);break;case"Attribute":n=this.handleAttribute(e);break;case"Text":n=this.handleText(e);break;case"ElementEnd":{i=this.handleElementEnd(e);break}}n&&!this._isRecording&&(this._isRecording=!0,t({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(e);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{t(h)})}this._isRecording&&t(e),i&&(t({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(e){this._currentDepth+=1;let t=!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(e.local,e.prefix,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleAttribute(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Attributes)||n.transitionIfAttributesMatch(e.local,e.prefix,e.value,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleText(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Text)||n.transitionIfTextMatch(e.text,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleElementEnd(e){if(e.end.type==="Close"||e.end.type==="Empty"){this._currentDepth-=1;let t=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),t=t||n.isFinalState())}return!t}return!1}}exports.TokenSelector=S;
@@ -1,21 +1 @@
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
+ "use strict";function r(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=r;
@@ -1,19 +1 @@
1
- 'use strict';
2
-
3
- var tokenize = require('../tokenizer/tokenize.js');
4
- var TokenSelector = require('./TokenSelector.js');
5
-
6
- function select(xml, tokenSelectPaths, callback, options) {
7
- const selector = new TokenSelector.TokenSelector(tokenSelectPaths);
8
- tokenize.tokenize(
9
- xml,
10
- (token) => {
11
- selector.pipeToken(token, (recordedToken) => {
12
- callback(recordedToken);
13
- });
14
- },
15
- options
16
- );
17
- }
18
-
19
- exports.select = select;
1
+ "use strict";var k=require("../tokenizer/tokenize.js"),l=require("./TokenSelector.js");function s(e,t,n,o){const r=new l.TokenSelector(t);k.tokenize(e,c=>{r.pipeToken(c,i=>{n(i)})},o)}exports.select=s;
@@ -1,44 +1 @@
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;
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;