« 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:04:32 -0300
commitba828b4f12779c1ce356ea2c0d99bcb891a09aa0 (patch)
tree333ac430bdad3d086f488832033f7c73fb6b9da6
parent8927fb3f3ef9a3d641cf607a756b8815f06c57e2 (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 a4ec0d1..592e796 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -55,16 +55,16 @@
         "minimist": "^1.2.5"
       }
     },
+    "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.3",
       "resolved": "https://registry.npmjs.org/open/-/open-7.0.3.tgz",
diff --git a/package.json b/package.json
index 7e33ce0..421b0a4 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.3",
     "sanitize-filename": "^1.6.3",
     "tempy": "^0.2.1",
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.