Skip to content

Instantly share code, notes, and snippets.

@lionelB
Created May 1, 2013 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lionelB/5496739 to your computer and use it in GitHub Desktop.
Save lionelB/5496739 to your computer and use it in GitHub Desktop.
Strip accent (and lower case)
function strip_accent( str ) {
var acc = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿñ".split('')
, min = "aaaaaaceeeeiiiiooooouuuuyaaaaaaceeeeiiiioooooouuuuyyn".split('')
, l = acc.length
, i = 0;
for(; i < l ; i++) {
str = str.replace( new RegExp(acc[i], "g"), min[i]);
}
return str.toLowerCase();
}
@lionelB
Copy link
Author

lionelB commented May 1, 2013

Use case

I usually create a field dedicated to sorting / filtering which holds data transformed using this function.
It allow me to do any search / order / filter without worried about accented letters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment