From 3f9f999f417d16e70bb5d6aac1461babf71a22f0 Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 11 Sep 2017 22:23:06 -0300 Subject: 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!!']. --- src/crawl-local.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') 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) -- cgit 1.3.0-6-gf8a5