« get me outta code hell

use better package for natural sorting - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-07-17 19:02:18 -0300
committerFlorrie <towerofnix@gmail.com>2020-07-17 19:02:18 -0300
commit602426894d04d4a1d6878a585b08eb6d45662118 (patch)
tree57a9e26e775133d5974293707b16cad77c24c7e3
parent4b171a6a280b7f9927e95a72470daed551aa6e33 (diff)
use better package for natural sorting
-rw-r--r--crawlers.js10
-rw-r--r--package-lock.json10
-rw-r--r--package.json2
-rw-r--r--todo.txt1
4 files changed, 9 insertions, 14 deletions
diff --git a/crawlers.js b/crawlers.js
index e39dfa1..3f6e391 100644
--- a/crawlers.js
+++ b/crawlers.js
@@ -1,11 +1,11 @@
 const fs = require('fs')
 const path = require('path')
-const naturalSort = require('node-natural-sort')
 const expandHomeDir = require('expand-home-dir')
 const fetch = require('node-fetch')
 const url = require('url')
 const { downloadPlaylistFromOptionValue, promisifyProcess } = require('./general-util')
 const { spawn } = require('child_process')
+const { orderBy } = require('natural-orderby')
 
 const { promisify } = require('util')
 const readDir = promisify(fs.readdir)
@@ -20,12 +20,6 @@ const stat = promisify(fs.stat)
 //   getAllCrawlersForArg.
 const allCrawlers = {}
 
-function sortIgnoreCase(sortFunction) {
-  return function(a, b) {
-    return sortFunction(a.toLowerCase(), b.toLowerCase())
-  }
-}
-
 /* TODO: Removed cheerio, so crawl-http no longer works.
 function crawlHTTP(absURL, opts = {}, internals = {}) {
   // Recursively crawls a given URL, following every link to a deeper path and
@@ -254,7 +248,7 @@ function crawlLocal(dirPath, extensions = [
   }
 
   return readDir(dirPath).then(items => {
-    items.sort(sortIgnoreCase(naturalSort()))
+    items = orderBy(items)
 
     return Promise.all(items.map(item => {
       const itemPath = path.join(dirPath, item)
diff --git a/package-lock.json b/package-lock.json
index d1887d9..ae9a42f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -63,16 +63,16 @@
       "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz",
       "integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA=="
     },
+    "natural-orderby": {
+      "version": "2.0.3",
+      "resolved": "https://registry.npmjs.org/natural-orderby/-/natural-orderby-2.0.3.tgz",
+      "integrity": "sha512-p7KTHxU0CUrcOXe62Zfrb5Z13nLvPhSWR/so3kFulUQU0sgUll2Z0LwpsLN351eOOD+hRGu/F1g+6xDfPeD++Q=="
+    },
     "node-fetch": {
       "version": "2.6.0",
       "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
       "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
     },
-    "node-natural-sort": {
-      "version": "0.8.7",
-      "resolved": "https://registry.npmjs.org/node-natural-sort/-/node-natural-sort-0.8.7.tgz",
-      "integrity": "sha512-rMaLlHV5BlnRhIl6jUfgqdLY5U0NJkIxUdOsmpz3Txwh7js4+GwTiomhO8W4rp3SvX1zZ56mx13zfEWESr+qqA=="
-    },
     "open": {
       "version": "7.0.4",
       "resolved": "https://registry.npmjs.org/open/-/open-7.0.4.tgz",
diff --git a/package.json b/package.json
index 4ccec3d..1cbcb9c 100644
--- a/package.json
+++ b/package.json
@@ -12,8 +12,8 @@
     "command-exists": "^1.2.9",
     "expand-home-dir": "0.0.3",
     "mkdirp": "^0.5.5",
+    "natural-orderby": "^2.0.3",
     "node-fetch": "^2.6.0",
-    "node-natural-sort": "^0.8.7",
     "open": "^7.0.4",
     "sanitize-filename": "^1.6.3",
     "shortid": "^2.2.15",
diff --git a/todo.txt b/todo.txt
index 98a57a8..c58c1cb 100644
--- a/todo.txt
+++ b/todo.txt
@@ -529,6 +529,7 @@ TODO: A "before selected item" option for in the queue menu!
 
 TODO: The sorting for library3/C418 seems to be weird???? Could be pointing to
       some bug!
+      (Done! Using a better package for sorting now.)
 
 TODO: Selecting a group from the path listing at the bottom of listings should
       make it so the child of that group matching with the path is selected.