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.
String.codePointAt(pos: number): number |undefined
Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
value of the UTF-16 encoded code point starting at the string element at position pos in
the String resulting from converting this object to a String.
If there is no element at that position, the result is undefined.
If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
codePointAt(0);
const
const char:string
char =
var String:StringConstructor
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
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.