Skip to content

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.

const code = text.charCodeAt(0);
const char = String.fromCharCode(128512);

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.