Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Returns alphabetically sorted paths #4

Merged
merged 5 commits into from Apr 9, 2014
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions spec/fixtures/Sample.markdown
@@ -0,0 +1,3 @@
# Sample

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
3 changes: 3 additions & 0 deletions spec/fixtures/Xample.md
@@ -0,0 +1,3 @@
# Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
16 changes: 16 additions & 0 deletions spec/fs-plus-spec.coffee
Expand Up @@ -150,6 +150,22 @@ describe "fs", ->
expect(paths).toContain path.join(fixturesDir, 'coffee.coffee')
expect(listedPath).toMatch /(css|coffee)$/ for listedPath in paths

it "returns alphabetically sorted paths (lowercase first)", ->
paths = fs.listSync(fixturesDir)
sortedPaths = [
path.join(fixturesDir, 'binary-file.png')
path.join(fixturesDir, 'coffee.coffee')
path.join(fixturesDir, 'css.css')
path.join(fixturesDir, 'link-to-sample.js')
path.join(fixturesDir, 'sample.js')
path.join(fixturesDir, 'Sample.markdown')
path.join(fixturesDir, 'sample.txt')
path.join(fixturesDir, 'test.cson')
path.join(fixturesDir, 'test.json')
path.join(fixturesDir, 'Xample.md')
]
expect(sortedPaths).toEqual paths

describe ".list(path, [extensions,] callback)", ->
paths = null

Expand Down
2 changes: 1 addition & 1 deletion src/fs-plus.coffee
Expand Up @@ -131,7 +131,7 @@ fsPlus =
paths = fs.readdirSync(rootPath)
paths = fsPlus.filterExtensions(paths, extensions) if extensions
paths = paths.map (childPath) -> path.join(rootPath, childPath)
paths
paths.sort (a, b) -> a.toLowerCase().localeCompare(b.toLowerCase())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, maybe this should be done before the paths.map call since the strings will be shorter then and probably quicker to sort.


# Public: Asynchronously lists the files and directories in the given path.
# The listing is not recursive.
Expand Down