This TypeScript code demonstrates how to work with strings and Unicode code points. Here are some key differences from the Go version:
TypeScript uses the string type for all strings, which are sequences of UTF-16 code units.
There’s no built-in rune type in TypeScript. Instead, we work with code points using methods like codePointAt and fromCodePoint.
The length property of a string in TypeScript returns the number of UTF-16 code units, which may not always equal the number of perceived characters for strings containing characters outside the Basic Multilingual Plane (BMP).
To count actual Unicode code points, we can use the spread operator to convert the string to an array of code points.
TypeScript doesn’t have a built-in way to iterate over code points directly, so we implement our own methods using codePointAt.
Instead of using single quotes for rune literals, we use codePointAt(0) to get the code point of a single-character string.
This code provides similar functionality to the Go example, allowing you to examine and work with Unicode strings in TypeScript.