ChemPal Documentation - v1.6.0
    Preparing search index...
    • Classifies a single search term as a plain string, a CAS number, a SMILES string, or a chemical formula. Detection is heuristic and intended only to colorize the search box — it never changes what is searched. Phrases (anything containing whitespace) are always plain strings, since CAS/SMILES/formula tokens are contiguous.

      Ambiguous short tokens that read as valid formulas (e.g. "CCO", which is also SMILES for ethanol) are reported as "formula"; SMILES is only chosen when a SMILES-only signal is present (bonds, brackets, or aromatic lowercase atoms).

      Parameters

      • term: string

        A single search term (one leaf of the query).

      Returns SearchTermType

      The detected term type.

      detectTermType("7647-14-5");        // "cas"
      detectTermType("NaOH"); // "formula"
      detectTermType("KMnO4"); // "formula"
      detectTermType("O=C=O"); // "smiles"
      detectTermType("c1ccccc1"); // "smiles"
      detectTermType("sodium hydroxide"); // "string"
      detectTermType("acetone"); // "string"
      export function detectTermType(term: string): SearchTermType {
      const value = term.trim();
      if (value === '' || /\s/.test(value)) return 'string';
      if (isCAS(value)) return 'cas';
      if (hasSmilesSignal(value)) return 'smiles';
      if (isChemicalFormula(value)) return 'formula';
      return 'string';
      }