From 4003d2d7c630a1829846e3f2711017965ab05098 Mon Sep 17 00:00:00 2001 From: Ronan Amicel Date: Wed, 17 Aug 2022 18:35:50 +0200 Subject: [PATCH] Use lodash to remove accents and ther diacritics https://lodash.com/docs/4.17.15#deburr --- app/client/lib/ACIndex.ts | 10 ++++++---- app/common/gutil.ts | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/client/lib/ACIndex.ts b/app/client/lib/ACIndex.ts index 9a103d98..e305fcff 100644 --- a/app/client/lib/ACIndex.ts +++ b/app/client/lib/ACIndex.ts @@ -7,9 +7,10 @@ * "lush" would only match the "L" in "Lavender". */ -import {localeCompare, nativeCompare, removeDiacritics, sortedIndex} from 'app/common/gutil'; +import {localeCompare, nativeCompare, sortedIndex} from 'app/common/gutil'; import {DomContents} from 'grainjs'; import escapeRegExp = require("lodash/escapeRegExp"); +import deburr = require("lodash/deburr"); export interface ACItem { // This should be a trimmed lowercase version of the item's text. It may be an accessor. @@ -17,10 +18,11 @@ export interface ACItem { cleanText: string; } -// Returns a normalized, trimmed, lowercase version of a string, so that autocomplete is case- -// and accent-insensitive. +// Returns a trimmed, lowercase version of a string, +// from which accents and other diacritics have been removed, +// so that autocomplete is case- and accent-insensitive. export function cleanText(text: string): string { - return removeDiacritics(text).trim().toLowerCase(); + return deburr(text).trim().toLowerCase(); } // Regexp used to split text into words; includes nearly all punctuation. This means that diff --git a/app/common/gutil.ts b/app/common/gutil.ts index 998ea012..b3c37676 100644 --- a/app/common/gutil.ts +++ b/app/common/gutil.ts @@ -55,11 +55,6 @@ export function capitalizeFirstWord(str: string): string { return str.replace(/\b[a-z]/i, c => c.toUpperCase()); } -// Remove diacritics (accents and other signs). -export function removeDiacritics(text: string): string { - return text.normalize("NFKD").replace(/[\u0300-\u036f]/g, "") -} - // Returns whether the string n represents a valid number. // http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric export function isNumber(n: string): boolean {