@flighthq/xml 0.5.1-next.920.da8f530 → 0.7.0-edge.5213.ead804b
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/README.md +2 -2
- package/dist/contract.d.ts +3 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +4 -2
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/xmlNative.d.ts +24 -0
- package/dist/xmlNative.d.ts.map +1 -0
- package/dist/xmlNative.js +198 -0
- package/dist/xmlNative.js.map +1 -0
- package/dist/xmlParse.d.ts +12 -7
- package/dist/xmlParse.d.ts.map +1 -1
- package/dist/xmlParse.js +111 -226
- package/dist/xmlParse.js.map +1 -1
- package/dist/xmlQuery.d.ts +16 -6
- package/dist/xmlQuery.d.ts.map +1 -1
- package/dist/xmlQuery.js +42 -16
- package/dist/xmlQuery.js.map +1 -1
- package/package.json +4 -5
- package/src/xmlNative.test.ts +206 -0
- package/src/xmlParse.test.ts +170 -212
- package/src/xmlQuery.test.ts +38 -37
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/xml`. The `@flighthq
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/xml@0.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/xml@0.7.0-edge.5213.ead804b](https://github.com/flighthq/flight/tree/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/packages/xml)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export type { XmlContent, XmlElement } from './types.ts';
|
|
2
|
+
export { parseXmlAttributes, parseXmlDocument } from './xmlParse.ts';
|
|
3
|
+
export { getXmlElementAttribute, getXmlElementAttributeNumber, getXmlElementChildByName, getXmlElementChildrenByName, } from './xmlQuery.ts';
|
|
3
4
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,eAAe,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Generated from crates/flight-xml/src/lib.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
export { parseXmlAttributes, parseXmlDocument } from './xmlParse.js';
|
|
4
|
+
export { getXmlElementAttribute, getXmlElementAttributeNumber, getXmlElementChildByName, getXmlElementChildrenByName, } from './xmlQuery.js';
|
|
3
5
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,mEAAmE;AAGnE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,eAAe,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { getXmlElementAttribute, getXmlElementAttributeNumber, getXmlElementChildByName, getXmlElementChildrenByName, parseXmlAttributes, parseXmlDocument, } from './contract';
|
|
1
|
+
export { getXmlElementAttribute, getXmlElementAttributeNumber, getXmlElementChildByName, getXmlElementChildrenByName, parseXmlAttributes, parseXmlDocument, } from './contract.ts';
|
|
2
|
+
export type { XmlContent, XmlElement } from './contract.ts';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-xml/src/lib.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
export { getXmlElementAttribute, getXmlElementAttributeNumber, getXmlElementChildByName, getXmlElementChildrenByName, parseXmlAttributes, parseXmlDocument, } from './contract.js';
|
|
2
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,mEAAmE;AAEnE,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Literal text or a child element in source order. */
|
|
2
|
+
export type XmlContent = string | XmlElement;
|
|
3
|
+
/** A parsed XML element and its direct content projections. */
|
|
4
|
+
export interface XmlElement {
|
|
5
|
+
attributes: Record<string, string>;
|
|
6
|
+
/** Direct child elements. Text content and comments are discarded as elements. */
|
|
7
|
+
children: XmlElement[];
|
|
8
|
+
/** Raw direct text nodes and child elements in source order. */
|
|
9
|
+
content: XmlContent[];
|
|
10
|
+
name: string;
|
|
11
|
+
/** Raw text content (trimmed), concatenation of text nodes. */
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;AAE7C,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,kFAAkF;IAClF,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,gEAAgE;IAChE,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { XmlElement } from './types.ts';
|
|
2
|
+
export type XmlRecord<Key extends string, Value> = Record<Key, Value>;
|
|
3
|
+
export type XmlScanner = string;
|
|
4
|
+
export declare function createXmlRecord(): XmlRecord<string, string>;
|
|
5
|
+
export declare function createXmlScanner(value: string): XmlScanner;
|
|
6
|
+
export declare function decodeXmlEntitiesNative(source: string): string;
|
|
7
|
+
export declare function expandXmlEntitiesNative(source: string, entities: Readonly<XmlRecord<string, string>>): string;
|
|
8
|
+
export declare function getXmlRecordValue(record: Readonly<XmlRecord<string, string>>, key: string): string | null;
|
|
9
|
+
export declare function parseXmlAttributesNative(attrs: string): XmlRecord<string, string>;
|
|
10
|
+
export declare function parseXmlNumberNative(value: string): number | null;
|
|
11
|
+
export declare function prepareXmlDocumentNative(xml: string, entities: XmlRecord<string, string>): string;
|
|
12
|
+
export declare function pushXmlElementContent(out: Array<string | XmlElement>, value: XmlElement): void;
|
|
13
|
+
export declare function pushXmlTextContent(out: Array<string | XmlElement>, value: string): void;
|
|
14
|
+
export declare function setXmlRecordValue(record: XmlRecord<string, string>, key: string, value: string): void;
|
|
15
|
+
export declare function xmlIsWhitespace(unit: number): boolean;
|
|
16
|
+
export declare function xmlRecordIsEmpty(record: Readonly<XmlRecord<string, string>>): boolean;
|
|
17
|
+
export declare function xmlScannerFind(scanner: Readonly<XmlScanner>, pattern: string, start: number): number | null;
|
|
18
|
+
export declare function xmlScannerLength(scanner: Readonly<XmlScanner>): number;
|
|
19
|
+
export declare function xmlScannerStartsWith(scanner: Readonly<XmlScanner>, start: number, pattern: string): boolean;
|
|
20
|
+
export declare function xmlScannerUnitAt(scanner: Readonly<XmlScanner>, position: number): number;
|
|
21
|
+
export declare function xmlStringFromCodePoint(codePoint: number): string | null;
|
|
22
|
+
export declare function xmlTrim(value: string): string;
|
|
23
|
+
export declare function xmlUtf16Slice(value: string, start: number, end: number): string;
|
|
24
|
+
//# sourceMappingURL=xmlNative.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xmlNative.d.ts","sourceRoot":"","sources":["../src/xmlNative.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,SAAS,CAAC,GAAG,SAAS,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACtE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAMhC,wBAAgB,eAAe,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAE1D;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU9D;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAgB7G;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGzG;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAQjF;AAED,wBAAgB,oB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AAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGvE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/E"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
const MAX_XML_ENTITY_PASSES = 8;
|
|
2
|
+
const MAX_XML_ENTITY_GROWTH = 16;
|
|
3
|
+
const MAX_XML_ENTITY_BUDGET = 65536;
|
|
4
|
+
export function createXmlRecord() {
|
|
5
|
+
return {};
|
|
6
|
+
}
|
|
7
|
+
export function createXmlScanner(value) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function decodeXmlEntitiesNative(source) {
|
|
11
|
+
return source.replace(/&(?:#(\d+)|#x([\da-fA-F]+)|(\w+));/g, (reference, decimal, hexadecimal, name) => {
|
|
12
|
+
const numeric = decimal ?? hexadecimal;
|
|
13
|
+
if (numeric !== undefined) {
|
|
14
|
+
const codePoint = Number.parseInt(numeric, decimal !== undefined ? 10 : 16);
|
|
15
|
+
if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff))
|
|
16
|
+
return reference;
|
|
17
|
+
return String.fromCodePoint(codePoint);
|
|
18
|
+
}
|
|
19
|
+
return xmlEntityReplacement(name) ?? reference;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function expandXmlEntitiesNative(source, entities) {
|
|
23
|
+
if (Object.keys(entities).length === 0)
|
|
24
|
+
return source;
|
|
25
|
+
let output = source;
|
|
26
|
+
const budget = source.length * MAX_XML_ENTITY_GROWTH + MAX_XML_ENTITY_BUDGET;
|
|
27
|
+
for (let pass = 0; pass < MAX_XML_ENTITY_PASSES; pass += 1) {
|
|
28
|
+
let expanded = false;
|
|
29
|
+
const next = output.replace(/&([\w:.-]+);/g, (reference, name) => {
|
|
30
|
+
const replacement = entities[name];
|
|
31
|
+
if (replacement === undefined)
|
|
32
|
+
return reference;
|
|
33
|
+
expanded = true;
|
|
34
|
+
return replacement;
|
|
35
|
+
});
|
|
36
|
+
if (!expanded || next.length > budget)
|
|
37
|
+
return output;
|
|
38
|
+
output = next;
|
|
39
|
+
}
|
|
40
|
+
return output;
|
|
41
|
+
}
|
|
42
|
+
export function getXmlRecordValue(record, key) {
|
|
43
|
+
const value = record[key];
|
|
44
|
+
return value === undefined ? null : value;
|
|
45
|
+
}
|
|
46
|
+
export function parseXmlAttributesNative(attrs) {
|
|
47
|
+
const result = createXmlRecord();
|
|
48
|
+
const expression = /([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
49
|
+
let match;
|
|
50
|
+
while ((match = expression.exec(attrs)) !== null) {
|
|
51
|
+
result[match[1]] = decodeXmlEntitiesNative(match[2] ?? match[3] ?? '');
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
export function parseXmlNumberNative(value) {
|
|
56
|
+
const parsed = Number(value);
|
|
57
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
58
|
+
}
|
|
59
|
+
export function prepareXmlDocumentNative(xml, entities) {
|
|
60
|
+
return stripXmlDoctypes(stripProcessingInstructions(stripXmlComments(xml).replace(/\r\n?/g, '\n')), entities);
|
|
61
|
+
}
|
|
62
|
+
export function pushXmlElementContent(out, value) {
|
|
63
|
+
out.push(value);
|
|
64
|
+
}
|
|
65
|
+
export function pushXmlTextContent(out, value) {
|
|
66
|
+
out.push(value);
|
|
67
|
+
}
|
|
68
|
+
export function setXmlRecordValue(record, key, value) {
|
|
69
|
+
record[key] = value;
|
|
70
|
+
}
|
|
71
|
+
export function xmlIsWhitespace(unit) {
|
|
72
|
+
return /\s/u.test(String.fromCharCode(unit));
|
|
73
|
+
}
|
|
74
|
+
export function xmlRecordIsEmpty(record) {
|
|
75
|
+
return Object.keys(record).length === 0;
|
|
76
|
+
}
|
|
77
|
+
export function xmlScannerFind(scanner, pattern, start) {
|
|
78
|
+
const position = scanner.indexOf(pattern, start);
|
|
79
|
+
return position < 0 ? null : position;
|
|
80
|
+
}
|
|
81
|
+
export function xmlScannerLength(scanner) {
|
|
82
|
+
return scanner.length;
|
|
83
|
+
}
|
|
84
|
+
export function xmlScannerStartsWith(scanner, start, pattern) {
|
|
85
|
+
return scanner.startsWith(pattern, start);
|
|
86
|
+
}
|
|
87
|
+
export function xmlScannerUnitAt(scanner, position) {
|
|
88
|
+
return scanner.charCodeAt(position);
|
|
89
|
+
}
|
|
90
|
+
export function xmlStringFromCodePoint(codePoint) {
|
|
91
|
+
if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff))
|
|
92
|
+
return null;
|
|
93
|
+
return String.fromCodePoint(codePoint);
|
|
94
|
+
}
|
|
95
|
+
export function xmlTrim(value) {
|
|
96
|
+
return value.trim();
|
|
97
|
+
}
|
|
98
|
+
export function xmlUtf16Slice(value, start, end) {
|
|
99
|
+
return value.slice(start, end);
|
|
100
|
+
}
|
|
101
|
+
function collectXmlEntityDeclarations(doctype, out) {
|
|
102
|
+
const declaration = /<!ENTITY\s+([\w:.-]+)\s*(?:"([^"]*)"|'([^']*)')\s*>/g;
|
|
103
|
+
let match;
|
|
104
|
+
while ((match = declaration.exec(doctype)) !== null) {
|
|
105
|
+
out[match[1]] = match[2] ?? match[3] ?? '';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function stripProcessingInstructions(xml) {
|
|
109
|
+
let copyStart = 0;
|
|
110
|
+
let output = '';
|
|
111
|
+
let position = 0;
|
|
112
|
+
while (position < xml.length) {
|
|
113
|
+
if (!xml.startsWith('<?', position)) {
|
|
114
|
+
position += 1;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
output += xml.slice(copyStart, position);
|
|
118
|
+
const end = xml.indexOf('?>', position + 2);
|
|
119
|
+
position = end < 0 ? xml.length : end + 2;
|
|
120
|
+
copyStart = position;
|
|
121
|
+
}
|
|
122
|
+
return output + xml.slice(copyStart);
|
|
123
|
+
}
|
|
124
|
+
function stripXmlComments(xml) {
|
|
125
|
+
let copyStart = 0;
|
|
126
|
+
let output = '';
|
|
127
|
+
let position = 0;
|
|
128
|
+
while (position < xml.length) {
|
|
129
|
+
if (xml.startsWith('<![CDATA[', position)) {
|
|
130
|
+
const end = xml.indexOf(']]>', position + 9);
|
|
131
|
+
position = end < 0 ? xml.length : end + 3;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (!xml.startsWith('<!--', position)) {
|
|
135
|
+
position += 1;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
output += xml.slice(copyStart, position);
|
|
139
|
+
const end = xml.indexOf('-->', position + 4);
|
|
140
|
+
position = end < 0 ? xml.length : end + 3;
|
|
141
|
+
copyStart = position;
|
|
142
|
+
}
|
|
143
|
+
return output + xml.slice(copyStart);
|
|
144
|
+
}
|
|
145
|
+
function stripXmlDoctypes(xml, out) {
|
|
146
|
+
let copyStart = 0;
|
|
147
|
+
let output = '';
|
|
148
|
+
let position = 0;
|
|
149
|
+
while (position < xml.length) {
|
|
150
|
+
if (xml[position] !== '<' || xml.slice(position, position + 9).toLowerCase() !== '<!doctype') {
|
|
151
|
+
position += 1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
output += xml.slice(copyStart, position);
|
|
155
|
+
const doctypeStart = position;
|
|
156
|
+
position += 9;
|
|
157
|
+
let internalSubsetDepth = 0;
|
|
158
|
+
let quote = '';
|
|
159
|
+
while (position < xml.length) {
|
|
160
|
+
const character = xml[position];
|
|
161
|
+
if (quote !== '') {
|
|
162
|
+
if (character === quote)
|
|
163
|
+
quote = '';
|
|
164
|
+
}
|
|
165
|
+
else if (character === '"' || character === "'") {
|
|
166
|
+
quote = character;
|
|
167
|
+
}
|
|
168
|
+
else if (character === '[') {
|
|
169
|
+
internalSubsetDepth += 1;
|
|
170
|
+
}
|
|
171
|
+
else if (character === ']' && internalSubsetDepth > 0) {
|
|
172
|
+
internalSubsetDepth -= 1;
|
|
173
|
+
}
|
|
174
|
+
else if (character === '>' && internalSubsetDepth === 0) {
|
|
175
|
+
position += 1;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
position += 1;
|
|
179
|
+
}
|
|
180
|
+
collectXmlEntityDeclarations(xml.slice(doctypeStart, position), out);
|
|
181
|
+
copyStart = position;
|
|
182
|
+
}
|
|
183
|
+
return output + xml.slice(copyStart);
|
|
184
|
+
}
|
|
185
|
+
function xmlEntityReplacement(name) {
|
|
186
|
+
if (name === 'amp')
|
|
187
|
+
return '&';
|
|
188
|
+
if (name === 'apos')
|
|
189
|
+
return "'";
|
|
190
|
+
if (name === 'gt')
|
|
191
|
+
return '>';
|
|
192
|
+
if (name === 'lt')
|
|
193
|
+
return '<';
|
|
194
|
+
if (name === 'quot')
|
|
195
|
+
return '"';
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=xmlNative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xmlNative.js","sourceRoot":"","sources":["../src/xmlNative.ts"],"names":[],"mappings":"AAKA,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC,MAAM,UAAU,eAAe;IAC7B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAc;IACpD,OAAO,MAAM,CAAC,OAAO,CAAC,qCAAqC,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;QACrG,MAAM,OAAO,GAAG,OAAO,IAAI,WAAW,CAAC;QACvC,IAAI,OAAO,KAAK,SAAS,EAAE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,MAAM;YACR,CAAC;YACD,QAAQ,IAAI,CAAC,CAAC;QAChB,CAAC;QACD,4BAA4B,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;QACrE,SAAS,GAAG,QAAQ,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACxC,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,GAAG,CAAC;IAC/B,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,GAAG,CAAC;IAChC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IAC9B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IAC9B,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,GAAG,CAAC;IAChC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/xmlParse.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import type { XmlElement } from '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { XmlElement } from './types.ts';
|
|
2
|
+
import type { XmlRecord } from './xmlNative.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Parse all attributes from an element's attribute string.
|
|
5
|
+
* Supports double-quoted and single-quoted values and XML entity escapes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseXmlAttributes(attributes: string): XmlRecord<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Parse a simple XML document into a tree of XmlElement objects.
|
|
10
|
+
* Returns the root element, or None when the input contains no recognizable element.
|
|
11
|
+
* Does not validate DTD, namespaces, or processing instructions.
|
|
12
|
+
*/
|
|
8
13
|
export declare function parseXmlDocument(xml: string): XmlElement | null;
|
|
9
14
|
//# sourceMappingURL=xmlParse.d.ts.map
|
package/dist/xmlParse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xmlParse.d.ts","sourceRoot":"","sources":["../src/xmlParse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xmlParse.d.ts","sourceRoot":"","sources":["../src/xmlParse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,gBAAgB,CAAC;AAoJ5D;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAQ/D"}
|