krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.1k stars 766 forks source link

Ignore special character #246

Closed MenesesEvandro closed 4 years ago

MenesesEvandro commented 6 years ago

Would be nice an option to ignore special character similar to case sensitive option.

"ç" would be replaced by "c", "é" by "e" and so on...

omarciovsena commented 6 years ago

@MenesesEvandro I solved the problem like this:

const list = suggestions.map(suggestion => ({
   value: suggestion.value,
   noSpecialCharacters: stripDiacritics(suggestion.value)
}))

let opts = {
   caseSensitive: false,
   shouldSort: true,
   threshold: accuracy,
   keys: ['value', 'noSpecialCharacters']
}
export const stripDiacritics = str => {
  return (
    str && str.normalize && str.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
  )
}