Skip to content

Commit

Permalink
Implement new logic for accent conversion in search field (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejimsan authored Aug 24, 2024
1 parent 8b391aa commit e16b390
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/fragmentarium/domain/normalizeAccents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ test.each([
['PÈL', 'PEL₃'],
['LÚ', 'LU₂'],
['ÀMA', 'AMA₃'],
['ÀM]A', 'AM]A₃'],
['ÀM[A', 'AM[A₃'],
['ÀMA.KÚR', 'AMA₃.KUR₂'],
['LÌ gí-la-ka₃', 'LI₃ gi₂-la-ka₃'],
])('%s', (character, replacement) => {
Expand Down
9 changes: 7 additions & 2 deletions src/fragmentarium/domain/normalizeAccents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const specialTransliterationCharactersAsString = escapeRegExp(
specialTransliterationCharacters
)

const spaceCharacters = '[^\\{\\}\\-\\.:,\\+\\s\\n]'

const accentExpression = new RegExp(
`(${charactersWithAccentsAsString})(${specialTransliterationCharactersAsString}|)\\w*`,
`(${charactersWithAccentsAsString})(${specialTransliterationCharactersAsString}|)${spaceCharacters}*`,
'g'
)

Expand All @@ -25,6 +27,9 @@ export default function normalizeAccents(userInput: string): string {
.split('')
.map((character) => charactersWithAccents[character]?.letter ?? character)

return characterWithoutAccent.concat(subindex).join('')
// Check if the characterWithoutAccent contains an index
const index = subindex.length > 0 ? subindex.join('') : ''

return characterWithoutAccent.concat(index).join('')
})
}

0 comments on commit e16b390

Please sign in to comment.