Transliteration with Typeahead.js

How to deal with special characters when using typeahead.js

Often in real world web applications we have to deal with words or characters that fall outside of the standard latin-based keyboard character set.

For example lets say we wanted our users to search through a list of torrent clients, a list wouldn’t be complete without including µTorrent, but here we have two problems.

  1. Very few people will know how to type µ or have the inclination to look it up.
  2. If they just type torrent, we presume that most torrent clients will have torrent in their name, so this isn’t going to narrow down the search too much.

The solution is to use tokens in our datum, so where as before we might have just had;

{"value": "µTorrent"}

We would now have;

{
  "value" : "µTorrent",
  "tokens": ["µTorrent", "uTorrent"]
}

Which means if our user types in ‘u’, typeahead.js will know to return µTorrent amongst the results.

I hope this post has helped someone, did you know I have written a book on Typeahead?


Recent posts View all

Web Dev

Updating payment method email addresses in Stripe

You can't update the email address associated with a payment method in Stripe via their dashboard, you need to use the Stripe CLI

Ruby

Irreversible Rails Migrations

What are irreversible migrations and how might we use them to our advantage?