The chemical name to lookup
The CAS number of the chemical
getCASByName("Acetic Acid")
// Returns '79-11-8'
getCASByName("Acide chloracetique")
// Returns '79-11-8'
getCASByName("adsfasfd")
// Returns undefined
export async function getCASByName(name: string): Promise<Maybe<CAS<string>>> {
try {
const response = await fetch(
`https://cactus.nci.nih.gov/chemical/structure/${encodeURIComponent(name)}/cas`,
);
const data = await response.text();
if (typeof data === 'undefined') return;
const casList = data.split('\n').find((cas) => isCAS(cas));
return casList;
} catch (error) {
console.error(error);
return;
}
}
Gets the CAS of a chemical using the name from the Cactus API.