getExtensionName
The getExtensionName() function returns the last extension of a path, with or without the leading dot.
WARNING
Works only with POSIX paths (not Windows paths).
Interactive example
Syntax
typescript
function getExtensionName<
GenericPath extends string
>(
path: GenericPath,
params?: {
withDot?: boolean;
}
): string | null;Parameters
path: The path to analyze.params: Optional behavior options.params.withDot: Whentrue, keeps the leading dot in the returned extension.
Return value
The last extension segment:
- without the dot by default (for example
txt) - with the dot when
withDotistrue(for example.txt) nullwhen no extension is found
See also
getBaseName- Returns the last segment of a pathgetParentFolderPath- Returns the parent folder
