Skip to content

Commit

Permalink
feat(organisations): ignore special chars in search filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Dec 14, 2023
1 parent afc7359 commit ed0285f
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export class OrganisationsComponent {
private filterOrganisations(organisations: Organization[], filterBy: string) {
if (!filterBy) return organisations
const filterRegex = new RegExp(
this.normalizeString(filterBy) //ignore accents
.replace(/[()[\]{}*+?^$|#.,/\\]/g, '\\$&') //escape special characters
this.normalizeString(filterBy) //ignore accents and case
.replace(/[^a-z0-9\s]/g, '') //ignore special characters
.replace(/\s(?=.)/g, '.*') //replace whitespaces by "AND" separator
.replace(/\s/g, ''), //remove potential whitespaces left
'i'
Expand All @@ -99,7 +99,10 @@ export class OrganisationsComponent {
}

private normalizeString(str: string) {
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
return str
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
}

private sortOrganisations(
Expand Down

0 comments on commit ed0285f

Please sign in to comment.