Skip to content

Instantly share code, notes, and snippets.

@iegik
Last active February 28, 2018 09:08
Show Gist options
  • Save iegik/1302029 to your computer and use it in GitHub Desktop.
Save iegik/1302029 to your computer and use it in GitHub Desktop.
Replace āēūīšģķļ to aeuisgkl
// shim for String.prototype.normalize https://github.com/walling/unorm
export default str => str.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, "") // remove accents
.replace(/\u0142/g, "l"); // ł is a letter in itself
/*
const normalize = import('normalize.js')
console.log(normalize('ąśćńżółźćęāēūīšģķļ'))
*/
<?php
return function normalize($str) {
$normalized = Normalizer::normalize($str, Normalizer::NFKD);
$normalized = preg_replace('/[\u0300-\u036f]/g', '', $normalized);
$normalized = preg_replace('/\u0142/g', 'l', $normalized);
return $normalized;
}
/*
normalize = include 'normalize.php'
echo normalize('ąśćńżółźćęāēūīšģķļ');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment