site/node_modules/@citation-js/plugin-bibjson/lib-mjs/index.js
2024-10-14 08:09:33 +02:00

62 lines
1.5 KiB
JavaScript

import * as json from './json.js';
import { plugins } from '@citation-js/core';
const scraperLinks = ['fulltext_html', 'fulltext_xml', 'fulltext_pdf'];
const authorNameFields = ['name', 'lastname', 'lastName', 'firstname', 'firstName'];
const ref = '@bibjson';
const parsers = {
json
};
const formats = {
'@bibjson/quickscrape+record+object': {
parse: json.quickscrapeRecord,
parseType: {
propertyConstraint: {
props: 'link',
value(links) {
return scraperLinks.some(link => links.find(({
type
}) => type === link));
}
},
extends: '@bibjson/record+object'
}
},
'@bibjson/record+object': {
parse: json.record,
parseType: {
dataType: 'SimpleObject',
propertyConstraint: [{
props: 'title'
}, {
props: ['author', 'editor'],
match: 'some',
value(authors) {
return Array.isArray(authors) && authors[0] && authorNameFields.some(field => field in authors[0]);
}
}]
}
},
'@bibjson/collection+object': {
parse(collection) {
return collection.records;
},
parseType: {
dataType: 'SimpleObject',
propertyConstraint: [{
props: 'metadata',
value(metadata) {
return 'collection' in metadata;
}
}, {
props: 'records',
value(records) {
return Array.isArray(records);
}
}]
}
}
};
plugins.add(ref, {
input: formats
});
export { ref, parsers, formats };