xml-tokenizer 0.0.22 → 0.0.24
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 +7 -1
- package/dist/cjs/index.js +75 -1
- package/dist/cjs/selector/TokenSelectState.js +106 -1
- package/dist/cjs/selector/TokenSelectStateMachine.js +150 -1
- package/dist/cjs/selector/TokenSelector.js +139 -1
- package/dist/cjs/selector/match-string.js +21 -1
- package/dist/cjs/selector/select.js +19 -1
- package/dist/cjs/token-to-xml.js +44 -1
- package/dist/cjs/tokenizer/XmlError.js +96 -1
- package/dist/cjs/tokenizer/XmlStream.js +447 -1
- package/dist/cjs/tokenizer/ascii-constants.js +69 -1
- package/dist/cjs/tokenizer/tokenize.js +408 -1
- package/dist/cjs/tokenizer/utils.js +47 -1
- package/dist/cjs/tokens-to-xml.js +13 -1
- package/dist/cjs/xml-to-object.js +69 -1
- package/dist/cjs/xml-to-simplified-object.js +86 -1
- package/dist/esm/get-q-name.js +5 -1
- package/dist/esm/index.js +14 -1
- package/dist/esm/selector/TokenSelectState.js +102 -1
- package/dist/esm/selector/TokenSelectStateMachine.js +148 -1
- package/dist/esm/selector/TokenSelector.js +137 -1
- package/dist/esm/selector/match-string.js +19 -1
- package/dist/esm/selector/select.js +17 -1
- package/dist/esm/token-to-xml.js +42 -1
- package/dist/esm/tokenizer/XmlError.js +94 -1
- package/dist/esm/tokenizer/XmlStream.js +445 -1
- package/dist/esm/tokenizer/ascii-constants.js +35 -1
- package/dist/esm/tokenizer/tokenize.js +405 -1
- package/dist/esm/tokenizer/utils.js +40 -1
- package/dist/esm/tokens-to-xml.js +11 -1
- package/dist/esm/xml-to-object.js +66 -1
- package/dist/esm/xml-to-simplified-object.js +83 -1
- package/dist/types/get-q-name.d.ts +1 -0
- package/dist/types/get-q-name.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/selector/TokenSelectState.d.ts +1 -0
- package/dist/types/selector/TokenSelectState.d.ts.map +1 -0
- package/dist/types/selector/TokenSelectStateMachine.d.ts +1 -0
- package/dist/types/selector/TokenSelectStateMachine.d.ts.map +1 -0
- package/dist/types/selector/TokenSelector.d.ts +1 -0
- package/dist/types/selector/TokenSelector.d.ts.map +1 -0
- package/dist/types/selector/index.d.ts +1 -0
- package/dist/types/selector/index.d.ts.map +1 -0
- package/dist/types/selector/match-string.d.ts +1 -0
- package/dist/types/selector/match-string.d.ts.map +1 -0
- package/dist/types/selector/select.d.ts +1 -0
- package/dist/types/selector/select.d.ts.map +1 -0
- package/dist/types/selector/types.d.ts +1 -0
- package/dist/types/selector/types.d.ts.map +1 -0
- package/dist/types/token-to-xml.d.ts +1 -0
- package/dist/types/token-to-xml.d.ts.map +1 -0
- package/dist/types/tokenizer/XmlError.d.ts +1 -0
- package/dist/types/tokenizer/XmlError.d.ts.map +1 -0
- package/dist/types/tokenizer/XmlStream.d.ts +3 -7
- package/dist/types/tokenizer/XmlStream.d.ts.map +1 -0
- package/dist/types/tokenizer/ascii-constants.d.ts +1 -0
- package/dist/types/tokenizer/ascii-constants.d.ts.map +1 -0
- package/dist/types/tokenizer/index.d.ts +1 -0
- package/dist/types/tokenizer/index.d.ts.map +1 -0
- package/dist/types/tokenizer/tokenize.d.ts +1 -0
- package/dist/types/tokenizer/tokenize.d.ts.map +1 -0
- package/dist/types/tokenizer/types.d.ts +1 -0
- package/dist/types/tokenizer/types.d.ts.map +1 -0
- package/dist/types/tokenizer/utils.d.ts +1 -0
- package/dist/types/tokenizer/utils.d.ts.map +1 -0
- package/dist/types/tokens-to-xml.d.ts +1 -0
- package/dist/types/tokens-to-xml.d.ts.map +1 -0
- package/dist/types/xml-to-object.d.ts +1 -0
- package/dist/types/xml-to-object.d.ts.map +1 -0
- package/dist/types/xml-to-simplified-object.d.ts +1 -0
- package/dist/types/xml-to-simplified-object.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/cjs/get-q-name.js
CHANGED
|
@@ -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;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +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 +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 +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 +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 +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 +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;
|
package/dist/cjs/token-to-xml.js
CHANGED
|
@@ -1 +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;
|