« get me outta code hell

Sort local crawl - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-06-04 12:23:51 -0300
committerliam4 <towerofnix@gmail.com>2017-06-04 12:23:51 -0300
commitbb7dbb8a3fe098e13870b54cbde018d977c6d947 (patch)
tree541f0b2527fdc45e681f0625e63bc2e20eff14d0
parent9fcf30b57a7a8f0fc86f1187d2cad72e8eaaa37e (diff)
Sort local crawl
-rw-r--r--src/crawl-local.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/crawl-local.js b/src/crawl-local.js
index d9a9a70..cd213e0 100644
--- a/src/crawl-local.js
+++ b/src/crawl-local.js
@@ -10,8 +10,14 @@ const readDir = promisify(fs.readdir)
 const stat = promisify(fs.stat)
 
 function crawl(dirPath) {
-  return readDir(dirPath).then(
-    res => Promise.all(res.map(item => {
+  return readDir(dirPath).then(items => {
+    items.sort((a, b) => {
+      const aUp = a.toUpperCase()
+      const bUp = b.toUpperCase()
+      return (aUp < bUp) ? -1 : (aUp == bUp) ? 0 : 1
+    })
+
+    return Promise.all(items.map(item => {
       const itemPath = path.join(dirPath, item)
 
       return stat(itemPath).then(stats => {
@@ -25,8 +31,8 @@ function crawl(dirPath) {
           return track
         }
       })
-    })
-  ))
+    }))
+  })
 }
 
 if (process.argv.length === 2) {