« get me outta code hell

Natural sort in local crawl - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-06-04 16:36:55 -0300
committerliam4 <towerofnix@gmail.com>2017-06-04 16:36:55 -0300
commit40442cd9088b9680d5d62c185c7a5f5af2db2886 (patch)
treeae3a57f74dc141beaa1b8c956928dbdcd811b0fd /src
parenta067d49f496d5205b02ba1358b124db5d10b3352 (diff)
Natural sort in local crawl
Diffstat (limited to 'src')
-rwxr-xr-xsrc/crawl-local.js7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/crawl-local.js b/src/crawl-local.js
index cd213e0..4c510a1 100755
--- a/src/crawl-local.js
+++ b/src/crawl-local.js
@@ -4,6 +4,7 @@
 
 const fs = require('fs')
 const path = require('path')
+const naturalSort = require('node-natural-sort')
 
 const { promisify } = require('util')
 const readDir = promisify(fs.readdir)
@@ -11,11 +12,7 @@ const stat = promisify(fs.stat)
 
 function crawl(dirPath) {
   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
-    })
+    items.sort(naturalSort())
 
     return Promise.all(items.map(item => {
       const itemPath = path.join(dirPath, item)