xml-tokenizer 0.0.25 → 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.
- package/dist/cjs/get-q-name.js +1 -7
- package/dist/cjs/index.js +1 -75
- package/dist/cjs/selector/TokenSelectState.js +1 -106
- package/dist/cjs/selector/TokenSelectStateMachine.js +1 -150
- package/dist/cjs/selector/TokenSelector.js +1 -139
- package/dist/cjs/selector/match-string.js +1 -21
- package/dist/cjs/selector/select.js +1 -19
- package/dist/cjs/token-to-xml.js +1 -44
- package/dist/cjs/tokenizer/XmlError.js +1 -96
- package/dist/cjs/tokenizer/XmlStream.js +1 -447
- package/dist/cjs/tokenizer/ascii-constants.js +1 -69
- package/dist/cjs/tokenizer/tokenize.js +1 -408
- package/dist/cjs/tokenizer/utils.js +1 -47
- package/dist/cjs/tokens-to-xml.js +1 -13
- package/dist/cjs/xml-to-object.js +1 -69
- package/dist/cjs/xml-to-simplified-object.js +1 -86
- package/dist/esm/get-q-name.js +1 -5
- package/dist/esm/index.js +1 -14
- package/dist/esm/selector/TokenSelectState.js +1 -102
- package/dist/esm/selector/TokenSelectStateMachine.js +1 -148
- package/dist/esm/selector/TokenSelector.js +1 -137
- package/dist/esm/selector/match-string.js +1 -19
- package/dist/esm/selector/select.js +1 -17
- package/dist/esm/token-to-xml.js +1 -42
- package/dist/esm/tokenizer/XmlError.js +1 -94
- package/dist/esm/tokenizer/XmlStream.js +1 -445
- package/dist/esm/tokenizer/ascii-constants.js +1 -35
- package/dist/esm/tokenizer/tokenize.js +1 -405
- package/dist/esm/tokenizer/utils.js +1 -40
- package/dist/esm/tokens-to-xml.js +1 -11
- package/dist/esm/xml-to-object.js +1 -66
- package/dist/esm/xml-to-simplified-object.js +1 -83
- package/dist/types/get-q-name.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/selector/TokenSelectState.d.ts +0 -1
- package/dist/types/selector/TokenSelectStateMachine.d.ts +0 -1
- package/dist/types/selector/TokenSelector.d.ts +0 -1
- package/dist/types/selector/index.d.ts +0 -1
- package/dist/types/selector/match-string.d.ts +0 -1
- package/dist/types/selector/select.d.ts +0 -1
- package/dist/types/selector/types.d.ts +0 -1
- package/dist/types/token-to-xml.d.ts +0 -1
- package/dist/types/tokenizer/XmlError.d.ts +0 -1
- package/dist/types/tokenizer/XmlStream.d.ts +20 -1
- package/dist/types/tokenizer/ascii-constants.d.ts +0 -1
- package/dist/types/tokenizer/index.d.ts +0 -1
- package/dist/types/tokenizer/tokenize.d.ts +0 -1
- package/dist/types/tokenizer/types.d.ts +3 -2
- package/dist/types/tokenizer/utils.d.ts +0 -1
- package/dist/types/tokens-to-xml.d.ts +0 -1
- package/dist/types/xml-to-object.d.ts +0 -1
- package/dist/types/xml-to-simplified-object.d.ts +0 -1
- package/package.json +2 -2
- package/dist/types/get-q-name.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/selector/TokenSelectState.d.ts.map +0 -1
- package/dist/types/selector/TokenSelectStateMachine.d.ts.map +0 -1
- package/dist/types/selector/TokenSelector.d.ts.map +0 -1
- package/dist/types/selector/index.d.ts.map +0 -1
- package/dist/types/selector/match-string.d.ts.map +0 -1
- package/dist/types/selector/select.d.ts.map +0 -1
- package/dist/types/selector/types.d.ts.map +0 -1
- package/dist/types/token-to-xml.d.ts.map +0 -1
- package/dist/types/tokenizer/XmlError.d.ts.map +0 -1
- package/dist/types/tokenizer/XmlStream.d.ts.map +0 -1
- package/dist/types/tokenizer/ascii-constants.d.ts.map +0 -1
- package/dist/types/tokenizer/index.d.ts.map +0 -1
- package/dist/types/tokenizer/tokenize.d.ts.map +0 -1
- package/dist/types/tokenizer/types.d.ts.map +0 -1
- package/dist/types/tokenizer/utils.d.ts.map +0 -1
- package/dist/types/tokens-to-xml.d.ts.map +0 -1
- package/dist/types/xml-to-object.d.ts.map +0 -1
- package/dist/types/xml-to-simplified-object.d.ts.map +0 -1
|
@@ -1,102 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
class TokenSelectState {
|
|
7
|
-
constructor(segment) {
|
|
8
|
-
__publicField(this, "_segment");
|
|
9
|
-
__publicField(this, "_matchCriteria", 0 /* None */);
|
|
10
|
-
__publicField(this, "_toCacheNodeProps", 0 /* None */);
|
|
11
|
-
__publicField(this, "_enteredDepth", null);
|
|
12
|
-
this._segment = segment;
|
|
13
|
-
this.applyLevels();
|
|
14
|
-
}
|
|
15
|
-
get matchCriteria() {
|
|
16
|
-
return this._matchCriteria;
|
|
17
|
-
}
|
|
18
|
-
get toCacheNodeProps() {
|
|
19
|
-
return this._toCacheNodeProps;
|
|
20
|
-
}
|
|
21
|
-
get enteredDepth() {
|
|
22
|
-
return this._enteredDepth;
|
|
23
|
-
}
|
|
24
|
-
applyLevels() {
|
|
25
|
-
let matchCriteria = 0 /* None */;
|
|
26
|
-
let cacheProps = 0 /* None */;
|
|
27
|
-
if (this._segment.local != null || this._segment.prefix != null) {
|
|
28
|
-
matchCriteria |= 1 /* Name */;
|
|
29
|
-
}
|
|
30
|
-
if (this._segment.attributes != null) {
|
|
31
|
-
matchCriteria |= 2 /* Attributes */;
|
|
32
|
-
cacheProps |= 2 /* Attributes */;
|
|
33
|
-
}
|
|
34
|
-
if (this._segment.text != null) {
|
|
35
|
-
matchCriteria |= 4 /* Text */;
|
|
36
|
-
}
|
|
37
|
-
this._matchCriteria = matchCriteria;
|
|
38
|
-
this._toCacheNodeProps = cacheProps;
|
|
39
|
-
}
|
|
40
|
-
matchesName(local, prefix) {
|
|
41
|
-
return (
|
|
42
|
-
// Match local
|
|
43
|
-
(this._segment.local == null || matchString(local, this._segment.local)) && // Match prefix
|
|
44
|
-
(this._segment.prefix == null || matchString(prefix, this._segment.prefix))
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
matchesAttributes(attributes) {
|
|
48
|
-
if (this._segment.attributes == null) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
for (const attributeConfig of this._segment.attributes) {
|
|
52
|
-
let matchFound = false;
|
|
53
|
-
for (const attribute of attributes) {
|
|
54
|
-
const localMatch = attributeConfig.local == null || matchString(attribute.local, attributeConfig.local);
|
|
55
|
-
const valueMatch = attributeConfig.value == null || attribute.value != null && matchString(attribute.value, attributeConfig.value);
|
|
56
|
-
const prefixMatch = attributeConfig.prefix == null || attribute.prefix != null && matchString(attribute.prefix, attributeConfig.prefix);
|
|
57
|
-
if (localMatch && valueMatch && prefixMatch) {
|
|
58
|
-
matchFound = true;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (!matchFound) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
matchesText(text) {
|
|
69
|
-
return this._segment.text == null || matchString(text, this._segment.text);
|
|
70
|
-
}
|
|
71
|
-
matchesDepth(depth, parentDepth) {
|
|
72
|
-
switch (this._segment.axis) {
|
|
73
|
-
case "child":
|
|
74
|
-
return depth === parentDepth + 1;
|
|
75
|
-
case "self-or-descendant":
|
|
76
|
-
return depth >= parentDepth;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
match(depth) {
|
|
80
|
-
this._enteredDepth = depth;
|
|
81
|
-
}
|
|
82
|
-
unmatch() {
|
|
83
|
-
this._enteredDepth = null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
var EToCacheNodeProps = /* @__PURE__ */ ((EToCacheNodeProps2) => {
|
|
87
|
-
EToCacheNodeProps2[EToCacheNodeProps2["None"] = 0] = "None";
|
|
88
|
-
EToCacheNodeProps2[EToCacheNodeProps2["Name"] = 1] = "Name";
|
|
89
|
-
EToCacheNodeProps2[EToCacheNodeProps2["Attributes"] = 2] = "Attributes";
|
|
90
|
-
EToCacheNodeProps2[EToCacheNodeProps2["Text"] = 4] = "Text";
|
|
91
|
-
return EToCacheNodeProps2;
|
|
92
|
-
})(EToCacheNodeProps || {});
|
|
93
|
-
var ETokenMatchCriteria = /* @__PURE__ */ ((ETokenMatchCriteria2) => {
|
|
94
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["None"] = 0] = "None";
|
|
95
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Name"] = 1] = "Name";
|
|
96
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Attributes"] = 2] = "Attributes";
|
|
97
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Text"] = 4] = "Text";
|
|
98
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Node"] = 8] = "Node";
|
|
99
|
-
return ETokenMatchCriteria2;
|
|
100
|
-
})(ETokenMatchCriteria || {});
|
|
101
|
-
|
|
102
|
-
export { EToCacheNodeProps, ETokenMatchCriteria, TokenSelectState };
|
|
1
|
+
import{matchString as s}from"./match-string.js";var m=Object.defineProperty,p=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t,r)=>p(e,typeof t!="symbol"?t+"":t,r);class _{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(t,this._segment.local))&&(this._segment.prefix==null||s(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(i.local,r.local),o=r.value==null||i.value!=null&&s(i.value,r.value),c=r.prefix==null||i.prefix!=null&&s(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(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 l=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e))(l||{}),h=(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))(h||{});export{l as EToCacheNodeProps,h as ETokenMatchCriteria,_ as TokenSelectState};
|
|
@@ -1,148 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
class TokenSelectStateMachine {
|
|
7
|
-
constructor(tokenSelectPath) {
|
|
8
|
-
__publicField(this, "_states");
|
|
9
|
-
// null (start state) -> index (x state)
|
|
10
|
-
__publicField(this, "_currentState", null);
|
|
11
|
-
// Current state cache
|
|
12
|
-
__publicField(this, "_cachedNodeProps", {
|
|
13
|
-
prefix: null,
|
|
14
|
-
local: null,
|
|
15
|
-
attributes: null,
|
|
16
|
-
text: null
|
|
17
|
-
});
|
|
18
|
-
__publicField(this, "_cachedTokens", []);
|
|
19
|
-
__publicField(this, "_toRecordTokens", []);
|
|
20
|
-
this._states = tokenSelectPath.map((part) => new TokenSelectState(part));
|
|
21
|
-
}
|
|
22
|
-
getNextState() {
|
|
23
|
-
var _a;
|
|
24
|
-
const nextIndex = this._currentState != null ? this._currentState + 1 : 0;
|
|
25
|
-
if (nextIndex < this._states.length) {
|
|
26
|
-
return (_a = this._states[nextIndex]) != null ? _a : null;
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
getCurrentState() {
|
|
31
|
-
var _a;
|
|
32
|
-
if (this._currentState != null && this._currentState < this._states.length) {
|
|
33
|
-
return (_a = this._states[this._currentState]) != null ? _a : null;
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
record(token) {
|
|
38
|
-
if (this.getOffsetToFinal() <= 1) {
|
|
39
|
-
this._cachedTokens.push(token);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
takeRecordedTokens() {
|
|
43
|
-
if (this._toRecordTokens.length > 0) {
|
|
44
|
-
const recordedTokens = this._toRecordTokens;
|
|
45
|
-
this._toRecordTokens = [];
|
|
46
|
-
return recordedTokens;
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
transitionIfNameMatch(local, prefix, depth) {
|
|
51
|
-
var _a;
|
|
52
|
-
const nextState = this.getNextState();
|
|
53
|
-
const currentState = this.getCurrentState();
|
|
54
|
-
if (nextState == null) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
if (nextState.toCacheNodeProps & EToCacheNodeProps.Name) {
|
|
58
|
-
this._cachedNodeProps.local = local;
|
|
59
|
-
this._cachedNodeProps.prefix = prefix;
|
|
60
|
-
}
|
|
61
|
-
if (nextState.matchesName(local, prefix) && nextState.matchesDepth(depth, (_a = currentState == null ? void 0 : currentState.enteredDepth) != null ? _a : 0) && !(nextState.matchCriteria & (ETokenMatchCriteria.Attributes | ETokenMatchCriteria.Text | ETokenMatchCriteria.Node))) {
|
|
62
|
-
this.transitionForward(depth);
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
// Transition forward if attributes and depth match, and no additional criteria are required
|
|
68
|
-
transitionIfAttributesMatch(local, prefix, value, depth) {
|
|
69
|
-
var _a, _b;
|
|
70
|
-
const nextState = this.getNextState();
|
|
71
|
-
const currentState = this.getCurrentState();
|
|
72
|
-
if (nextState == null) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
const attributes = (_a = this._cachedNodeProps.attributes) != null ? _a : [];
|
|
76
|
-
attributes.push({ local, prefix, value });
|
|
77
|
-
if (nextState.toCacheNodeProps & EToCacheNodeProps.Attributes) {
|
|
78
|
-
this._cachedNodeProps.attributes = attributes;
|
|
79
|
-
}
|
|
80
|
-
if (nextState.matchesAttributes(attributes) && nextState.matchesDepth(depth, (_b = currentState == null ? void 0 : currentState.enteredDepth) != null ? _b : 0) && !(nextState.matchCriteria & (ETokenMatchCriteria.Text | ETokenMatchCriteria.Node))) {
|
|
81
|
-
this.transitionForward(depth);
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
// Transition forward if text content and depth match, and no additional criteria are required
|
|
87
|
-
transitionIfTextMatch(text, depth) {
|
|
88
|
-
var _a;
|
|
89
|
-
const nextState = this.getNextState();
|
|
90
|
-
const currentState = this.getCurrentState();
|
|
91
|
-
if (nextState == null) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
if (nextState.toCacheNodeProps & EToCacheNodeProps.Text) {
|
|
95
|
-
this._cachedNodeProps.text = text;
|
|
96
|
-
}
|
|
97
|
-
if (nextState.matchesText(text) && nextState.matchesDepth(depth, (_a = currentState == null ? void 0 : currentState.enteredDepth) != null ? _a : 0) && !(nextState.matchCriteria & ETokenMatchCriteria.Node)) {
|
|
98
|
-
this.transitionForward(depth);
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
transitionForward(depth) {
|
|
104
|
-
const previousState = this.getCurrentState();
|
|
105
|
-
if (previousState != null) {
|
|
106
|
-
previousState.unmatch();
|
|
107
|
-
}
|
|
108
|
-
this._currentState = this._currentState != null ? this._currentState + 1 : 0;
|
|
109
|
-
const currentState = this.getCurrentState();
|
|
110
|
-
if (currentState != null) {
|
|
111
|
-
currentState.match(depth);
|
|
112
|
-
}
|
|
113
|
-
if (this.isFinalState()) {
|
|
114
|
-
this._toRecordTokens = this._cachedTokens;
|
|
115
|
-
}
|
|
116
|
-
this.resetCurrentStateCache();
|
|
117
|
-
}
|
|
118
|
-
transitionBack(depth) {
|
|
119
|
-
const previousState = this.getCurrentState();
|
|
120
|
-
if (previousState != null) {
|
|
121
|
-
previousState.unmatch();
|
|
122
|
-
}
|
|
123
|
-
this._currentState = this._currentState != null ? this._currentState - 1 : 0;
|
|
124
|
-
const currentState = this.getCurrentState();
|
|
125
|
-
if (currentState != null) {
|
|
126
|
-
currentState.match(depth);
|
|
127
|
-
}
|
|
128
|
-
this.resetCurrentStateCache();
|
|
129
|
-
}
|
|
130
|
-
isFinalState() {
|
|
131
|
-
return this._currentState != null && this._currentState >= this._states.length - 1;
|
|
132
|
-
}
|
|
133
|
-
getOffsetToFinal() {
|
|
134
|
-
if (this._currentState == null) {
|
|
135
|
-
return this._states.length;
|
|
136
|
-
}
|
|
137
|
-
return this._states.length - 1 - this._currentState;
|
|
138
|
-
}
|
|
139
|
-
resetCurrentStateCache() {
|
|
140
|
-
this._cachedNodeProps.prefix = null;
|
|
141
|
-
this._cachedNodeProps.local = null;
|
|
142
|
-
this._cachedNodeProps.attributes = null;
|
|
143
|
-
this._cachedNodeProps.text = null;
|
|
144
|
-
this._cachedTokens = [];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export { TokenSelectStateMachine };
|
|
1
|
+
import{TokenSelectState as _,EToCacheNodeProps as u,ETokenMatchCriteria as h}from"./TokenSelectState.js";var S=Object.defineProperty,p=(n,t,e)=>t in n?S(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,o=(n,t,e)=>p(n,typeof t!="symbol"?t+"":t,e);class N{constructor(t){o(this,"_states"),o(this,"_currentState",null),o(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),o(this,"_cachedTokens",[]),o(this,"_toRecordTokens",[]),this._states=t.map(e=>new _(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(),i=this.getCurrentState();return a==null?!1:(a.toCacheNodeProps&u.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),a.matchesName(t,e)&&a.matchesDepth(r,(s=i==null?void 0:i.enteredDepth)!=null?s:0)&&!(a.matchCriteria&(h.Attributes|h.Text|h.Node))?(this.transitionForward(r),!0):!1)}transitionIfAttributesMatch(t,e,r,s){var a,i;const l=this.getNextState(),d=this.getCurrentState();if(l==null)return!1;const c=(a=this._cachedNodeProps.attributes)!=null?a:[];return c.push({local:t,prefix:e,value:r}),l.toCacheNodeProps&u.Attributes&&(this._cachedNodeProps.attributes=c),l.matchesAttributes(c)&&l.matchesDepth(s,(i=d==null?void 0:d.enteredDepth)!=null?i:0)&&!(l.matchCriteria&(h.Text|h.Node))?(this.transitionForward(s),!0):!1}transitionIfTextMatch(t,e){var r;const s=this.getNextState(),a=this.getCurrentState();return s==null?!1:(s.toCacheNodeProps&u.Text&&(this._cachedNodeProps.text=t),s.matchesText(t)&&s.matchesDepth(e,(r=a==null?void 0:a.enteredDepth)!=null?r:0)&&!(s.matchCriteria&h.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=[]}}export{N as TokenSelectStateMachine};
|
|
@@ -1,137 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { TokenSelectStateMachine } from './TokenSelectStateMachine.js';
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
class TokenSelector {
|
|
8
|
-
constructor(tokenSelectPaths) {
|
|
9
|
-
__publicField(this, "_currentDepth", 0);
|
|
10
|
-
__publicField(this, "_tspStateMachines");
|
|
11
|
-
__publicField(this, "_isRecording", false);
|
|
12
|
-
this._tspStateMachines = tokenSelectPaths.map(
|
|
13
|
-
(tokenSelectPath) => new TokenSelectStateMachine(tokenSelectPath)
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
pipeToken(token, recorder) {
|
|
17
|
-
let startRecording = false;
|
|
18
|
-
let stopRecording = false;
|
|
19
|
-
switch (token.type) {
|
|
20
|
-
case "ElementStart":
|
|
21
|
-
startRecording = this.handleElementStart(token);
|
|
22
|
-
break;
|
|
23
|
-
case "Attribute":
|
|
24
|
-
startRecording = this.handleAttribute(token);
|
|
25
|
-
break;
|
|
26
|
-
case "Text":
|
|
27
|
-
startRecording = this.handleText(token);
|
|
28
|
-
break;
|
|
29
|
-
case "ElementEnd": {
|
|
30
|
-
stopRecording = this.handleElementEnd(token);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (startRecording && !this._isRecording) {
|
|
35
|
-
this._isRecording = true;
|
|
36
|
-
recorder({ type: "SelectionStart" });
|
|
37
|
-
}
|
|
38
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
39
|
-
stateMachine.record(token);
|
|
40
|
-
const recordedTokens = stateMachine.takeRecordedTokens();
|
|
41
|
-
if (recordedTokens != null) {
|
|
42
|
-
recordedTokens.forEach((t) => {
|
|
43
|
-
recorder(t);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (this._isRecording) {
|
|
48
|
-
recorder(token);
|
|
49
|
-
}
|
|
50
|
-
if (stopRecording) {
|
|
51
|
-
recorder({ type: "SelectionEnd" });
|
|
52
|
-
this._isRecording = false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
handleElementStart(token) {
|
|
56
|
-
this._currentDepth += 1;
|
|
57
|
-
let startRecording = false;
|
|
58
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
59
|
-
stateMachine.resetCurrentStateCache();
|
|
60
|
-
if (stateMachine.isFinalState()) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const nextState = stateMachine.getNextState();
|
|
64
|
-
if (nextState == null || !(nextState.matchCriteria & ETokenMatchCriteria.Name)) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const transitioned = stateMachine.transitionIfNameMatch(
|
|
68
|
-
token.local,
|
|
69
|
-
token.prefix,
|
|
70
|
-
this._currentDepth
|
|
71
|
-
);
|
|
72
|
-
if (transitioned && stateMachine.isFinalState()) {
|
|
73
|
-
startRecording = true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return startRecording;
|
|
77
|
-
}
|
|
78
|
-
handleAttribute(token) {
|
|
79
|
-
let startRecording = false;
|
|
80
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
81
|
-
if (stateMachine.isFinalState()) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const nextState = stateMachine.getNextState();
|
|
85
|
-
if (nextState == null || !(nextState.matchCriteria & ETokenMatchCriteria.Attributes)) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const transitioned = stateMachine.transitionIfAttributesMatch(
|
|
89
|
-
token.local,
|
|
90
|
-
token.prefix,
|
|
91
|
-
token.value,
|
|
92
|
-
this._currentDepth
|
|
93
|
-
);
|
|
94
|
-
if (transitioned && stateMachine.isFinalState()) {
|
|
95
|
-
startRecording = true;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return startRecording;
|
|
99
|
-
}
|
|
100
|
-
handleText(token) {
|
|
101
|
-
let startRecording = false;
|
|
102
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
103
|
-
if (stateMachine.isFinalState()) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const nextState = stateMachine.getNextState();
|
|
107
|
-
if (nextState == null || !(nextState.matchCriteria & ETokenMatchCriteria.Text)) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const transitioned = stateMachine.transitionIfTextMatch(token.text, this._currentDepth);
|
|
111
|
-
if (transitioned && stateMachine.isFinalState()) {
|
|
112
|
-
startRecording = true;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return startRecording;
|
|
116
|
-
}
|
|
117
|
-
handleElementEnd(token) {
|
|
118
|
-
if (token.end.type === "Close" || token.end.type === "Empty") {
|
|
119
|
-
this._currentDepth -= 1;
|
|
120
|
-
let isFinalState = false;
|
|
121
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
122
|
-
const currentState = stateMachine.getCurrentState();
|
|
123
|
-
if (currentState == null) {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (currentState.enteredDepth != null && this._currentDepth < currentState.enteredDepth) {
|
|
127
|
-
stateMachine.transitionBack(this._currentDepth);
|
|
128
|
-
}
|
|
129
|
-
isFinalState = isFinalState || stateMachine.isFinalState();
|
|
130
|
-
}
|
|
131
|
-
return !isFinalState;
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { TokenSelector };
|
|
1
|
+
import{ETokenMatchCriteria as a}from"./TokenSelectState.js";import{TokenSelectStateMachine as o}from"./TokenSelectStateMachine.js";var u=Object.defineProperty,f=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,s=(r,t,e)=>f(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 o(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 l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{e(h)})}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.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.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.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}}export{p as TokenSelector};
|
|
@@ -1,19 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (typeof config === "string") {
|
|
3
|
-
return value === config;
|
|
4
|
-
}
|
|
5
|
-
switch (config.matchStrategy) {
|
|
6
|
-
case "ANY":
|
|
7
|
-
return true;
|
|
8
|
-
case "EXACT":
|
|
9
|
-
return value === config.value;
|
|
10
|
-
case "CONTAINS":
|
|
11
|
-
return value.includes(config.value);
|
|
12
|
-
case "STARTS_WITH":
|
|
13
|
-
return value.startsWith(config.value);
|
|
14
|
-
case "ENDS_WITH":
|
|
15
|
-
return value.endsWith(config.value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { matchString };
|
|
1
|
+
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)}}export{r as matchString};
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { TokenSelector } from './TokenSelector.js';
|
|
3
|
-
|
|
4
|
-
function select(xml, tokenSelectPaths, callback, options) {
|
|
5
|
-
const selector = new TokenSelector(tokenSelectPaths);
|
|
6
|
-
tokenize(
|
|
7
|
-
xml,
|
|
8
|
-
(token) => {
|
|
9
|
-
selector.pipeToken(token, (recordedToken) => {
|
|
10
|
-
callback(recordedToken);
|
|
11
|
-
});
|
|
12
|
-
},
|
|
13
|
-
options
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { select };
|
|
1
|
+
import{tokenize as c}from"../tokenizer/tokenize.js";import{TokenSelector as m}from"./TokenSelector.js";function f(e,o,t,n){const r=new m(o);c(e,i=>{r.pipeToken(i,p=>{t(p)})},n)}export{f as select};
|
package/dist/esm/token-to-xml.js
CHANGED
|
@@ -1,42 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
let xmlString = "";
|
|
3
|
-
switch (token.type) {
|
|
4
|
-
case "ProcessingInstruction":
|
|
5
|
-
xmlString += `<?${token.target}`;
|
|
6
|
-
if (token.content) {
|
|
7
|
-
xmlString += ` ${token.content}`;
|
|
8
|
-
}
|
|
9
|
-
xmlString += "?>";
|
|
10
|
-
break;
|
|
11
|
-
case "Comment":
|
|
12
|
-
xmlString += `<!--${token.text}-->`;
|
|
13
|
-
break;
|
|
14
|
-
case "EntityDeclaration":
|
|
15
|
-
xmlString += `<!ENTITY ${token.name} "${token.definition}">`;
|
|
16
|
-
break;
|
|
17
|
-
case "ElementStart":
|
|
18
|
-
xmlString += `<${token.prefix.length > 0 ? `${token.prefix}:` : ""}${token.local}`;
|
|
19
|
-
break;
|
|
20
|
-
case "Attribute":
|
|
21
|
-
xmlString += ` ${token.prefix.length > 0 ? `${token.prefix}:` : ""}${token.local}="${token.value}"`;
|
|
22
|
-
break;
|
|
23
|
-
case "ElementEnd":
|
|
24
|
-
if (token.end.type === "Open") {
|
|
25
|
-
xmlString += ">";
|
|
26
|
-
} else if (token.end.type === "Close") {
|
|
27
|
-
xmlString += `</${token.end.prefix.length > 0 ? `${token.end.prefix}:` : ""}${token.end.local}>`;
|
|
28
|
-
} else {
|
|
29
|
-
xmlString += "/>";
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
case "Text":
|
|
33
|
-
xmlString += token.text;
|
|
34
|
-
break;
|
|
35
|
-
case "Cdata":
|
|
36
|
-
xmlString += `<![CDATA[${token.text}]]>`;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
return xmlString;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { tokenToXml };
|
|
1
|
+
function n(t){let e="";switch(t.type){case"ProcessingInstruction":e+=`<?${t.target}`,t.content&&(e+=` ${t.content}`),e+="?>";break;case"Comment":e+=`<!--${t.text}-->`;break;case"EntityDeclaration":e+=`<!ENTITY ${t.name} "${t.definition}">`;break;case"ElementStart":e+=`<${t.prefix.length>0?`${t.prefix}:`:""}${t.local}`;break;case"Attribute":e+=` ${t.prefix.length>0?`${t.prefix}:`:""}${t.local}="${t.value}"`;break;case"ElementEnd":t.end.type==="Open"?e+=">":t.end.type==="Close"?e+=`</${t.end.prefix.length>0?`${t.end.prefix}:`:""}${t.end.local}>`:e+="/>";break;case"Text":e+=t.text;break;case"Cdata":e+=`<![CDATA[${t.text}]]>`;break}return e}export{n as tokenToXml};
|
|
@@ -1,94 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
class XmlError extends Error {
|
|
5
|
-
constructor(variant, pos = { col: 1, row: 1 }, message) {
|
|
6
|
-
super(message != null ? message : XmlError.toMessage(variant, pos));
|
|
7
|
-
__publicField(this, "variant");
|
|
8
|
-
__publicField(this, "pos");
|
|
9
|
-
this.variant = variant;
|
|
10
|
-
this.pos = pos;
|
|
11
|
-
}
|
|
12
|
-
static toMessage(variant, pos) {
|
|
13
|
-
switch (variant.type) {
|
|
14
|
-
case "InvalidXmlPrefixUri":
|
|
15
|
-
return `'xml' namespace prefix mapped to wrong URI at ${formatPos(pos)}`;
|
|
16
|
-
case "UnexpectedXmlUri":
|
|
17
|
-
return `the 'xml' namespace URI is used for not 'xml' prefix at ${formatPos(pos)}`;
|
|
18
|
-
case "UnexpectedXmlnsUri":
|
|
19
|
-
return `the 'xmlns' URI is used at ${formatPos(pos)}, but it must not be declared`;
|
|
20
|
-
case "InvalidElementNamePrefix":
|
|
21
|
-
return `the 'xmlns' prefix is used at ${formatPos(pos)}, but it must not be`;
|
|
22
|
-
case "DuplicatedNamespace":
|
|
23
|
-
return `namespace '${variant.name}' at ${formatPos(pos)} is already defined`;
|
|
24
|
-
case "UnknownNamespace":
|
|
25
|
-
return `an unknown namespace prefix '${variant.name}' at ${formatPos(pos)}`;
|
|
26
|
-
case "UnexpectedCloseTag":
|
|
27
|
-
return `expected '${variant.expected}' tag, not '${variant.actual}' at ${formatPos(pos)}`;
|
|
28
|
-
case "UnexpectedEntityCloseTag":
|
|
29
|
-
return `unexpected close tag at ${formatPos(pos)}`;
|
|
30
|
-
case "MalformedEntityReference":
|
|
31
|
-
return `malformed entity reference at ${formatPos(pos)}`;
|
|
32
|
-
case "UnknownEntityReference":
|
|
33
|
-
return `unknown entity reference '${variant.name}' at ${formatPos(pos)}`;
|
|
34
|
-
case "EntityReferenceLoop":
|
|
35
|
-
return `a possible entity reference loop is detected at ${formatPos(pos)}`;
|
|
36
|
-
case "InvalidAttributeValue":
|
|
37
|
-
return `unescaped '<' found at ${formatPos(pos)}`;
|
|
38
|
-
case "DuplicatedAttribute":
|
|
39
|
-
return `attribute '${variant.attribute}' at ${formatPos(pos)} is already defined`;
|
|
40
|
-
case "NoRootNode":
|
|
41
|
-
return `the document does not have a root node`;
|
|
42
|
-
case "UnclosedRootNode":
|
|
43
|
-
return `the root node was opened but never closed`;
|
|
44
|
-
case "UnexpectedDeclaration":
|
|
45
|
-
return `unexpected XML declaration at ${formatPos(pos)}`;
|
|
46
|
-
case "DtdDetected":
|
|
47
|
-
return `XML with DTD detected`;
|
|
48
|
-
case "NodesLimitReached":
|
|
49
|
-
return `nodes limit reached`;
|
|
50
|
-
case "AttributesLimitReached":
|
|
51
|
-
return `more than 2^32 attributes were parsed`;
|
|
52
|
-
case "NamespacesLimitReached":
|
|
53
|
-
return `more than 2^16 unique namespaces were parsed`;
|
|
54
|
-
case "InvalidName":
|
|
55
|
-
return `invalid name token at ${formatPos(pos)}`;
|
|
56
|
-
case "NonXmlChar":
|
|
57
|
-
return `a non-XML character '${toUnicodeEscape(variant.char)}' found at ${formatPos(pos)}`;
|
|
58
|
-
case "InvalidChar":
|
|
59
|
-
return `expected ${typeof variant.expected === "string" ? variant.expected : `'${toUnicodeEscape(variant.expected)}'`} not '${toUnicodeEscape(variant.actual)}' at ${formatPos(pos)}`;
|
|
60
|
-
case "InvalidString":
|
|
61
|
-
return `expected '${variant.expected}' at ${formatPos(pos)}`;
|
|
62
|
-
case "InvalidExternalID":
|
|
63
|
-
return `invalid ExternalID at ${formatPos(pos)}`;
|
|
64
|
-
case "InvalidComment":
|
|
65
|
-
return `comment at ${formatPos(pos)} contains '--'`;
|
|
66
|
-
case "InvalidCharacterData":
|
|
67
|
-
return `']]>' at ${formatPos(pos)} is not allowed inside a character data`;
|
|
68
|
-
case "UnknownToken":
|
|
69
|
-
return `unknown token at ${formatPos(pos)}`;
|
|
70
|
-
case "UnexpectedEndOfStream":
|
|
71
|
-
return `unexpected end of stream`;
|
|
72
|
-
default:
|
|
73
|
-
return `unknown error type`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function formatPos(pos) {
|
|
78
|
-
return `${pos.row.toString()}:${pos.col.toString()}`;
|
|
79
|
-
}
|
|
80
|
-
function toUnicodeEscape(codePoint) {
|
|
81
|
-
const code = typeof codePoint === "string" ? codePoint.charCodeAt(0) : codePoint;
|
|
82
|
-
if (code < 0 || code > 1114111) {
|
|
83
|
-
throw new Error("Code point out of range");
|
|
84
|
-
}
|
|
85
|
-
let hexString = code.toString(16).toUpperCase();
|
|
86
|
-
if (code <= 65535) {
|
|
87
|
-
hexString = hexString.padStart(4, "0");
|
|
88
|
-
} else {
|
|
89
|
-
hexString = hexString.padStart(6, "0");
|
|
90
|
-
}
|
|
91
|
-
return `\\u{${hexString}}`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { XmlError };
|
|
1
|
+
var i=Object.defineProperty,d=(a,t,e)=>t in a?i(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,s=(a,t,e)=>d(a,typeof t!="symbol"?t+"":t,e);class c extends Error{constructor(t,e={col:1,row:1},o){super(o!=null?o:c.toMessage(t,e)),s(this,"variant"),s(this,"pos"),this.variant=t,this.pos=e}static toMessage(t,e){switch(t.type){case"InvalidXmlPrefixUri":return`'xml' namespace prefix mapped to wrong URI at ${n(e)}`;case"UnexpectedXmlUri":return`the 'xml' namespace URI is used for not 'xml' prefix at ${n(e)}`;case"UnexpectedXmlnsUri":return`the 'xmlns' URI is used at ${n(e)}, but it must not be declared`;case"InvalidElementNamePrefix":return`the 'xmlns' prefix is used at ${n(e)}, but it must not be`;case"DuplicatedNamespace":return`namespace '${t.name}' at ${n(e)} is already defined`;case"UnknownNamespace":return`an unknown namespace prefix '${t.name}' at ${n(e)}`;case"UnexpectedCloseTag":return`expected '${t.expected}' tag, not '${t.actual}' at ${n(e)}`;case"UnexpectedEntityCloseTag":return`unexpected close tag at ${n(e)}`;case"MalformedEntityReference":return`malformed entity reference at ${n(e)}`;case"UnknownEntityReference":return`unknown entity reference '${t.name}' at ${n(e)}`;case"EntityReferenceLoop":return`a possible entity reference loop is detected at ${n(e)}`;case"InvalidAttributeValue":return`unescaped '<' found at ${n(e)}`;case"DuplicatedAttribute":return`attribute '${t.attribute}' at ${n(e)} is already defined`;case"NoRootNode":return"the document does not have a root node";case"UnclosedRootNode":return"the root node was opened but never closed";case"UnexpectedDeclaration":return`unexpected XML declaration at ${n(e)}`;case"DtdDetected":return"XML with DTD detected";case"NodesLimitReached":return"nodes limit reached";case"AttributesLimitReached":return"more than 2^32 attributes were parsed";case"NamespacesLimitReached":return"more than 2^16 unique namespaces were parsed";case"InvalidName":return`invalid name token at ${n(e)}`;case"NonXmlChar":return`a non-XML character '${r(t.char)}' found at ${n(e)}`;case"InvalidChar":return`expected ${typeof t.expected=="string"?t.expected:`'${r(t.expected)}'`} not '${r(t.actual)}' at ${n(e)}`;case"InvalidString":return`expected '${t.expected}' at ${n(e)}`;case"InvalidExternalID":return`invalid ExternalID at ${n(e)}`;case"InvalidComment":return`comment at ${n(e)} contains '--'`;case"InvalidCharacterData":return`']]>' at ${n(e)} is not allowed inside a character data`;case"UnknownToken":return`unknown token at ${n(e)}`;case"UnexpectedEndOfStream":return"unexpected end of stream";default:return"unknown error type"}}}function n(a){return`${a.row.toString()}:${a.col.toString()}${a.contextSlice!=null?` (${a.contextSlice})`:""}`}function r(a){const t=typeof a=="string"?a.charCodeAt(0):a;if(t<0||t>1114111)throw new Error("Code point out of range");let e=t.toString(16).toUpperCase();return t<=65535?e=e.padStart(4,"0"):e=e.padStart(6,"0"),`\\u{${e}}`}export{c as XmlError};
|