How to use the citation-js.async function in citation-js

To help you get started, we’ve selected a few citation-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pubpub / pubpub / server / utils / citations.js View on Github external
})
		.map((attribution) => {
			return {
				given: attribution.user.firstName,
				family: attribution.user.lastName,
			};
		});
	const authorsEntry = authorData.length ? { author: authorData } : {};
	const commonData = {
		type: 'article-journal',
		title: pubData.title,
		...authorsEntry,
		'container-title': communityData.title,
		...getCollectionLevelData(primaryCollectionPub),
	};
	const pubCiteObject = await Cite.async({
		...commonData,
		id: pubData.id,
		DOI: pubData.doi,
		ISSN: pubData.doi ? communityData.issn : null,
		issued: pubIssuedDate && [getDatePartsObject(pubIssuedDate)],
		note: pubLink,
		URL: pubLink,
	});

	return {
		pub: {
			apa: pubCiteObject
				.get({ format: 'string', type: 'html', style: 'citation-apa', lang: 'en-US' })
				.replace(/\n/gi, ''),
			harvard: pubCiteObject
				.get({ format: 'string', type: 'html', style: 'citation-harvard', lang: 'en-US' })
github pubpub / pubpub / server / editor / queries.js View on Github external
const citeObjects = inputVals.map((input) => {
		if (!input.structuredValue) {
			return { ...input, html: '' };
		}
		try {
			return Cite.async(input.structuredValue)
				.then((data) => {
					const html = data.get({
						format: 'string',
						type: 'html',
						style: format,
						lang: 'en-US',
					});
					return { ...input, html: html };
				})
				.catch(() => {
					return { ...input, html: 'Error' };
				});
		} catch (err) {
			return { ...input, html: 'Error' };
		}
	});

citation-js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.

MIT
Latest version published 1 month ago

Package Health Score

68 / 100
Full package analysis