ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function getNamesByCAS

    • Gets the names of a CAS number from the Cactus API.

      Parameters

      • cas: `${string}-${string}-${string}`

        The CAS number to get the names of

      Returns Promise<Maybe<string[]>>

      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;
      }
      }