toSuperscript method

String toSuperscript()

Converts an integer to its superscript Unicode string (e.g., 12 → ¹²).

Implementation

String toSuperscript() {
  const superscripts = {
    '0': '⁰',
    '1': '¹',
    '2': '²',
    '3': '³',
    '4': '⁴',
    '5': '⁵',
    '6': '⁶',
    '7': '⁷',
    '8': '⁸',
    '9': '⁹',
    '-': '⁻',
  };
  return toString().split('').map((c) => superscripts[c] ?? '').join();
}