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

25 lines
795 B
JavaScript

import { plugins } from '@citation-js/core';
import { format as mapBiblatex, formatBibtex as mapBibtex } from './entries.js';
import { format } from './bibtex.js';
import { format as formatBibtxt } from './bibtxt.js';
const factory = function (mapper, formatter) {
return function (data, opts = {}) {
const {
type,
format = type || 'text'
} = opts;
data = mapper(data);
if (format === 'object') {
return data;
} else if (plugins.dict.has(format)) {
return formatter(data, plugins.dict.get(format), opts);
} else {
throw new RangeError(`Output dictionary "${format}" not available`);
}
};
};
export default {
bibtex: factory(mapBibtex, format),
biblatex: factory(mapBiblatex, format),
bibtxt: factory(mapBibtex, formatBibtxt)
};