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

25 lines
795 B
JavaScript
Raw Permalink Normal View History

2024-10-14 06:09:33 +00:00
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)
};