UNPKG

1.1 kBJavaScriptView Raw
1const path = require("path");
2
3/**
4 * On win32 platforms transform win32 type paths into posix paths
5 * (leaves paths on posix platforms alone)ß
6 *
7 * This function is just to make dependency-cruiser's internal
8 * representation consistent. This is the reason it doesn't have
9 * exceptions for extended paths (\\my-cool-share\bladiebla)
10 * and paths that contain non-ascii characters like e.g.
11 * sindresorhus/slash does.
12 *
13 * One consequence of this is that internal dependency-cruise
14 * representations cannot be converted back to win32 paths
15 * with 100% confidence.
16 *
17 * @param {string} pFilePath the path to transform
18 * @param {string} pPathModule optional - the path module/ object to use (for testing
19 * this module on posix platforms only; defaults to require('path'))
20 * @return {string} the transformed path
21 */
22module.exports = (pFilePath, pPathModule) => {
23 const lPathModule = pPathModule || path;
24
25 if (lPathModule.sep !== path.posix.sep) {
26 return pFilePath.split(lPathModule.sep).join(path.posix.sep);
27 }
28
29 return pFilePath;
30};