Add fs.join

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-05 12:01:55 -08:00
parent 1c24ad0fdd
commit 5293ba7469
2 changed files with 11 additions and 0 deletions

View File

@@ -11,6 +11,12 @@ describe "fs", ->
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures/dir/')
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures/dir/')
describe ".join(paths...)", ->
it "concatenates the given paths with the directory seperator", ->
expect(fs.join('a')).toBe 'a'
expect(fs.join('a', 'b', 'c')).toBe 'a/b/c'
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 ".async", ->
describe ".listFiles(directoryPath, recursive)", ->

View File

@@ -35,6 +35,11 @@ module.exports =
exists: (path) ->
OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory path, null
join: (paths...) ->
return paths[0] if paths.length == 1
[first, rest...] = paths
first.replace(/\/?$/, "/") + @join(rest...)
# Returns true if the file specified by path exists and is a
# directory.
isDirectory: (path) ->