You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
766 B
JavaScript

"use strict";
const assureArray = require("assure-array");
function normalizeTags(item) {
let tags = { _item: [] };
let data = {};
let canonicalItem = item;
while (canonicalItem.__tag != null) {
tags._item.push(canonicalItem.__tag);
canonicalItem = canonicalItem.__content;
}
for (let property of Object.keys(canonicalItem)) {
let value = canonicalItem[property];
tags[property] = [];
while (value != null && value.__tag != null) {
tags[property].push(value.__tag);
value = value.__contents;
}
data[property] = value;
}
return {
tags: tags,
data: data
};
}
module.exports = function normalizeItems(items) {
if (items == null) {
return [];
} else {
return assureArray(items).map((item) => normalizeTags(item));
}
};