« get me outta code hell

Ignore filename case in crawl-local - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-09-11 22:23:06 -0300
committerFlorrie <towerofnix@gmail.com>2017-09-11 22:23:10 -0300
commit3f9f999f417d16e70bb5d6aac1461babf71a22f0 (patch)
treebd1a67854977c9f3c9c06c64f04f450dd5067a44
parente66b70fafc140af7abbe0ade44ed55bbd757e7d7 (diff)
Ignore filename case in crawl-local
The array ['banana', 'Rainbows!!', 'Abstract', 'kangaroo']..
..would previously be sorted as ['Abstract', 'Rainbows!!', 'banana',
'kangaroo']..
..but that was clearly wrong; it's now sorted as ['Abstract', 'banana',
'kangaroo', 'Rainbows!!'].
-rwxr-xr-xsrc/crawl-local.js8
-rw-r--r--todo.txt3
2 files changed, 10 insertions, 1 deletions
diff --git a/src/crawl-local.js b/src/crawl-local.js
index 1baebc3..91554af 100755
--- a/src/crawl-local.js
+++ b/src/crawl-local.js
@@ -11,6 +11,12 @@ const { promisify } = require('util')
 const readDir = promisify(fs.readdir)
 const stat = promisify(fs.stat)
 
+function sortIgnoreCase(sortFunction) {
+  return function(a, b) {
+    return sortFunction(a.toLowerCase(), b.toLowerCase())
+  }
+}
+
 function crawl(dirPath, extensions = [
   // This list isn't very extensive, and can be customized via the
   // --extensions (or --exts, -e) option.
@@ -18,7 +24,7 @@ function crawl(dirPath, extensions = [
   'wav', 'mp3', 'mp4', 'm4a', 'aac'
 ]) {
   return readDir(dirPath).then(items => {
-    items.sort(naturalSort())
+    items.sort(sortIgnoreCase(naturalSort()))
 
     return Promise.all(items.map(item => {
       const itemPath = path.join(dirPath, item)
diff --git a/todo.txt b/todo.txt
index 907c9e2..6395146 100644
--- a/todo.txt
+++ b/todo.txt
@@ -348,3 +348,6 @@ TODO: Rename pickers2.js to pickers.js, and get rid of the old pickers.js.
 TODO: Some way to control how verbose http-music is.. most people probably
       don't care about 'Indexing (flattening)', but it is handy for those on
       slow computers.
+
+TODO: Make the natural sort in crawl-local ignore capitalization case.
+      (Done!)