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

43 lines
1.4 KiB

exports.readRelationships = readRelationships;
exports.defaultValue = new Relationships([]);
exports.Relationships = Relationships;
function readRelationships(element) {
var relationships = [];
element.children.forEach(function(child) {
if (child.name === "{http://schemas.openxmlformats.org/package/2006/relationships}Relationship") {
var relationship = {
relationshipId: child.attributes.Id,
target: child.attributes.Target,
type: child.attributes.Type
};
relationships.push(relationship);
}
});
return new Relationships(relationships);
}
function Relationships(relationships) {
var targetsByRelationshipId = {};
relationships.forEach(function(relationship) {
targetsByRelationshipId[relationship.relationshipId] = relationship.target;
});
var targetsByType = {};
relationships.forEach(function(relationship) {
if (!targetsByType[relationship.type]) {
targetsByType[relationship.type] = [];
}
targetsByType[relationship.type].push(relationship.target);
});
return {
findTargetByRelationshipId: function(relationshipId) {
return targetsByRelationshipId[relationshipId];
},
findTargetsByType: function(type) {
return targetsByType[type] || [];
}
};
}