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

    Function superscriptGlyph

    • Normalizes Unicode superscript digits already present in str to their literal glyph spelling, mapping each SUPERSCRIPTS value to its SUPERSCRIPT_GLYPHS counterpart. Because both maps resolve the digit keys to identical code points, a string that already contains superscript characters is returned unchanged — this is a normalization pass, not a converter. It does NOT turn ASCII digits into superscripts; use superscript for that.

      Parameters

      • str: string

        The string whose Unicode superscript digits to normalize

      Returns string

      The string with superscript digits in glyph form (ASCII digits untouched)

      superscriptGlyph("x²") // Returns "x²"
      superscriptGlyph("x2") // Returns "x2" (ASCII digits are not converted)
      export const superscriptGlyph = (str: string) => {
      for (const key in SUPERSCRIPT_GLYPHS) {
      str = str.replace(new RegExp(SUPERSCRIPTS[key], 'g'), SUPERSCRIPT_GLYPHS[key]);
      }
      return str;
      };