Created
January 13, 2017 21:22
-
-
Save cjroth/0acdeaa70a465e1a0a33cef97c9dea6f to your computer and use it in GitHub Desktop.
Experimenting with Javascript (ES6) unicode emojis + regenerate + punycode to fix problems with unicode surrogate pairs. Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://mathiasbynens.be/notes/javascript-unicode | |
const punycode = require('punycode') | |
const regenerate = require('regenerate') | |
let str1 = '☕️' | |
let str2 = '💩' | |
let regex = regenerate(str1).toString() | |
console.log('regex', regex, new RegExp(regex).test(str1)) | |
console.log('str1 length', str1.length) | |
console.log('str2 length', str2.length) | |
console.log('str1 decoded', punycode.ucs2.decode(str1)) | |
console.log('str2 decoded', punycode.ucs2.decode(str2)) | |
console.log('str1 unicode', punycode.toUnicode(str1)) | |
console.log('str2 unicode', punycode.toUnicode(str2)) | |
console.log('str1 charCodeAt(0)', str1.charCodeAt(0), str1.charCodeAt(1)) | |
console.log('str2 charCodeAt(0)', str2.charCodeAt(0), str2.charCodeAt(2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment