site/node_modules/@citation-js/plugin-bibtex/lib-mjs/output/entries.js

35 lines
967 B
JavaScript
Raw Normal View History

2024-10-14 06:09:33 +00:00
import { format as mapBiblatex, formatBibtex as mapBibtex } from '../mapping/index.js';
import { format as formatValue, formatAnnotation } from './value.js';
function formatEntryValues({
type,
label,
properties
}) {
const output = {
type,
label,
properties: {}
};
for (const property in properties) {
const value = properties[property];
const [field, annotation] = property.split('+an:');
if (annotation) {
if (!output.annotations) {
output.annotations = {};
}
if (!output.annotations[field]) {
output.annotations[field] = {};
}
output.annotations[field][annotation] = formatAnnotation(value);
} else {
output.properties[property] = formatValue(property, value);
}
}
return output;
}
export function format(entries) {
return mapBiblatex(entries).map(formatEntryValues);
}
export function formatBibtex(entries) {
return mapBibtex(entries).map(formatEntryValues);
}