From 5293ba746942ccabdff6fe61f79715b38d17cd9c Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 5 Jan 2012 12:01:55 -0800 Subject: [PATCH] Add fs.join --- spec/stdlib/fs-spec.coffee | 6 ++++++ src/stdlib/fs.coffee | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index 66ce34e1b..7c8875b30 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -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)", -> diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index 0950232e9..614da994f 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -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) ->