@f-o-t/ofx 1.1.0 → 1.2.0
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/index.js +15 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -220,7 +220,11 @@ function parseHeader(content) {
|
|
|
220
220
|
function addToContent(content, key, value) {
|
|
221
221
|
const existing = content[key];
|
|
222
222
|
if (existing !== undefined) {
|
|
223
|
-
|
|
223
|
+
if (Array.isArray(existing)) {
|
|
224
|
+
existing.push(value);
|
|
225
|
+
} else {
|
|
226
|
+
content[key] = [existing, value];
|
|
227
|
+
}
|
|
224
228
|
} else {
|
|
225
229
|
content[key] = value;
|
|
226
230
|
}
|
|
@@ -228,6 +232,7 @@ function addToContent(content, key, value) {
|
|
|
228
232
|
function sgmlToObject(sgml) {
|
|
229
233
|
const result = {};
|
|
230
234
|
const tagStack = [{ content: result, name: "root" }];
|
|
235
|
+
const stackMap = new Map([["root", 0]]);
|
|
231
236
|
const cleanSgml = sgml.replace(/<\?.*?\?>/g, "").replace(/<!--.*?-->/gs, "").trim();
|
|
232
237
|
const tagRegex = /<(\/?)([\w.]+)>([^<]*)/g;
|
|
233
238
|
let match = tagRegex.exec(cleanSgml);
|
|
@@ -245,14 +250,21 @@ function sgmlToObject(sgml) {
|
|
|
245
250
|
continue;
|
|
246
251
|
}
|
|
247
252
|
if (isClosing) {
|
|
248
|
-
|
|
249
|
-
|
|
253
|
+
const stackIndex = stackMap.get(tagName);
|
|
254
|
+
if (stackIndex !== undefined && stackIndex > 0) {
|
|
255
|
+
for (let i = tagStack.length - 1;i >= stackIndex; i--) {
|
|
256
|
+
const item = tagStack[i];
|
|
257
|
+
if (item)
|
|
258
|
+
stackMap.delete(item.name);
|
|
259
|
+
}
|
|
260
|
+
tagStack.length = stackIndex;
|
|
250
261
|
}
|
|
251
262
|
} else if (textContent) {
|
|
252
263
|
addToContent(current.content, tagName, textContent);
|
|
253
264
|
} else {
|
|
254
265
|
const newObj = {};
|
|
255
266
|
addToContent(current.content, tagName, newObj);
|
|
267
|
+
stackMap.set(tagName, tagStack.length);
|
|
256
268
|
tagStack.push({ content: newObj, name: tagName });
|
|
257
269
|
}
|
|
258
270
|
match = tagRegex.exec(cleanSgml);
|
package/package.json
CHANGED