1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-17 04:30:31 +09:00

fix: normalize diacritics

This commit is contained in:
uetchy 2020-02-11 17:57:10 +09:00
parent 73f39dd615
commit b953d4a07a
2 changed files with 8 additions and 2 deletions

View File

@ -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<string[]> {
[] as string[],
),
),
).filter((word) => !/[\s-]/.exec(word));
)
.filter((word) => !/[\s-]/.exec(word))
.map((word) => sanitize(word));
return synonyms;
} catch (err) {
return [];

View File

@ -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 {