Skip to content

Commit

Permalink
Merge pull request #72 from aleksasiriski/as/fix/diacritics-map
Browse files Browse the repository at this point in the history
fix(utils): init diacritics map once
  • Loading branch information
aleksasiriski authored Dec 18, 2024
2 parents 1ba4889 + 921f83f commit f2f944a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/lib/utils/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ export function capitalizeString(value: string): string {
}

export function removeDiacritics(input: string): string {
const diacriticsMap = new Map([
['č', 'c'],
['Č', 'C'],
['ć', 'c'],
['Ć', 'C'],
['dž', 'dz'],
['DŽ', 'Dz'],
['đ', 'dj'],
['Đ', 'Dj'],
['š', 's'],
['Š', 'S'],
['ž', 'z'],
['Ž', 'Z']
]);

return input
.split('')
.split('') // Splits string into characters
.map((char) => diacriticsMap.get(char) ?? char)
.join('');
}

const diacriticsMap = new Map([
['č', 'c'],
['Č', 'C'],
['ć', 'c'],
['Ć', 'C'],
['dž', 'dz'],
['DŽ', 'Dz'],
['đ', 'dj'],
['Đ', 'Dj'],
['š', 's'],
['Š', 'S'],
['ž', 'z'],
['Ž', 'Z']
]);

0 comments on commit f2f944a

Please sign in to comment.