Skip to content

Instantly share code, notes, and snippets.

@myfonj
Last active June 30, 2022 08:07
Show Gist options
  • Save myfonj/d322ff603b3ac26ed2788611afdd2c15 to your computer and use it in GitHub Desktop.
Save myfonj/d322ff603b3ac26ed2788611afdd2c15 to your computer and use it in GitHub Desktop.
function stringToCodePoints (string) {
function charToCodePoint (char) {
// "brute-force"
let codePoint = 0;
while (char !== String.fromCodePoint(codePoint)) {
// will throw for codePoint exceeding legal range
++codePoint;
}
return codePoint;
};
return Array.from(string).map(charToCodePoint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment