mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
fs.directory matches commonjs spec
This commit is contained in:
parent
28f39cbdab
commit
ee51a72721
@ -8,8 +8,8 @@ describe "fs", ->
|
||||
|
||||
describe "when called with a directory path", ->
|
||||
it "return the path it was given", ->
|
||||
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures/dir')
|
||||
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures/dir')
|
||||
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures')
|
||||
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures')
|
||||
|
||||
describe ".join(paths...)", ->
|
||||
it "concatenates the given paths with the directory seperator", ->
|
||||
|
@ -14,17 +14,14 @@ module.exports =
|
||||
# any leading directory components removed. If specified, also
|
||||
# remove a trailing extension.
|
||||
base: (path, ext) ->
|
||||
path =
|
||||
base = path.replace(/\/$/, '').split("/").pop()
|
||||
if ext then base.replace(RegEx(ext + "$"), "") else base
|
||||
|
||||
# Return the dirname of the given path. That is the path with any trailing
|
||||
# non-directory component removed.
|
||||
# Returns the path of a file's containing directory, albeit the
|
||||
# parent directory if the file is a directory. A terminal directory
|
||||
# separator is ignored.
|
||||
directory: (path) ->
|
||||
if @isDirectory(path)
|
||||
path.replace(/\/?$/, '')
|
||||
else
|
||||
path.replace(new RegExp("/#{@base(path)}$"), '')
|
||||
path.replace(new RegExp("/#{@base(path)}\/?$"), '')
|
||||
|
||||
# Returns true if the file specified by path exists
|
||||
exists: (path) ->
|
||||
|
Loading…
Reference in New Issue
Block a user