The string whose Unicode subscript digits to normalize
The string with subscript digits in glyph form (ASCII digits untouched)
subscriptGlyph("H₂O") // Returns "H₂O"
subscriptGlyph("H2O") // Returns "H2O" (ASCII digits are not converted)
export const subscriptGlyph = (str: string) => {
for (const key in SUBSCRIPT_GLYPHS) {
str = str.replace(new RegExp(SUBSCRIPTS[key], 'g'), SUBSCRIPT_GLYPHS[key]);
}
return str;
};
Normalizes Unicode subscript digits already present in
strto their literal glyph spelling, mapping each SUBSCRIPTS value to its SUBSCRIPT_GLYPHS counterpart. Because both maps resolve the digit keys to identical code points, a string that already contains subscript characters is returned unchanged — this is a normalization pass, not a converter. It does NOT turn ASCII digits into subscripts; use subscript for that.