Select2 custom match but hold stripDiacritics

I know in previous versions of select2, stripDiacritics was exported, so it was available outside the standard socket. In current version 4.0.1, it seems impossible to write a custom match and use select2 stripDiacritics since it is not exported to $.fn.select2.defaults

What is the best way I can pull out the original stripDiacritics for me to write custom matches?

I am trying to write a match that matches both the option text and the data attribute. I am trying to avoid correcting the source of select2, I think it will be a nightmare if I follow this path.

Update

I highlighted a relevant question and posted additional information about the code I'm working with, as suggested in the comments:

I do not ask anyone to write new matches (based on $.fn.select2.defaults.defaults.matcher ) for me, I just ask for the best way to pull out the original stripDiacritics , which is private, so that I can use it.

I could just copy the function (and its dependencies: the DIACRITICS object) into my code, but this is a hole that I am trying to avoid.

+6
source share
1 answer

Since stripDiacritics is a private method, you cannot do it (other than parsing the source code).

However, if you are only happy with copying the stripDiacritics method from the select2 database and relying on select2 to provide the DIACRITICS dependency, you can always just require the 'select2/diacritics' module:

 $.fn.select2.amd.require(['select2/diacritics'], function (DIACRITICS) { // stripDiacritics code copied from select2 function stripDiacritics (text) { // Used 'uni range + named function' from http://jsperf.com/diacritics/18 function match(a) { return DIACRITICS[a] || a; } return text.replace(/[^\u0000-\u007E]/g, match); } $(".awesome").select2({ // declare your matcher code here with access to stripDiacritics }) }); 
+4
source

All Articles