Adding path.existsSync (with tests.)
This commit is contained in:
parent
73f207fe59
commit
b05daaaf69
@ -79,3 +79,12 @@ exports.exists = function (path, callback) {
|
|||||||
if (callback) callback(err ? false : true);
|
if (callback) callback(err ? false : true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.existsSync = function (path) {
|
||||||
|
try {
|
||||||
|
process.binding('fs').stat(path)
|
||||||
|
return true;
|
||||||
|
} catch(e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -12,6 +12,8 @@ assert.equal(path.dirname("/a"), "/");
|
|||||||
assert.equal(path.dirname("/"), "/");
|
assert.equal(path.dirname("/"), "/");
|
||||||
path.exists(f, function (y) { assert.equal(y, true) });
|
path.exists(f, function (y) { assert.equal(y, true) });
|
||||||
|
|
||||||
|
assert.equal(path.existsSync(f), true);
|
||||||
|
|
||||||
assert.equal(path.extname(""), "");
|
assert.equal(path.extname(""), "");
|
||||||
assert.equal(path.extname("/path/to/file"), "");
|
assert.equal(path.extname("/path/to/file"), "");
|
||||||
assert.equal(path.extname("/path/to/file.ext"), ".ext");
|
assert.equal(path.extname("/path/to/file.ext"), ".ext");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user