@codemod-utils/files
Version:
Utilities for handling files
28 lines (27 loc) • 686 B
TypeScript
import type { FilePath, ParsedPath } from './types.js';
/**
* Parses a file path, similarly to `parse()` from `node:path`,
* but correctly handles file extensions with more than one `.`,
* e.g. `.d.ts` and `.css.d.ts`.
*
* @param filePath
*
* A file path.
*
* @return
*
* An object with `base`, `dir`, `ext`, and `name`.
*
* @example
*
* ```ts
* const filePath = 'src/components/navigation-menu.d.ts';
* const { base, dir, ext, name } = parseFilePath(filePath);
*
* // base -> 'navigation-menu.d.ts'
* // dir -> 'src/components'
* // ext -> '.d.ts'
* // name -> 'navigation-menu'
* ```
*/
export declare function parseFilePath(filePath: FilePath): ParsedPath;