4
0

getRelativePath.mjs 452 B

123456789101112
  1. import path from 'node:path';
  2. /**
  3. * Returns the relative path of a file to the current working directory.
  4. * Always in POSIX format for consistency and interoperability.
  5. * @param {string} cwd The current working directory.
  6. * @param {string} filePath The file path.
  7. * @returns {string} The relative file path.
  8. */
  9. export default function getRelativePath(cwd, filePath) {
  10. return path.relative(cwd, filePath).split(path.sep).join(path.posix.sep);
  11. }