Deviopath › Node.js

File Extension

Easy · Paths

Node's path.extname(p) returns the extension of the last part of a path: from the last . to the end, including the dot.

Write a function extname(p) that matches it for POSIX paths (with /):

- "a.tar.gz" → ".gz"

- no dot in the last part → ""

- a dot at the very start of the name does not count, so ".bashrc" → ""

- a name ending with a dot: "file." → "."

- dots in folder names do not count: "dir.v2/file" → ""

The path will not end with / and will not be "..".

Next: Bearer Token