prefer-code-point
UnreleasedConfiguration
Rule Details
String#codePointAt() and String.fromCodePoint() handle the full Unicode range, including characters outside the Basic Multilingual Plane that JavaScript represents with surrogate pairs. String#charCodeAt() and String.fromCharCode() only operate on individual UTF-16 code units, so they truncate emoji and other high code points.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Suggestions
The rule offers a suggestion that renames charCodeAt to codePointAt only when the result is not consumed as a number. In string hashing or digit parsing such as string.charCodeAt(index) - 48, swapping in codePointAt would change the computed value: a code point outside the BMP occupies two code units, and iterating by string.length would still visit the trailing surrogate separately. The diagnostic is still reported there, but the fix is left for manual review.
String.fromCharCode is always reported with a suggestion because the call shape does not change; callers that intentionally build strings from UTF-16 code units can disable the rule for that line.