I have a search string and a source string. I want to test if the search string is included in the source string.
Search | Source | |
---|---|---|
C | Сon | |
str.codePointAt(0) |
67 | 1057 |
You can see that the source string’s first character looks like a capital letter “C”, but is UTF-16 number 1057 making it not the same as typing “C” on your keyboard which is UTF-16 number 67.
These two encodings of a capital letter “C” are close enough that they should match, but how do I perform the test?
source.includes(search)
returns false because the source doesn’t contain “C” (#67).
I have heard this is called a homoglyph. How do I perform the test without needing a big map of character equivalents? Is there a built-in JS function?