mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add fs.extension
This commit is contained in:
@@ -18,6 +18,14 @@ describe "fs", ->
|
||||
expect(fs.join('/a/b/', 'c', 'd')).toBe '/a/b/c/d'
|
||||
expect(fs.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/'
|
||||
|
||||
describe ".extension(path)", ->
|
||||
it "returns the extension of a file", ->
|
||||
expect(fs.extension("a/b/corey.txt")).toBe '.txt'
|
||||
expect(fs.extension("a/b/corey.txt.coffee")).toBe '.coffee'
|
||||
|
||||
it "returns an empty string for paths without an extension", ->
|
||||
expect(fs.extension("a/b.not-extension/a-dir")).toBe ''
|
||||
|
||||
describe ".async", ->
|
||||
directoryPath = null
|
||||
beforeEach ->
|
||||
|
||||
@@ -27,6 +27,17 @@ module.exports =
|
||||
exists: (path) ->
|
||||
$native.exists path
|
||||
|
||||
# Returns the extension of a file. The extension of a file is the
|
||||
# last dot (excluding any number of initial dots) followed by one or
|
||||
# more non-dot characters. Returns an empty string if no valid
|
||||
# extension exists.
|
||||
extension: (path) ->
|
||||
match = @base(path).match(/\.[^\.]+$/)
|
||||
if match
|
||||
match[0]
|
||||
else
|
||||
""
|
||||
|
||||
join: (paths...) ->
|
||||
return paths[0] if paths.length == 1
|
||||
[first, rest...] = paths
|
||||
|
||||
Reference in New Issue
Block a user