ChemPal Documentation - v1.18.0
    Preparing search index...

    Function deriveChemicalInfo

    • Merges whatever the sources have returned so far into a ChemicalInfo. Recomputed on each update, so the title, links and structure image fill in as data arrives.

      Parameters

      Returns ChemicalInfo

      The merged info.

      deriveChemicalInfo('67-64-1', initialSources());
      // { term: "67-64-1", cas: "67-64-1", synonyms: [], imageUrls: [<NIST image>], ... }
      export function deriveChemicalInfo(term: string, sources: ChemicalInfoSources): ChemicalInfo {
      const english = sources.english.value;
      const osha = sources.osha.value;
      const cid = sources.cid.value;
      const properties = sources.properties.value;
      const synonyms = sources.synonyms.value ?? [];
      const lookupTerm = english?.cas ?? english?.name ?? term;
      const cas = isCAS(lookupTerm) ? lookupTerm : (osha?.cas ?? synonyms.find((name) => isCAS(name)));
      const imageUrls = [
      ...(cas === undefined ? [] : [nistStructureImageUrl(cas)]),
      ...(cid === undefined ? [] : [pubchemStructureImageUrl(cid)]),
      ];

      return {
      term,
      osha,
      cid,
      nistUrl: cas === undefined ? undefined : nistWebbookUrl(cas),
      wikipediaUrl: wikipediaUrl(properties?.title ?? osha?.name ?? english?.name ?? term),
      pubchemUrl: cid === undefined ? undefined : pubchemCompoundUrl(cid),
      properties,
      synonyms,
      description: sources.description.value,
      ghs: sources.ghs.value,
      solubility: sources.solubility.value,
      cas,
      imageUrls,
      };
      }