The CAS number to get the names of
The names of the CAS number
getNamesByCAS("79-11-8")
// Returns ['2-chloroacetic acid', '2-chloroethanoic acid', 'Acide chloracetique', ...etc]
getNamesByCAS("1234567890")
// Returns undefined
export async function getNamesByCAS(cas: CAS<string>): Promise<Maybe<string[]>> {
try {
const response = await fetch(
`https://cactus.nci.nih.gov/chemical/structure/${encodeURIComponent(cas)}/names`,
);
const data = await response.text();
if (!data) return;
return data.split("\n").map((line: string) => line.trim());
} catch (error) {
console.error(error);
return;
}
}
Gets the names of a CAS number from the Cactus API.