Comments (7)
Hello @nikolasr200
I've run a couple of tests in order to change the function normalizeString
to:
static normalizeString(text) {
const NON_WORD_REGEX = /[\u0300-\u036f]/g;
// Normalize the text to lowercase and remove accents
let normalizedText = text
.toLowerCase()
.normalize('NFD')
.replace(NON_WORD_REGEX, '');
// Define a mapping of characters to remove accents for
const accentMappings = {
'a': ['à', 'á', 'â', 'ã', 'ä', 'å'],
'e': ['è', 'é', 'ê', 'ë','έ','ε'],
'i': ['ì', 'í', 'î', 'ï'],
'o': ['ò', 'ó', 'ô', 'õ', 'ö'],
'u': ['ù', 'ú', 'û', 'ü'],
'c': ['ç'],
'g': ['ğ'],
'n': ['ñ'],
};
// Replace accented characters with their non-accented equivalents
for (const baseChar in accentMappings) {
const accentedChars = accentMappings[baseChar].join('');
const regex = new RegExp(`[${accentedChars}]`, 'g');
normalizedText = normalizedText.replace(regex, baseChar);
}
return normalizedText; }
Another alternative would be:
`static normalizeString(text) {
//const NON_WORD_REGEX = /[^\w]/g;
//return text.normalize("NFD").replace(NON_WORD_REGEX, "");
const NON_WORD_REGEX = /[^a-z0-9\s]/g;
// Define a mapping of characters to remove accents for
const accentMappings = {
'à': 'a', 'á': 'a', 'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a',
'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e', 'έ': 'e', 'ε': 'e',
'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i',
'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', 'ö': 'o',
'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u',
'ç': 'c',
'ğ': 'g',
'ñ': 'n'
};
// Create a regex pattern to match accented characters
const accentPattern = new RegExp([${Object.keys(accentMappings).join('')}]
, 'g');
// Normalize the text to lowercase, remove accents, and non-word characters
const normalizedText = text
.toLowerCase()
.normalize('NFD')
.replace(accentPattern, char => accentMappings[char] || char)
.replace(NON_WORD_REGEX, '');
return normalizedText;
}`
Could you run some tests on top of this in order to make sure it won't break the current use cases and fulfil the requirements you mentioned? I'm also worried about performance in these scenarios.
cc: @sa-si-dev
from virtual-select.
IMHO, it would be probably a good idea to allow to pass a
searchCompareValues
function, to be able to fully customize the search. Thus one could implements fuzzy search, custom normalization, etc...
I personally will see that as a new feature (even to be able to be backwards compatible) and here just try to include new use cases without further impacts.
But feel free to propose that via PR.
from virtual-select.
I think it's more complex to handle all diacritics, and it would be better to not reinvent the wheel : for example, this package is well maintained and tested https://github.com/motss/normalize-diacritics
It's why I would prefer to be able to apply a custom normalization function
from virtual-select.
IMHO, it would be probably a good idea to allow to pass a searchCompareValues
function, to be able to fully customize the search.
Thus one could implements fuzzy search, custom normalization, etc...
from virtual-select.
Hi @nikolasr200
Did you get the chance to test the alternatives I suggested?
I would like more input before moving forward with a PR.
Cheers
from virtual-select.
Hi @gnbm, sorry i didn't have the time to do any tests so far. I believe your approach is to the right direction, and i ll try to test it asap.
from virtual-select.
I think it's more complex to handle all diacritics, and it would be better to not reinvent the wheel : for example, this package is well maintained and tested https://github.com/motss/normalize-diacritics It's why I would prefer to be able to apply a custom normalization function
Feel free to add that to the library via PR so that we can avoid breaking changes and @sa-si-dev might be able to review it
from virtual-select.
Related Issues (20)
- Dropbox has blurry borders in Chromium browsers HOT 2
- when using server search, disableSelectAll doesn't work HOT 6
- When using popup mode and preselected values make the focus go to the dropdown when entering the screen
- The "disabled" property doesn't account for the tabindex. HOT 7
- Inline Style Css Properties is not Showing HOT 1
- Add property in the documentation HOT 1
- deselectAllOnlyVisible feature HOT 1
- Broken display of options with icons HOT 4
- Add classes to button HOT 3
- The search input is disabled when allowNewOption is set to true and the options are empty. HOT 5
- Search Feature Unresponsive After Setting an Empty List of Options HOT 3
- Scrolling is broken when a custom onServerSearch function Is defined HOT 10
- The reset() method is triggering on change event and causing an infinite loop when used on certain contexts HOT 1
- Custom values in onServerSearch are not respected HOT 1
- Scrolling gets stuck in Safari when multiple select has options selected HOT 2
- why i get the wrong in browser console: index.vue:62 Couldn't initiate Virtual Select HOT 1
- Search and Select not working with Groups HOT 1
- Dropdown gets blank after scroll to bottom and changing browser zoom
- first option always selected even when autoSelectFirstOption set to false
- When setting maxValues, first option is always selected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from virtual-select.