path.extname(path)
path.extname() 方法返回 path 的扩展名,从最后一个 .(点)字符开始,到 path 最后一部分的字符串末尾。如果 path 的最后一部分中没有 .,或者除了 path 的基本名称(见 path.basename())的第一个字符外没有其他 . 字符,则返回空字符串。
【The path.extname() method returns the extension of the path, from the last
occurrence of the . (period) character to end of string in the last portion of
the path. If there is no . in the last portion of the path, or if
there are no . characters other than the first character of
the basename of path (see path.basename()) , an empty string is returned.】
path.extname('index.html');
// Returns: '.html'
path.extname('index.coffee.md');
// Returns: '.md'
path.extname('index.');
// Returns: '.'
path.extname('index');
// Returns: ''
path.extname('.index');
// Returns: ''
path.extname('.index.md');
// Returns: '.md' 如果 path 不是字符串,则会抛出 TypeError。
【A TypeError is thrown if path is not a string.】