Browse Source

Added extname function to path module that returns the extension.

v0.7.4-release
Benjamin Thomas 15 years ago
committed by Ryan Dahl
parent
commit
73266cb486
  1. 12
      doc/api.txt
  2. 5
      src/node.js

12
doc/api.txt

@ -1548,6 +1548,18 @@ node> require("path").filename("/foo/bar/baz/asdf/quux")
------------------------------------
+
+path.extname(p)+::
Return the extension of the path. Everything after the last '.', if there
is no '.' then it returns an empty string. Examples:
+
------------------------------------
node> require("path").extname("index.html")
".html"
node> require("path").extname("index")
""
------------------------------------
+
+path.exists(p, callback)+::
Test whether or not the given path exists. Then, call the +callback+ argument with either true or false. Example:
+

5
src/node.js

@ -716,6 +716,11 @@ var pathModule = createInternalModule("path", function (exports) {
return parts[parts.length-1];
};
exports.extname = function (path) {
var index = path.lastIndexOf('.');
return index < 0 ? '' : path.substring(index);
};
exports.exists = function (path, callback) {
var p = posix.stat(path);
p.addCallback(function () { callback(true); });

Loading…
Cancel
Save