From 40442cd9088b9680d5d62c185c7a5f5af2db2886 Mon Sep 17 00:00:00 2001 From: liam4 Date: Sun, 4 Jun 2017 16:36:55 -0300 Subject: Natural sort in local crawl --- src/crawl-local.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') 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) -- cgit 1.3.0-6-gf8a5