Raw HTML that may contain an anchor linking to a PDF
The PDF URL, or undefined if none is found
findPdfHref('<a href="https://x.com/sds.pdf" target="_blank">Safety Data Sheet</a>')
// "https://x.com/sds.pdf"
findPdfHref("<p>No documents here</p>") // undefined
export function findPdfHref(html: string): string | undefined {
if (!html || typeof html !== 'string') return undefined;
return html.match(PDF_HREF_REGEX)?.[1];
}
Finds the href of the first PDF-linking anchor in a block of HTML. Useful for pulling out linked documents such as Safety Data Sheets or spec sheets that suppliers attach as
<a href="….pdf">inside descriptions or info sections.