Convert a DOI or DOI URL to JSON via CrossRef API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets JSON citation data from the CrossRef API for a DOI or DOI URL | |
* @param doi A DOI or DOI URL | |
*/ | |
export async function doi2json(doiOrUrl: string) { | |
// Extract the DOI from the URL | |
const doi = doiOrUrl.replace('https://doi.org/', ''); | |
// Fetch data from the CrossRef API | |
const response = await fetch(`https://api.crossref.org/works/${doi}`); | |
if (!response.ok) { | |
throw new Error(`HTTP error! status: ${response.status}`); | |
} | |
const data = await response.json(); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment