Docs of `charCodeAt` and `codePointAt` are flipped
See original GitHub issueBug Report
Docs of charCodeAt
and codePointAt
are flipped. Described in MDN, the codePointAt
returns Unicode code point, and charCodeAt
returns UTF16 char code, however in JSDoc string of Typescript they are flipped.
How it is
How it should be
The
codePointAt()
method returns a non-negative integer that is the Unicode code point value at the given position. Note that this function does not give the nth code point in a string, but the code point starting at the specified string index. Docs
The
charCodeAt()
method returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index. Docs
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
Difference between codePointAt and charCodeAt
The charCodeAt() method returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.
Read more >Js.String-2 | ReScript API
charCodeAt (s, n) returns the character code at position n in string s ; the result is in the range 0-65535, unlke codePointAt...
Read more >Modern ES6+ Javascript Pt. 5 - CodinGame
The charAt() method is used to return a single element String containing the code unit at index position within a particular String value....
Read more >String.prototype.codePointAt() - JavaScript - MDN Web Docs
The codePointAt() method returns a non-negative integer that is the Unicode code point value at the given position.
Read more >String (Java Platform SE 8 ) - Oracle Help Center
Returns the char value at the specified index. int, codePointAt(int index). Returns the character (Unicode code point) at the specified index.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s all quiet interesting, I will study that implementation.
Maybe the docs could mention at least that for all unicode points there exists a unicode character usually with a glyph. But for char codes that is not the case, as they are just bits.
I’m pretty sure that will 1) break apart surrogates, and 2) cause more GC pressure creating temp arrays, unless the engine is specifically optimized for that case to avoid creating the temp.
Text processing is tricky.