diff --git a/src/path.ts b/src/path.ts index f295bd5..0eab07a 100644 --- a/src/path.ts +++ b/src/path.ts @@ -182,9 +182,10 @@ export const toNamespacedPath: typeof path.toNamespacedPath = function (p) { } // extname +const _EXTNAME_RE = /(? 1 ? `.${segments.pop()}` : '' + const match = _EXTNAME_RE.exec(normalizeWindowsPath(p)) + return (match && match[0]) || '' } // relative diff --git a/test/index.spec.ts b/test/index.spec.ts index e3e43e5..05098e6 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -61,6 +61,14 @@ runTest('extname', extname, { '/temp/myfile.html': '.html', './myfile.html': '.html', + '.foo': '', + '..foo': '.foo', + 'foo.123': '.123', + '..': '', + '.': '', + './': '', + // '...': '.', // TODO: Edge case behavior of Node? + // Windows 'C:\\temp\\myfile.html': '.html', '\\temp\\myfile.html': '.html',