Created
October 20, 2016 13:28
-
-
Save evolutionxbox/31e9dfc1128fcc9f2152c07168d56e0c to your computer and use it in GitHub Desktop.
Find Unicode Chars in String
This file contains hidden or 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
// Returns array of objects containing the character it found, and it's hexidecimal string value. | |
function findUnicodeChars(str) { | |
var arr = str.split(''); | |
return arr.filter(char => { | |
return (char.charCodeAt(0) > 255) && char; | |
}).map(char => { | |
return { | |
char: char, | |
code: char.charCodeAt(0).toString(16) | |
}; | |
}); | |
} | |
// Usage | |
findUnicodeChars('lorem ipsum'); // returns: [{char: '', code: 'f138'}] | |
findUnicodeChars('abc'); // returns: [] | |
// Shortcomings... cannot parse strings with emoji. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment