Removing diacritics from a string

Options

I'm new to Xano and recently came across the issue of having to remove diacritics (accents) from a string, namely to transform a user-provided title into a slug so as to avoid presenting ASCII-encoded characters in the URL. In my (relatively limited) experience as a programmer, this usually requires some sort of library, such as Unidecode in Python.

I did not find a filter to accomplish this in Xano, so I came up with a rudimentary solution. I created a function called removeDiacritics which takes a single string input. An empty output variable is created for the end result. There is also a character_table variable which is an array containing a few hundred objects with two keys, accented and unaccented. You guessed it: I'm looping over the entire array to replace the accented characters with equivalent unaccented characters using a mapping of my own creation. This works, but seems inefficient compared to more sophisticated methods of string replacements using a set of needles/haystacks that exist in other frameworks, such as PHP's string_replace.

I'm sharing this in case someone might have a better approach, but also to propose adding a filter to Xano so this won't be necessary. My apologies if there was an existing solution which I've missed. I had previously explored alternatives with encoding/decoding the string, but I couldn't get it to work.

Comments