Skip to content

Instantly share code, notes, and snippets.

@ahultgren
ahultgren / undiacritics.js
Last active November 20, 2019 13:35
A little helper to remove so called diacritics from latin characters (eg convert international characters to url-friendly ones). Please tell me if you find some missing characters or a way to make this more efficient.
"use strict";
var accents = 'àáäâæåèéëêęìíïîòóöôøœōõùúüûūýçñ',
normals = 'aaaaaaeeeeeiiiioooooooouuuuuycn',
diacriticsRegexp = new RegExp('[' + accents + ']', 'ig');
module.exports = exports = function undiacritics (string) {
return string.replace(diacriticsRegexp, function(s){
return normals[accents.indexOf(s)];
});