Convert accented text to ASCII characters?

I would like to convert accented letters and various encoding in ASCII plain English one in Javascript and wonder, what are the possible options. I need to:

éclair ~becomes~ eclair bär ~becomes~ bar  ~becomes~ privet こんにちは ~becomes~ konnichiva 

As you can see, the idea is that any language is converted to an ASCII equivalent of the English language. áčçèñtèd Letters converted to ethers equivalents, in Cyrillic letters or Japanese character set are converted to their equivalent transliterated.

Does anyone know how to do this in Javascript?

+6
source share
3 answers

Node There are several modules that perform similar functions, but it is much lighter than the node -iconv, and, in particular, are in all the JS and do not require compiling any C or C ++:

  • unidecode-node , it seems, does basically what you asked for:

     $ npm install unidecode ... unidecode@0.1.3 node_modules/unidecode $ node > var unidecode = require('unidecode'); undefined > unidecode('éclair') 'eclair' > unidecode('bär') 'bar' > unidecode('') 'priviet' > unidecode('こんにちは') 'konnitiha' は') $ npm install unidecode ... unidecode@0.1.3 node_modules/unidecode $ node > var unidecode = require('unidecode'); undefined > unidecode('éclair') 'eclair' > unidecode('bär') 'bar' > unidecode('') 'priviet' > unidecode('こんにちは') 'konnitiha' 
  • node-transliterator even lighter weight, but behaves even further from what you asked for:

     $ npm install transliterator ... transliterator@0.1.0 node_modules/transliterator $ node > var transliterator = require('transliterator'); undefined > transliterator('éclair') 'eclair' > transliterator('bär') 'baer' > transliterator('') '' > transliterator('こんにちは') '' '); $ npm install transliterator ... transliterator@0.1.0 node_modules/transliterator $ node > var transliterator = require('transliterator'); undefined > transliterator('éclair') 'eclair' > transliterator('bär') 'baer' > transliterator('') '' > transliterator('こんにちは') '' は') $ npm install transliterator ... transliterator@0.1.0 node_modules/transliterator $ node > var transliterator = require('transliterator'); undefined > transliterator('éclair') 'eclair' > transliterator('bär') 'baer' > transliterator('') '' > transliterator('こんにちは') '' 
  • node-urlify a little closer, but further away from what you asked for:

     $ npm install urlify ... urlify@0.3.5 node_modules/urlify $ node > var urlify = require('urlify').create({ spaces: ' ' }); undefined > urlify('éclair') 'eclair' > urlify('bär') 'bar' > urlify('') 'privet' > urlify('こんにちは') '_____' は') $ npm install urlify ... urlify@0.3.5 node_modules/urlify $ node > var urlify = require('urlify').create({ spaces: ' ' }); undefined > urlify('éclair') 'eclair' > urlify('bär') 'bar' > urlify('') 'privet' > urlify('こんにちは') '_____' 
  • Finally, Limax More heavyweight when I did npm install limax , he published numerous warnings C compiler, but it is still simple to operate and is closest to what you asked for:

     $ npm install limax ... limax@0.0.2 node_modules/limax ├── speakingurl@0.9.1 ├── pinyin2@2.0.8 ├── hepburn@0.5.2 ( bulk-replace@0.0.1 ) └── cld@0.0.6 $ node > var slug = require('limax') undefined > slug('éclair') 'eclair' > slug('bär') 'baer' > slug('') 'privet' > slug('こんにちは') 'konnichiha' は') $ npm install limax ... limax@0.0.2 node_modules/limax ├── speakingurl@0.9.1 ├── pinyin2@2.0.8 ├── hepburn@0.5.2 ( bulk-replace@0.0.1 ) └── cld@0.0.6 $ node > var slug = require('limax') undefined > slug('éclair') 'eclair' > slug('bär') 'baer' > slug('') 'privet' > slug('こんにちは') 'konnichiha' 
+24
source

Checkout node-the iconv .

Similar to the equivalent node php iconv.

+2
source

The author here. You can try the transliteration module. It can be run both in the browser and in node.js and without dependencies

0
source

All Articles