splitFileExtension()function
splitFileExtension(file: Nullish<string> = ""): [base: string | undefined, extension: string | undefined]
| Param | Type | |
|---|---|---|
file | Nullish<string> | The filename to split, or a nullish value (defaults to ""). Defaults to "" |
| Return | |
|---|---|
[base: string | undefined, extension: string | undefined] | A [base, extension] tuple, with undefined for either part that is absent. |
Split a filename into its base name and extension in a single pass.
- Extension with no leading dot, e.g.
"ts". - Returns
undefinedfor either part if the filename has no dot or starts with a dot only.
Examples
splitFileExtension("array.ts") // ["array", "ts"]splitFileExtension("no-ext") // ["no-ext", undefined]splitFileExtension(".gitignore") // [undefined, "gitignore"]splitFileExtension(undefined) // [undefined, undefined]