mProjectsCode / obsidian-media-db-plugin

A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.
GNU General Public License v3.0
255 stars 31 forks source link

unicode normalized search on steamApi #132

Closed stracaganasse closed 7 months ago

stracaganasse commented 10 months ago

Describe the bug When searching for "paquerette" there will be no result from steamApi because the data.applist.apps pulled includes the diacritic â in the app.name and the string matching only normalizes with .toLowerCase() so far.

To Reproduce Steps to reproduce the behavior:

  1. Search for "paquerette" with steamApi, obtain nothing
  2. Search for "pâquerette" with steamApi, obtain correct resultlist

Expected behavior Not common diacritics could be normalized and excluded when searching in a form akin to this:

for (const app of data.applist.apps) {
    if (app.name.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase().includes(title.toLowerCase())) {
        filteredData.push(app);
    }
    if (filteredData.length > 20) {
        break;
    }
}

Where .normalize('NFD').replace(/[\u0300-\u036f]/g, '') will decompose â to ^a and then replace all diacritics in the usual unicode range indicated by the regex /[\u0300-\u036f]/g.

Occurs on

Plugin version 0.6.0

Additional context

I did not submit a pull request because:

  1. I am not sure this is the best way to do it and don't know if it impacts performance in any way,
  2. I do not know if this is a desirable change for the author of the plugin
  3. maybe there are other instances of this search and it would be best to abstract the normalization to its own util function