question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs of `charCodeAt` and `codePointAt` are flipped

See original GitHub issue

Bug 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

https://github.com/microsoft/TypeScript/blob/89d05f7131b233c4482aaba5c15ad289f26173b4/lib/lib.es2015.core.d.ts#L401-L408

https://github.com/microsoft/TypeScript/blob/89d05f7131b233c4482aaba5c15ad289f26173b4/lib/lib.es5.d.ts#L404-L408

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:open
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
Cianticcommented, Jun 15, 2022

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.

1reaction
fatcerberuscommented, Jun 15, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found