stringCodePoints
Reports usage of charCodeAt and fromCharCode instead of their codePoint equivalents.
✅ This rule is included in the ts logical presets.
JavaScript’s original charCodeAt and String.fromCharCode methods only properly handle characters in the Basic Multilingual Plane (BMP), which includes code points from U+0000 to U+FFFF.
Characters outside this range, such as many emoji and less common scripts, require two UTF-16 code units (a surrogate pair) and are not handled correctly by these methods.
The modern codePointAt and String.fromCodePoint methods correctly handle all Unicode code points, including those that require surrogate pairs.
This rule reports using charCodeAt or fromCharCode instead of codePointAt or fromCodePoint.
Examples
Section titled “Examples”const code = text.charCodeAt(0);const char = String.fromCharCode(128512);const code = text.codePointAt(0);const char = String.fromCodePoint(128512);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you’re intentionally working with UTF-16 code units or need to support very old JavaScript environments that don’t have codePointAt and fromCodePoint, you may need to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/prefer-code-point - Oxlint:
unicorn/prefer-code-point