From b953d4a07abb1269dff3037502ca3937f75a4572 Mon Sep 17 00:00:00 2001 From: Yasuaki Uechi Date: Tue, 11 Feb 2020 17:57:10 +0900 Subject: [PATCH] fix: normalize diacritics --- web/src/components/Suggestion.tsx | 5 ++++- web/src/util/text.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/web/src/components/Suggestion.tsx b/web/src/components/Suggestion.tsx index da51b70..b016792 100644 --- a/web/src/components/Suggestion.tsx +++ b/web/src/components/Suggestion.tsx @@ -7,6 +7,7 @@ import {TiArrowSync} from 'react-icons/ti'; import {capitalize, stem, germanify, njoin, lower, upper} from '../util/text'; import {sampleFromArray, fillArray} from '../util/array'; import {mobile} from '../util/css'; +import {sanitize} from '../util/text'; type Modifier = (word: string) => string; @@ -141,7 +142,9 @@ async function findSynonyms(word: string): Promise { [] as string[], ), ), - ).filter((word) => !/[\s-]/.exec(word)); + ) + .filter((word) => !/[\s-]/.exec(word)) + .map((word) => sanitize(word)); return synonyms; } catch (err) { return []; diff --git a/web/src/util/text.ts b/web/src/util/text.ts index ce11c85..b965e50 100644 --- a/web/src/util/text.ts +++ b/web/src/util/text.ts @@ -4,7 +4,10 @@ export function capitalize(text: string): string { } export function sanitize(text: string): string { - return text.replace(/[\s@+!#$%^&*()[\]./<>{}]/g, ''); + return text + .replace(/[\s@+!#$%^&*()[\]./<>{}]/g, '') + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, ''); } export function upper(word: string): string {