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.