Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Idea: Revised library sorting
#2
Hi,

Nice idea :-)

Below is the sort routine for upcoming 4.3 release. It uses Intl.Collator() and collator.compare(a, b) instead of localeCompare() which is super slow. Its in a try/catch block to cover Browsers/Javascript that may not support collator, and its case insensitive (sensitivity: 'base').

Give it a try. It should be fast :-)

Code:
        // sort the lists
        allGenres.sort();
        // sort using natural ordering
        try {
            var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
            allArtists.sort(function(a, b) {
                a = removeArticles(a);
                b = removeArticles(b);
                return collator.compare(a, b);
            });
            allAlbumsTmp.sort(function(a, b) {
                a = removeArticles(a['album']);
                b = removeArticles(b['album']);
                return collator.compare(a, b);
            });
        }            
        // fallback to default ordering
        catch (e) {
            allArtists.sort(function(a, b) {
                a = removeArticles(a.toLowerCase());
                b = removeArticles(b.toLowerCase());
                return a > b ? 1 : (a < b ? -1 : 0);
            });
            allAlbumsTmp.sort(function(a, b) {
                a = removeArticles(a['album'].toLowerCase());
                b = removeArticles(b['album'].toLowerCase());
                return a > b ? 1 : (a < b ? -1 : 0);
            });
        }
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Messages In This Thread
Revised library sorting - by scblock - 08-20-2018, 03:04 PM
RE: Revised library sorting - by Tim Curtis - 08-20-2018, 03:39 PM
RE: Revised library sorting - by scblock - 08-20-2018, 04:47 PM
RE: Revised library sorting - by scblock - 08-20-2018, 08:13 PM
RE: Revised library sorting - by Tim Curtis - 08-20-2018, 09:12 PM

Forum Jump: