0

So i saw this thread here which talks about converting non-ASCII characters to their closest ASCII equivalent. The given solution is:

var str = "Rånades på Skyttis i Ö-vik";
var combining = /[\u0300-\u036F]/g; 

console.log(str.normalize('NFKD').replace(combining, ''));

Now my issue is similar but not the same. I am looking at replacing special characters like Left Double Quotation Mark which is hex “ or entity “. The problem is that i can't use the hex code, html entity or any form of encoding. I need to replace special characters like this with their closest standard UTF-8 Character like a normal Double Quotation Mark. The reason being is that the final product is going into an email subject line and no encoding can be present there on some clients, so i'm looking for a JS solution.

It can't be a straight mapping either because it might not be a quotation mark, it could be any kind of symbol. Like an mdash which needs to become a normal dash.

JordanGS
  • 3,966
  • 5
  • 16
  • 21
  • why do you assume there is an appropriate ascii character? Without a mapping, I think this is going to be essentially impossible. – Scott Sauyet Mar 22 '19 at 00:39
  • @Scott Sauyet If i do a mapping there is always the potential to miss something. I assumed, maybe there is a js library that already has a mapping out there which covers 99% of characters. – JordanGS Mar 22 '19 at 00:42
  • Unicode is *large*. What would be your candidate ASCII character for [:pile-of-poo:](https://unicode.org/emoji/charts/full-emoji-list.html#1f4a9)? – Scott Sauyet Mar 22 '19 at 00:49
  • @Scott Sauyet no emoji's, just stuff that's usually used in essays, stories, news articles, etc. – JordanGS Mar 22 '19 at 03:54
  • But the point is that as far as I know there is no definitive list of that "stuff". I think you probably need to start collecting a list of the ones that matter to you. Almost certainly others have done so, and you might be able to find such a list online. But I've never seen one. – Scott Sauyet Mar 22 '19 at 16:14

0 Answers0